CodeSampleX

Ejemplo

pretty-format 27.5.1: plugins

Muestra verificada para npm pretty-format 27.5.1: plugins. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:97a8606b85878b9e51324be368f17bc4951430279bf916d1488f7fbe0a794921

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-06

Caso

HOW
Objetivo
verify pretty-format.plugins in pkg:npm/pretty-format@27.5.1
Paquetes
Símbolos
  • pretty-format.plugins
Creado
2026-09-06T00:31:19Z

Contrato

  1. plugins export contains built-in plugin definitions for React, DOM, Immutable, and ConvertAnsi 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. formatWithPlugins with ConvertAnsi converts ANSI escape sequences
  7. createCustomPlugin validates testFn and serializeFn argument types
  8. createCustomPlugin and formatWithPlugins support custom formatting and printer delegation
  9. formatWithPlugins without matching plugins falls back to standard object formatting

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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@27.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pretty-format@27.5.1
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:31940eecb7ee3c309120ca62a02a2b7752852c5d96f484d562d1219dea61dcb6","contract":["plugins export contains built-in plugin definitions for React, DOM, Immutable, and ConvertAnsi 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","formatWithPlugins with ConvertAnsi converts ANSI escape sequences","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@27.5.1","kind":"HOW","packages":["pkg:npm/pretty-format@27.5.1"],"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@27.5.1"],"schemaVersion":1,"subject":"pkg:npm/pretty-format@27.5.1","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": "27.5.1"
      }
    },
    "node_modules/ansi-regex": {
      "version": "5.0.1",
      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "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": "27.5.1",
      "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz",
      "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1",
        "ansi-styles": "^5.0.0",
        "react-is": "^17.0.1"
      },
      "engines": {
        "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
      }
    },
    "node_modules/react-is": {
      "version": "17.0.2",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
      "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
      "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": "27.5.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pretty-format.plugins in pkg:npm/pretty-format@27.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@27.5.1"
  ],
  "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.ConvertAnsi, 'object', 'plugins.ConvertAnsi 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. ConvertAnsi plugin formatting
const ansiString = '\u001b[31mRed text\u001b[39m';
const formattedAnsi = formatWithPlugins(ansiString, [plugins.ConvertAnsi]);
assert.strictEqual(formattedAnsi, '"<red>Red text</>"');

// 7. 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/
);

// 8. 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)'
);

// 9. 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 de origen

anónimo