CodeSampleX

샘플

jest-matcher-utils 29.7.0: matcherHint, printExpected, printReceived

검증된 샘플 — npm jest-matcher-utils 29.7.0: matcherHint, printExpected, printReceived. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:072b875b978792c8a625dc87bd43e92ef7d5563aae6b5290d7eec3beca554f39

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

실행 증거

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

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

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

케이스

HOW
목표
verify pkg:npm/jest-matcher-utils@29.7.0
패키지
심벌
  • matcherHint
  • printExpected
  • printReceived
  • printWithType
  • diff
  • stringify
  • matcherErrorMessage
  • ensureActualIsNumber
  • ensureExpectedIsNumber
  • ensureNoExpected
  • pluralize
  • getLabelPrinter
환경
node 22.23.2
생성일
2026-08-27T12:36:44Z

컨트랙트

  1. matcherHint formats standard matcher invocation headers with expected and received labels
  2. matcherHint supports options including isNot, promise, and comment modifiers
  3. printExpected formats expected values with quotes and syntax formatting
  4. printReceived formats received values with quotes and syntax formatting
  5. printWithType displays the type and formatted value of an argument
  6. diff computes and returns a unified string diff between expected and received values
  7. stringify serializes JavaScript values cleanly into string representation
  8. matcherErrorMessage formats standard matcher failure messages with hints and explanations
  9. ensureActualIsNumber validates received value is numeric and throws formatted error otherwise
  10. ensureExpectedIsNumber validates expected value is numeric and throws formatted error otherwise
  11. ensureNoExpected verifies matcher does not receive an expected argument
  12. pluralize formats countable noun singular and plural forms based on count
  13. getLabelPrinter creates formatted and aligned label printers for matcher outputs

파일

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

