CodeSampleX

示例

@jest/expect-utils 29.7.0: equals

已验证示例 — npm @jest/expect-utils 29.7.0: equals. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: equals performs structural deep equality check on…

sha256:47710044294bb121c7f79bb22c3e052f8fbb6a44f676422e88d7371c9b3d4472

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-23

案例

HOW
目标
verify pkg:npm/%40jest/expect-utils@29.7.0
包
符号
  • equals
环境
node 22.23.2
创建时间
2026-08-23T16:19:38Z

契约

  1. equals performs structural deep equality check on primitives, nested objects, arrays, Dates, RegExps, Sets, and Maps
  2. equals resolves circular references without infinite recursion
  3. equals supports custom tester functions for specialized type comparisons
  4. equals with strictCheck false allows matching missing properties with undefined properties
  5. equals with strictCheck true rejects object property mismatches where one property is undefined and missing on the other
  6. equals with strictCheck true rejects sparse array vs dense undefined array differences

文件

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

下载源代码构件 (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/%40jest/expect-utils@29.7.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jest/expect-utils@29.7.0
Demonstrate these symbols/APIs:
  - equals
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:601495bf77d38aaa47b43efede97e80148d930a857be5b02e45db77ffa4d0b95","constraints":{"executionContext":"node"},"contract":["equals performs structural deep equality check on primitives, nested objects, arrays, Dates, RegExps, Sets, and Maps","equals resolves circular references without infinite recursion","equals supports custom tester functions for specialized type comparisons","equals with strictCheck false allows matching missing properties with undefined properties","equals with strictCheck true rejects object property mismatches where one property is undefined and missing on the other","equals with strictCheck true rejects sparse array vs dense undefined array differences"],"goal":"verify pkg:npm/%40jest/expect-utils@29.7.0","kind":"HOW","packages":["pkg:npm/%40jest/expect-utils@29.7.0"],"schemaVersion":1,"symbols":["equals"]},"contractCommand":["node","test/contract.cjs"],"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/%40jest/expect-utils@29.7.0"],"schemaVersion":1,"subject":"pkg:npm/%40jest/expect-utils@29.7.0","symbols":["equals"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-jest-expect-utils-equals",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-expect-utils-equals",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jest/expect-utils": "29.7.0"
      }
    },
    "node_modules/@jest/expect-utils": {
      "version": "29.7.0",
      "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz",
      "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==",
      "license": "MIT",
      "dependencies": {
        "jest-get-type": "^29.6.3"
      },
      "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"
      }
    }
  }
}
package.json
{
  "name": "sample-jest-expect-utils-equals",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/%40jest/expect-utils@29.7.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@jest/expect-utils": "29.7.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40jest/expect-utils@29.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jest/expect-utils@29.7.0"
  ],
  "symbols": [
    "equals"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { equals } = require('@jest/expect-utils');

/**
 * Performs deep structural equality comparison between two values.
 *
 * @param {unknown} a - First value to compare.
 * @param {unknown} b - Second value to compare.
 * @param {Array<Function>} [customTesters] - Optional custom tester functions.
 * @param {boolean} [strictCheck=false] - Whether to perform strict checks.
 * @returns {boolean} True if values are deeply equal, false otherwise.
 */
function areDeeplyEqual(a, b, customTesters, strictCheck = false) {
  return equals(a, b, customTesters, strictCheck);
}

module.exports = {
  equals,
  areDeeplyEqual
};
test/contract.cjs
const assert = require('node:assert');
const { equals, areDeeplyEqual } = require('../src/index.js');

async function main() {
  // 1. equals performs structural deep equality check on primitives, nested objects, arrays, Dates, RegExps, Sets, and Maps
  assert.strictEqual(areDeeplyEqual(42, 42), true, 'primitives must match');
  assert.strictEqual(areDeeplyEqual('foo', 'foo'), true, 'strings must match');
  assert.strictEqual(areDeeplyEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }), true, 'nested objects and arrays must match');
  assert.strictEqual(areDeeplyEqual({ a: 1 }, { a: 2 }), false, 'different property values must not match');

  assert.strictEqual(areDeeplyEqual(new Date('2026-01-01'), new Date('2026-01-01')), true, 'identical dates must match');
  assert.strictEqual(areDeeplyEqual(new Date('2026-01-01'), new Date('2026-01-02')), false, 'different dates must not match');
  assert.strictEqual(areDeeplyEqual(/abc/g, /abc/g), true, 'identical regexes must match');
  assert.strictEqual(areDeeplyEqual(/abc/g, /abc/i), false, 'different regex flags must not match');

  const setA = new Set([1, 2, { x: 3 }]);
  const setB = new Set([1, 2, { x: 3 }]);
  assert.strictEqual(areDeeplyEqual(setA, setB), true, 'sets with deeply equal elements must match');

  const mapA = new Map([['k1', { v: 1 }]]);
  const mapB = new Map([['k1', { v: 1 }]]);
  assert.strictEqual(areDeeplyEqual(mapA, mapB), true, 'maps with deeply equal entries must match');

  // 2. equals resolves circular references without infinite recursion
  const circA = { name: 'circular' };
  circA.self = circA;
  const circB = { name: 'circular' };
  circB.self = circB;
  assert.strictEqual(areDeeplyEqual(circA, circB), true, 'circular structures must be handled without overflow');

  // 3. equals supports custom tester functions for specialized type comparisons
  const customTester = function(a, b) {
    if (typeof a === 'string' && typeof b === 'number') {
      return a === String(b);
    }
    return undefined;
  };
  assert.strictEqual(areDeeplyEqual('123', 123, [customTester]), true, 'custom tester should match string with number');
  assert.strictEqual(areDeeplyEqual('123', 456, [customTester]), false, 'custom tester should reject unequal numbers');

  // 4. equals with strictCheck false allows matching missing properties with undefined properties
  const objUndefined = { a: undefined };
  const objMissing = {};
  assert.strictEqual(areDeeplyEqual(objUndefined, objMissing, undefined, false), true, 'loose check matches undefined with missing prop');

  // 5. equals with strictCheck true rejects object property mismatches where one property is undefined and missing on the other
  assert.strictEqual(areDeeplyEqual(objUndefined, objMissing, undefined, true), false, 'strict check rejects undefined vs missing prop');

  // 6. equals with strictCheck true rejects sparse array vs dense undefined array differences
  assert.strictEqual(areDeeplyEqual([,], [undefined], undefined, false), true, 'loose check matches sparse hole with undefined');
  assert.strictEqual(areDeeplyEqual([,], [undefined], undefined, true), false, 'strict check distinguishes sparse hole from undefined');

  console.log('Contract assertions passed.');
  process.exit(0);
}

main().catch((err) => {
  console.error('Contract failed:', err);
  process.exit(1);
});

原始种子者

匿名