CodeSampleX

Exemple

pretty-format 29.7.0: plugins

Échantillon vérifié pour npm pretty-format 29.7.0: plugins. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:258e7d004087861ed6249d6796082c1b2bd451fc6fcedf54258bd4b58cc97ed0

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

Cas

HOW
Objectif
verify pretty-format.plugins in pkg:npm/pretty-format@29.7.0
Paquets
Symboles
  • pretty-format.plugins
Créé
2026-08-21T06:01:33Z

Contrat

  1. plugins export contains built-in plugin definitions for React, DOM, and Immutable types
  2. getBuiltinPlugins returns the exported plugins object
  3. formatWithPlugins with ReactTestComponent formats React test renderer JSON structures
  4. formatWithPlugins with ReactElement formats standard React element structures
  5. formatWithPlugins with AsymmetricMatcher formats Jest asymmetric matcher structures
  6. createCustomPlugin validates testFn and serializeFn argument types
  7. createCustomPlugin and formatWithPlugins support custom formatting and printer delegation
  8. formatWithPlugins without matching plugins falls back to standard object formatting

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Télécharger l’artefact source (tar.gz)

Code source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pretty-format.plugins in pkg:npm/pretty-format@29.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pretty-format@29.7.0
Demonstrate these symbols/APIs:
  - pretty-format.plugins

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:aed1c521d9f3f6ecbf00f74faebbf73ce82616264902a8d71109b3475ae8bf3c","contract":["plugins export contains built-in plugin definitions for React, DOM, and Immutable types","getBuiltinPlugins returns the exported plugins object","formatWithPlugins with ReactTestComponent formats React test renderer JSON structures","formatWithPlugins with ReactElement formats standard React element structures","formatWithPlugins with AsymmetricMatcher formats Jest asymmetric matcher structures","createCustomPlugin validates testFn and serializeFn argument types","createCustomPlugin and formatWithPlugins support custom formatting and printer delegation","formatWithPlugins without matching plugins falls back to standard object formatting"],"goal":"verify pretty-format.plugins in pkg:npm/pretty-format@29.7.0","kind":"HOW","packages":["pkg:npm/pretty-format@29.7.0"],"schemaVersion":1,"symbols":["pretty-format.plugins"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/pretty-format@29.7.0"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@29.7.0","symbols":["pretty-format.plugins"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-pretty-format-plugins",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-pretty-format-plugins",
      "version": "1.0.0",
      "dependencies": {
        "pretty-format": "29.7.0"
      }
    },
    "node_modules/@jest/schemas": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz",
      "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==",
      "license": "MIT",
      "dependencies": {
        "@sinclair/typebox": "^0.27.8"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/@sinclair/typebox": {
      "version": "0.27.12",
      "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz",
      "integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==",
      "license": "MIT"
    },
    "node_modules/ansi-styles": {
      "version": "5.2.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
      "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/pretty-format": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",
      "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==",
      "license": "MIT",
      "dependencies": {
        "@jest/schemas": "^29.6.3",
        "ansi-styles": "^5.0.0",
        "react-is": "^18.0.0"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/react-is": {
      "version": "18.3.1",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
      "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-pretty-format-plugins",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of pretty-format.plugins",
  "main": "src/index.js",
  "dependencies": {
    "pretty-format": "29.7.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pretty-format.plugins in pkg:npm/pretty-format@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@29.7.0"
  ],
  "symbols": [
    "pretty-format.plugins"
  ]
}
src/index.js
const { format, plugins } = require('pretty-format');

/**
 * Returns all built-in plugins provided by pretty-format.
 * @returns {typeof plugins}
 */
function getBuiltinPlugins() {
  return plugins;
}

/**
 * Formats a value using pretty-format with specified plugins.
 * @param {unknown} value - The value to format.
 * @param {Array<object>} [pluginList] - List of plugins to apply.
 * @param {object} [options] - Additional format options.
 * @returns {string}
 */
function formatWithPlugins(value, pluginList = [], options = {}) {
  return format(value, {
    ...options,
    plugins: pluginList
  });
}

/**
 * Creates a custom pretty-format plugin.
 * @param {(val: unknown) => boolean} testFn - Predicate to test if value should be handled.
 * @param {(val: unknown, config: object, indentation: string, depth: number, refs: Array<unknown>, printer: Function) => string} serializeFn - Serialization function.
 * @returns {{ test: Function, serialize: Function }}
 */
function createCustomPlugin(testFn, serializeFn) {
  if (typeof testFn !== 'function' || typeof serializeFn !== 'function') {
    throw new TypeError('testFn and serializeFn must be functions');
  }
  return {
    test: testFn,
    serialize: serializeFn
  };
}

module.exports = {
  plugins,
  getBuiltinPlugins,
  formatWithPlugins,
  createCustomPlugin
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  plugins,
  getBuiltinPlugins,
  formatWithPlugins,
  createCustomPlugin
} = require('../src/index.js');

// 1. Built-in plugins export structure
assert.strictEqual(typeof plugins, 'object', 'plugins must be an object');
assert.strictEqual(typeof plugins.AsymmetricMatcher, 'object', 'plugins.AsymmetricMatcher must be an object');
assert.strictEqual(typeof plugins.DOMCollection, 'object', 'plugins.DOMCollection must be an object');
assert.strictEqual(typeof plugins.DOMElement, 'object', 'plugins.DOMElement must be an object');
assert.strictEqual(typeof plugins.Immutable, 'object', 'plugins.Immutable must be an object');
assert.strictEqual(typeof plugins.ReactElement, 'object', 'plugins.ReactElement must be an object');
assert.strictEqual(typeof plugins.ReactTestComponent, 'object', 'plugins.ReactTestComponent must be an object');

for (const [name, plugin] of Object.entries(plugins)) {
  assert.strictEqual(typeof plugin.test, 'function', `${name}.test must be a function`);
  assert.strictEqual(typeof plugin.serialize, 'function', `${name}.serialize must be a function`);
}

// 2. getBuiltinPlugins helper
assert.strictEqual(getBuiltinPlugins(), plugins, 'getBuiltinPlugins must return plugins export');

// 3. ReactTestComponent plugin formatting
const reactTestComp = {
  $$typeof: Symbol.for('react.test.json'),
  type: 'div',
  props: { className: 'card', id: 'main' },
  children: ['Sample text']
};
const formattedReactTestComp = formatWithPlugins(reactTestComp, [plugins.ReactTestComponent]);
assert.strictEqual(
  formattedReactTestComp,
  '<div\n  className="card"\n  id="main"\n>\n  Sample text\n</div>'
);

// 4. ReactElement plugin formatting
const reactElement = {
  $$typeof: Symbol.for('react.element'),
  type: 'span',
  props: { children: 'inline text' }
};
const formattedReactElement = formatWithPlugins(reactElement, [plugins.ReactElement]);
assert.strictEqual(
  formattedReactElement,
  '<span>\n  inline text\n</span>'
);

// 5. AsymmetricMatcher plugin formatting
const asymmetricMatcher = {
  $$typeof: Symbol.for('jest.asymmetricMatcher'),
  asymmetricMatch: () => true,
  toAsymmetricMatcher: () => 'StringMatching(/sample/)'
};
const formattedMatcher = formatWithPlugins(asymmetricMatcher, [plugins.AsymmetricMatcher]);
assert.strictEqual(formattedMatcher, 'StringMatching(/sample/)');

// 6. createCustomPlugin validation
assert.throws(
  () => createCustomPlugin(null, () => ''),
  /TypeError: testFn and serializeFn must be functions/
);
assert.throws(
  () => createCustomPlugin(() => true, 'invalid'),
  /TypeError: testFn and serializeFn must be functions/
);

// 7. Custom plugin formatting and printer delegation
const currencyPlugin = createCustomPlugin(
  (val) => val != null && typeof val === 'object' && val.__type === 'Currency',
  (val, config, indentation, depth, refs, printer) => {
    return `${val.currency} ${val.amount.toFixed(2)}`;
  }
);

const wrapperPlugin = createCustomPlugin(
  (val) => val != null && typeof val === 'object' && val.__type === 'Wrapper',
  (val, config, indentation, depth, refs, printer) => {
    const inner = printer(val.inner, config, indentation, depth, refs);
    return `Wrapper(${inner})`;
  }
);

const sampleCurrency = { __type: 'Currency', currency: 'USD', amount: 99.5 };
assert.strictEqual(
  formatWithPlugins(sampleCurrency, [currencyPlugin]),
  'USD 99.50'
);

const nestedSample = {
  __type: 'Wrapper',
  inner: { __type: 'Currency', currency: 'EUR', amount: 42 }
};
assert.strictEqual(
  formatWithPlugins(nestedSample, [wrapperPlugin, currencyPlugin]),
  'Wrapper(EUR 42.00)'
);

// 8. Default formatting without matching plugins
const unformattedCurrency = formatWithPlugins(sampleCurrency, []);
assert.strictEqual(
  unformattedCurrency,
  'Object {\n  "__type": "Currency",\n  "amount": 99.5,\n  "currency": "USD",\n}'
);

console.log('Contract tests passed successfully.');

Seeder d'origine

anonyme