소스 아티팩트 내려받기 (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 pkg:npm/jest-matcher-utils@29.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/jest-matcher-utils@29.7.0

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:bfbc0907ceffc559fd8e11b2258aa8b3cf5bdd5e30996533e005e3aa0b3b4098","contract":["matcherHint formats standard matcher invocation headers with expected and received labels","matcherHint supports options including isNot, promise, and comment modifiers","printExpected formats expected values with quotes and syntax formatting","printReceived formats received values with quotes and syntax formatting","printWithType displays the type and formatted value of an argument","diff computes and returns a unified string diff between expected and received values","stringify serializes JavaScript values cleanly into string representation","matcherErrorMessage formats standard matcher failure messages with hints and explanations","ensureActualIsNumber validates received value is numeric and throws formatted error otherwise","ensureExpectedIsNumber validates expected value is numeric and throws formatted error otherwise","ensureNoExpected verifies matcher does not receive an expected argument","pluralize formats countable noun singular and plural forms based on count","getLabelPrinter creates formatted and aligned label printers for matcher outputs"],"goal":"verify pkg:npm/jest-matcher-utils@29.7.0","kind":"HOW","packages":["pkg:npm/jest-matcher-utils@29.7.0"],"schemaVersion":1,"symbols":["matcherHint","printExpected","printReceived","printWithType","diff","stringify","matcherErrorMessage","ensureActualIsNumber","ensureExpectedIsNumber","ensureNoExpected","pluralize","getLabelPrinter"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/jest-matcher-utils@29.7.0"],"schemaVersion":1,"subject":"pkg:npm/jest-matcher-utils@29.7.0","symbols":["matcherHint","printExpected","printReceived","printWithType","diff","stringify","matcherErrorMessage","ensureActualIsNumber","ensureExpectedIsNumber","ensureNoExpected","pluralize","getLabelPrinter"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-jest-matcher-utils-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-matcher-utils-verify",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "jest-matcher-utils": "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": "4.3.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
      "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
      "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.1.0",
        "supports-color": "^7.1.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/chalk?sponsor=1"
      }
    },
    "node_modules/color-convert": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
      "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/color-name": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
      "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
      "license": "MIT"
    },
    "node_modules/diff-sequences": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz",
      "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==",
      "license": "MIT",
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/has-flag": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
      "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/jest-diff": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz",
      "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==",
      "license": "MIT",
      "dependencies": {
        "chalk": "^4.0.0",
        "diff-sequences": "^29.6.3",
        "jest-get-type": "^29.6.3",
        "pretty-format": "^29.7.0"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/jest-get-type": {
      "version": "29.6.3",
      "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz",
      "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==",
      "license": "MIT",
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "node_modules/jest-matcher-utils": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz",
      "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==",
      "license": "MIT",
      "dependencies": {
        "chalk": "^4.0.0",
        "jest-diff": "^29.7.0",
        "jest-get-type": "^29.6.3",
        "pretty-format": "^29.7.0"
      },
      "engines": {
        "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
      }
    },
    "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/pretty-format/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/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"
    },
    "node_modules/supports-color": {
      "version": "7.2.0",
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
      "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
      "license": "MIT",
      "dependencies": {
        "has-flag": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-jest-matcher-utils-verify",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/jest-matcher-utils@29.7.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "jest-matcher-utils": "29.7.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/jest-matcher-utils@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/jest-matcher-utils@29.7.0"
  ],
  "symbols": [
    "matcherHint",
    "printExpected",
    "printReceived",
    "printWithType",
    "diff",
    "stringify",
    "matcherErrorMessage",
    "ensureActualIsNumber",
    "ensureExpectedIsNumber",
    "ensureNoExpected",
    "pluralize",
    "getLabelPrinter"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const {
  matcherHint,
  printExpected,
  printReceived,
  printWithType,
  diff,
  stringify,
  matcherErrorMessage,
  ensureActualIsNumber,
  ensureExpectedIsNumber,
  ensureNoExpected,
  pluralize,
  getLabelPrinter
} = require('jest-matcher-utils');

/**
 * Formats standard matcher header string.
 * @param {string} matcherName
 * @param {string} [received]
 * @param {string} [expected]
 * @param {object} [options]
 * @returns {string}
 */
function formatMatcherHint(matcherName, received, expected, options) {
  return matcherHint(matcherName, received, expected, options);
}

/**
 * Formats expected value for display.
 * @param {*} value
 * @returns {string}
 */
function formatExpected(value) {
  return printExpected(value);
}

/**
 * Formats received value for display.
 * @param {*} value
 * @returns {string}
 */
function formatReceived(value) {
  return printReceived(value);
}

/**
 * Computes difference between expected and received.
 * @param {*} expected
 * @param {*} received
 * @param {object} [options]
 * @returns {string|null}
 */
function computeDiff(expected, received, options) {
  return diff(expected, received, options);
}

module.exports = {
  matcherHint,
  printExpected,
  printReceived,
  printWithType,
  diff,
  stringify,
  matcherErrorMessage,
  ensureActualIsNumber,
  ensureExpectedIsNumber,
  ensureNoExpected,
  pluralize,
  getLabelPrinter,
  formatMatcherHint,
  formatExpected,
  formatReceived,
  computeDiff
};
test/contract.js
'use strict';

const assert = require('assert');
const {
  matcherHint,
  printExpected,
  printReceived,
  printWithType,
  diff,
  stringify,
  matcherErrorMessage,
  ensureActualIsNumber,
  ensureExpectedIsNumber,
  ensureNoExpected,
  pluralize,
  getLabelPrinter,
  formatMatcherHint,
  formatExpected,
  formatReceived,
  computeDiff
} = require('../src/index.js');

// 1. matcherHint formats standard matcher invocation headers with expected and received labels
{
  const hint = matcherHint('toBe', 'received', 'expected');
  assert.strictEqual(hint, 'expect(received).toBe(expected)');

  const customHint = formatMatcherHint('toEqual', 'actual', 'expected');
  assert.strictEqual(customHint, 'expect(actual).toEqual(expected)');
}

// 2. matcherHint supports options including isNot, promise, and comment modifiers
{
  const hintNot = matcherHint('toBe', undefined, undefined, { isNot: true });
  assert.strictEqual(hintNot, 'expect(received).not.toBe(expected)');

  const hintRejects = matcherHint('toThrow', undefined, undefined, { promise: 'rejects' });
  assert.strictEqual(hintRejects, 'expect(received).rejects.toThrow(expected)');

  const hintWithComment = matcherHint('toBe', 'received', 'expected', { comment: 'equality check' });
  assert.strictEqual(hintWithComment, 'expect(received).toBe(expected) // equality check');
}

// 3. printExpected formats expected values with quotes and syntax formatting
{
  const printedNum = formatExpected(123);
  assert.strictEqual(printedNum, '123');

  const printedStr = printExpected('hello');
  assert.strictEqual(printedStr, '"hello"');

  const printedArr = printExpected([1, 2]);
  assert.strictEqual(printedArr, '[1, 2]');
}

// 4. printReceived formats received values with quotes and syntax formatting
{
  const printedNum = formatReceived(456);
  assert.strictEqual(printedNum, '456');

  const printedStr = printReceived('world');
  assert.strictEqual(printedStr, '"world"');

  const printedObj = printReceived({ key: 'val' });
  assert.strictEqual(printedObj, '{"key": "val"}');
}

// 5. printWithType displays the type and formatted value of an argument
{
  const formatted = printWithType('received', 'abc', printReceived);
  assert.strictEqual(formatted, 'received has type:  string\nreceived has value: "abc"');

  const formattedNum = printWithType('expected', 99, printExpected);
  assert.strictEqual(formattedNum, 'expected has type:  number\nexpected has value: 99');
}

// 6. diff computes and returns a unified string diff between expected and received values
{
  const diffResult = computeDiff('hello world', 'hello there');
  assert.ok(typeof diffResult === 'string');
  assert.ok(diffResult.includes('- Expected'));
  assert.ok(diffResult.includes('+ Received'));

  const noDiff = diff('same', 'same');
  assert.ok(noDiff.includes('Compared values have no visual difference'));
}

// 7. stringify serializes JavaScript values cleanly into string representation
{
  assert.strictEqual(stringify(null), 'null');
  assert.strictEqual(stringify(undefined), 'undefined');
  assert.strictEqual(stringify(true), 'true');
  assert.strictEqual(stringify(100), '100');
  assert.strictEqual(stringify('test'), '"test"');
  assert.strictEqual(stringify({ a: 1 }), '{"a": 1}');
  assert.strictEqual(stringify([1, 2]), '[1, 2]');
}

// 8. matcherErrorMessage formats standard matcher failure messages with hints and explanations
{
  const hint = matcherHint('toBeGreaterThan');
  const explanation = 'expected value must be a number or bigint';
  const printedType = printWithType('Expected', 'string-val', printExpected);
  const message = matcherErrorMessage(hint, explanation, printedType);

  assert.ok(message.includes('expect(received).toBeGreaterThan(expected)'));
  assert.ok(message.includes('Matcher error: expected value must be a number or bigint'));
  assert.ok(message.includes('Expected has type:  string'));
}

// 9. ensureActualIsNumber validates received value is numeric and throws formatted error otherwise
{
  assert.doesNotThrow(() => ensureActualIsNumber(42, 'toBeCloseTo'));
  assert.doesNotThrow(() => ensureActualIsNumber(42n, 'toBeCloseTo'));

  assert.throws(
    () => ensureActualIsNumber('invalid', 'toBeCloseTo'),
    (err) => {
      assert.ok(err instanceof Error);
      assert.ok(err.message.includes('received value must be a number or bigint'));
      return true;
    }
  );
}

// 10. ensureExpectedIsNumber validates expected value is numeric and throws formatted error otherwise
{
  assert.doesNotThrow(() => ensureExpectedIsNumber(100, 'toBeCloseTo'));
  assert.doesNotThrow(() => ensureExpectedIsNumber(100n, 'toBeCloseTo'));

  assert.throws(
    () => ensureExpectedIsNumber('invalid', 'toBeCloseTo'),
    (err) => {
      assert.ok(err instanceof Error);
      assert.ok(err.message.includes('expected value must be a number or bigint'));
      return true;
    }
  );
}

// 11. ensureNoExpected verifies matcher does not receive an expected argument
{
  assert.doesNotThrow(() => ensureNoExpected(undefined, 'toBeNull'));

  assert.throws(
    () => ensureNoExpected('extra-arg', 'toBeNull'),
    (err) => {
      assert.ok(err instanceof Error);
      assert.ok(err.message.includes('this matcher must not have an expected argument'));
      return true;
    }
  );
}

// 12. pluralize formats countable noun singular and plural forms based on count
{
  assert.strictEqual(pluralize('apple', 0), 'zero apples');
  assert.strictEqual(pluralize('apple', 1), 'one apple');
  assert.strictEqual(pluralize('apple', 2), 'two apples');
  assert.strictEqual(pluralize('apple', 14), '14 apples');
}

// 13. getLabelPrinter creates formatted and aligned label printers for matcher outputs
{
  const printLabel = getLabelPrinter('Expected', 'Received value');
  assert.strictEqual(printLabel('Expected'), 'Expected:       ');
  assert.strictEqual(printLabel('Received value'), 'Received value: ');
}

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

오리진 시더

익명