CodeSampleX

샘플

pretty-format 29.7.0: plugins

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

sha256:39df2d710ef44bac52ceb4a4e332f4eb2e86ab27b4f185d400d167213c23a886

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify plugins in pkg:npm/pretty-format@29.7.0
패키지
심벌
  • plugins
생성일
2026-09-02T00:51:14Z

컨트랙트

  1. plugins exports built-in serializer plugins including ReactElement, ReactTestComponent, and AsymmetricMatcher
  2. format with plugins.ReactElement formats React element structures into JSX-like strings
  3. format with plugins.ReactTestComponent formats React test renderer JSON structures
  4. format with plugins.AsymmetricMatcher formats Jest asymmetric matchers
  5. format supports custom plugins implementing test and serialize hooks
  6. format supports recursive nested serialization with printer in custom plugins
  7. format applies plugins in array order where earlier matching plugins take precedence
  8. format ignores plugins when test returns false and falls back to default formatting

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 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:
  - 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:16e7c8d985b2c94cc4e1d300cb4be56fb96479cabd90f0c8a04073ed4f0a28bb","contract":["plugins exports built-in serializer plugins including ReactElement, ReactTestComponent, and AsymmetricMatcher","format with plugins.ReactElement formats React element structures into JSX-like strings","format with plugins.ReactTestComponent formats React test renderer JSON structures","format with plugins.AsymmetricMatcher formats Jest asymmetric matchers","format supports custom plugins implementing test and serialize hooks","format supports recursive nested serialization with printer in custom plugins","format applies plugins in array order where earlier matching plugins take precedence","format ignores plugins when test returns false and falls back to default formatting"],"goal":"verify plugins in pkg:npm/pretty-format@29.7.0","kind":"HOW","packages":["pkg:npm/pretty-format@29.7.0"],"schemaVersion":1,"symbols":["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":["plugins"],"verifierAdapter":"node-typescript@1"}
index.mjs
import prettyFormat, { format, plugins, DEFAULT_OPTIONS } from 'pretty-format';

export { prettyFormat, format, plugins, DEFAULT_OPTIONS };

/**
 * Format a value using provided plugins array.
 */
export function formatWithPlugins(value, pluginList, options = {}) {
  return format(value, { ...options, plugins: pluginList });
}

/**
 * Format a value using a custom test/serialize plugin.
 */
export function formatWithCustomSerializer(value, testFn, serializeFn, options = {}) {
  const plugin = {
    test: testFn,
    serialize: serializeFn,
  };
  return format(value, { ...options, plugins: [plugin] });
}

/**
 * Create a simple custom serializer plugin.
 */
export function createCustomPlugin(testFn, serializeFn) {
  return {
    test: testFn,
    serialize: serializeFn,
  };
}
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",
      "license": "MIT-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",
  "description": "Clean-room verification sample for pretty-format plugins",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "pretty-format": "29.7.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify plugins in pkg:npm/pretty-format@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pretty-format@29.7.0"
  ],
  "symbols": [
    "plugins"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import prettyFormat, { format, plugins, DEFAULT_OPTIONS } from 'pretty-format';
import {
  formatWithPlugins,
  formatWithCustomSerializer,
  createCustomPlugin,
} from '../index.mjs';

// 1. plugins exports built-in serializer plugins including ReactElement, ReactTestComponent, and AsymmetricMatcher
{
  assert.equal(typeof plugins, 'object');
  assert.equal(typeof plugins.ReactElement.test, 'function');
  assert.equal(typeof plugins.ReactElement.serialize, 'function');
  assert.equal(typeof plugins.ReactTestComponent.test, 'function');
  assert.equal(typeof plugins.ReactTestComponent.serialize, 'function');
  assert.equal(typeof plugins.AsymmetricMatcher.test, 'function');
  assert.equal(typeof plugins.AsymmetricMatcher.serialize, 'function');
  assert.equal(typeof plugins.DOMElement.test, 'function');
  assert.equal(typeof plugins.DOMCollection.test, 'function');
  assert.equal(typeof plugins.Immutable.test, 'function');
}

// 2. format with plugins.ReactElement formats React element structures into JSX-like strings
{
  const reactEl = {
    $$typeof: Symbol.for('react.element'),
    type: 'div',
    props: { className: 'card' },
    key: null,
    ref: null,
  };
  const result = format(reactEl, { plugins: [plugins.ReactElement] });
  assert.equal(result, '<div\n  className="card"\n/>');
  assert.equal(formatWithPlugins(reactEl, [plugins.ReactElement]), '<div\n  className="card"\n/>');
}

// 3. format with plugins.ReactTestComponent formats React test renderer JSON structures
{
  const testComp = {
    $$typeof: Symbol.for('react.test.json'),
    type: 'button',
    props: { disabled: true },
    children: ['Click'],
  };
  const result = format(testComp, { plugins: [plugins.ReactTestComponent] });
  assert.equal(result, '<button\n  disabled={true}\n>\n  Click\n</button>');
}

// 4. format with plugins.AsymmetricMatcher formats Jest asymmetric matchers
{
  const matcher = {
    $$typeof: Symbol.for('jest.asymmetricMatcher'),
    asymmetricMatch: () => true,
    toAsymmetricMatcher: () => 'StringMatching(/xyz/)',
  };
  const result = format(matcher, { plugins: [plugins.AsymmetricMatcher] });
  assert.equal(result, 'StringMatching(/xyz/)');
}

// 5. format supports custom plugins implementing test and serialize hooks
{
  const personPlugin = createCustomPlugin(
    (val) => val && val.__type === 'Person',
    (val) => `Person(${val.name}, ${val.age})`
  );
  const data = { user: { __type: 'Person', name: 'Bob', age: 25 } };
  const result = format(data, { plugins: [personPlugin] });
  assert.equal(result, 'Object {\n  "user": Person(Bob, 25),\n}');

  const helperResult = formatWithCustomSerializer(
    data,
    (val) => val && val.__type === 'Person',
    (val) => `Person(${val.name}, ${val.age})`
  );
  assert.equal(helperResult, 'Object {\n  "user": Person(Bob, 25),\n}');
}

// 6. format supports recursive nested serialization with printer in custom plugins
{
  const wrapperPlugin = {
    test: (val) => val && val.__type === 'Wrapper',
    serialize: (val, config, indentation, depth, refs, printer) => {
      return `Wrapper<${printer(val.inner, config, indentation, depth, refs)}>`;
    },
  };
  const wrapped = { __type: 'Wrapper', inner: 42 };
  assert.equal(format(wrapped, { plugins: [wrapperPlugin] }), 'Wrapper<42>');
}

// 7. format applies plugins in array order where earlier matching plugins take precedence
{
  const pluginA = {
    test: (val) => val && val.tag === 'special',
    serialize: () => 'PluginA',
  };
  const pluginB = {
    test: (val) => val && val.tag === 'special',
    serialize: () => 'PluginB',
  };
  assert.equal(format({ tag: 'special' }, { plugins: [pluginA, pluginB] }), 'PluginA');
  assert.equal(format({ tag: 'special' }, { plugins: [pluginB, pluginA] }), 'PluginB');
}

// 8. format ignores plugins when test returns false and falls back to default formatting
{
  const noopPlugin = {
    test: () => false,
    serialize: () => 'Never',
  };
  assert.equal(format({ a: 1 }, { plugins: [noopPlugin] }), 'Object {\n  "a": 1,\n}');
}

console.log('All pretty-format plugins contract assertions passed.');

오리진 시더

익명