CodeSampleX

샘플

pretty-format 29.7.0: plugins

검증된 샘플 — npm pretty-format 29.7.0: plugins. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: plugins export contains built-in plugin definitions…

sha256:258e7d004087861ed6249d6796082c1b2bd451fc6fcedf54258bd4b58cc97ed0

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pretty-format.plugins in pkg:npm/pretty-format@29.7.0
패키지
심벌
  • pretty-format.plugins
생성일
2026-08-21T06:01:33Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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

오리진 시더

익명