CodeSampleX

サンプル

@vitest/expect 3.2.7

検証済みサンプル — npm @vitest/expect 3.2.7. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: JestChaiExpect plugin integrates Jest-compatible expect…

sha256:a16f0d95fbaf1cf216abebff9f54d698ec8010a0c4d7142d955b3710c23d7109

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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@1
2026-08-21

ケース

HOW
ゴール
verify pkg:npm/%40vitest/expect@3.2.7
パッケージ
環境
node 22.23.2
作成日
2026-08-21T09:56:31Z

コントラクト

  1. JestChaiExpect plugin integrates Jest-compatible expect matchers into Chai
  2. JestAsymmetricMatchers provides asymmetric matchers like any, stringContaining, arrayContaining, objectContaining, and anything
  3. Asymmetric matcher classes (StringContaining, Any, Anything, ArrayContaining, ObjectContaining, StringMatching) evaluate matching correctly
  4. Standalone utility functions (equals, subsetEquality, iterableEquality) verify structural and subset equality
  5. getState and setState inspect and update matcher state
  6. expect.extend registers custom matchers

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 pkg:npm/%40vitest/expect@3.2.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/expect@3.2.7
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:2adf182a014da5d6f4acd0b0a54075381a5b899bb3fcd87a4513b21c192065ae","constraints":{"executionContext":"node"},"contract":["JestChaiExpect plugin integrates Jest-compatible expect matchers into Chai","JestAsymmetricMatchers provides asymmetric matchers like any, stringContaining, arrayContaining, objectContaining, and anything","Asymmetric matcher classes (StringContaining, Any, Anything, ArrayContaining, ObjectContaining, StringMatching) evaluate matching correctly","Standalone utility functions (equals, subsetEquality, iterableEquality) verify structural and subset equality","getState and setState inspect and update matcher state","expect.extend registers custom matchers"],"goal":"verify pkg:npm/%40vitest/expect@3.2.7","kind":"HOW","packages":["pkg:npm/%40vitest/expect@3.2.7"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/%40vitest/expect@3.2.7"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/expect@3.2.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vitest-expect",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-expect",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vitest/expect": "3.2.7"
      }
    },
    "node_modules/@types/chai": {
      "version": "5.2.3",
      "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",
      "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",
      "license": "MIT",
      "dependencies": {
        "@types/deep-eql": "*",
        "assertion-error": "^2.0.1"
      }
    },
    "node_modules/@types/deep-eql": {
      "version": "4.0.2",
      "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
      "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",
      "license": "MIT"
    },
    "node_modules/@vitest/expect": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.7.tgz",
      "integrity": "sha512-E8eBXaKibuvH2pSZErOjdVb5vF4PbKYcrnluBTYxEk1l/VhhwZg1kZQsdtjq+CsF5CFydf2Rdkz7jDHKSisi3w==",
      "license": "MIT",
      "dependencies": {
        "@types/chai": "^5.2.2",
        "@vitest/spy": "3.2.7",
        "@vitest/utils": "3.2.7",
        "chai": "^5.2.0",
        "tinyrainbow": "^2.0.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/@vitest/pretty-format": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.7.tgz",
      "integrity": "sha512-KUHlwqVu0sRlhCdyPdQ/wBoTfRahjUky1MubOmYw9fWfIZy1gNoHpuaaQBPAaMaVYdQYHJLurzj8ECCj5OwTqA==",
      "license": "MIT",
      "dependencies": {
        "tinyrainbow": "^2.0.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/@vitest/spy": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.7.tgz",
      "integrity": "sha512-Q2eQGI6d2L/hBtZ0qNuKcAGid68XK6cv1xsoaIma6PaJhHPoqcEJhYpXZ/5myCMqkNgtP6UKuBhbc0nHKnrkuQ==",
      "license": "MIT",
      "dependencies": {
        "tinyspy": "^4.0.3"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/@vitest/utils": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.2.7.tgz",
      "integrity": "sha512-x6BDOd7dyo3PFLY3I9/HJ25X/6OurhGXk2/B9gOZNPF7XDVjeBK4k01lQE5uvDpbuheErh91qYuE1E2OEjK3Rw==",
      "license": "MIT",
      "dependencies": {
        "@vitest/pretty-format": "3.2.7",
        "loupe": "^3.1.4",
        "tinyrainbow": "^2.0.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/assertion-error": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
      "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/chai": {
      "version": "5.3.3",
      "resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz",
      "integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==",
      "license": "MIT",
      "dependencies": {
        "assertion-error": "^2.0.1",
        "check-error": "^2.1.1",
        "deep-eql": "^5.0.1",
        "loupe": "^3.1.0",
        "pathval": "^2.0.0"
      },
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/check-error": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.3.tgz",
      "integrity": "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==",
      "license": "MIT",
      "engines": {
        "node": ">= 16"
      }
    },
    "node_modules/deep-eql": {
      "version": "5.0.2",
      "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
      "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/loupe": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",
      "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",
      "license": "MIT"
    },
    "node_modules/pathval": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz",
      "integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 14.16"
      }
    },
    "node_modules/tinyrainbow": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz",
      "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    },
    "node_modules/tinyspy": {
      "version": "4.0.4",
      "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.4.tgz",
      "integrity": "sha512-azl+t0z7pw/z958Gy9svOTuzqIk6xq+NSheJzn5MMWtWTFywIacg2wUlzKFGtt3cthx0r2SxMK0yzJOR0IES7Q==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-expect",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "description": "Clean-room verification for @vitest/expect",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@vitest/expect": "3.2.7"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40vitest/expect@3.2.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/expect@3.2.7"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import * as chai from 'chai';
import {
  JestChaiExpect,
  JestAsymmetricMatchers,
  JestExtend,
  equals,
  subsetEquality,
  iterableEquality,
  StringContaining,
  ArrayContaining,
  ObjectContaining,
  Any,
  Anything,
  StringMatching,
  getState,
  setState,
  customMatchers
} from '@vitest/expect';

// Initialize Chai with @vitest/expect plugins
chai.use(JestChaiExpect);
chai.use(JestAsymmetricMatchers);
chai.use(JestExtend);

const { expect } = chai;

/**
 * Validates value equality using equals utility.
 * @param {unknown} actual
 * @param {unknown} expected
 * @returns {boolean}
 */
export function checkEquality(actual, expected) {
  return equals(actual, expected);
}

/**
 * Validates subset relationship using subsetEquality utility.
 * @param {unknown} object
 * @param {unknown} subset
 * @returns {boolean}
 */
export function checkSubset(object, subset) {
  return Boolean(subsetEquality(object, subset));
}

/**
 * Validates iterable equality using iterableEquality utility.
 * @param {unknown} a
 * @param {unknown} b
 * @returns {boolean}
 */
export function checkIterableEquality(a, b) {
  return Boolean(iterableEquality(a, b));
}

/**
 * Creates an Any asymmetric matcher instance.
 * @param {unknown} sampleType
 * @returns {Any}
 */
export function createAnyMatcher(sampleType) {
  return new Any(sampleType);
}

/**
 * Creates a StringContaining asymmetric matcher instance.
 * @param {string} substring
 * @returns {StringContaining}
 */
export function createStringContainingMatcher(substring) {
  return new StringContaining(substring);
}

/**
 * Registers custom matcher using expect.extend.
 * @param {Record<string, Function>} matchers
 */
export function registerCustomMatchers(matchers) {
  expect.extend(expect, matchers);
}

export {
  expect,
  JestChaiExpect,
  JestAsymmetricMatchers,
  JestExtend,
  equals,
  subsetEquality,
  iterableEquality,
  StringContaining,
  ArrayContaining,
  ObjectContaining,
  Any,
  Anything,
  StringMatching,
  getState,
  setState,
  customMatchers
};
test/contract.mjs
import assert from 'node:assert';
import {
  expect,
  checkEquality,
  checkSubset,
  checkIterableEquality,
  createAnyMatcher,
  createStringContainingMatcher,
  registerCustomMatchers,
  getState,
  setState,
  StringContaining,
  ArrayContaining,
  ObjectContaining,
  Any,
  Anything,
  StringMatching
} from '../src/index.mjs';

// 1. JestChaiExpect plugin integrates Jest-compatible expect matchers into Chai
expect(42).toBe(42);
expect(42).not.toBe(100);
expect({ key: 'val', list: [1, 2] }).toEqual({ key: 'val', list: [1, 2] });
expect({ a: 1, b: 2, c: 3 }).toMatchObject({ a: 1, b: 2 });
expect([10, 20, 30]).toContain(20);
expect('clean-room testing').toContain('clean-room');
expect('pattern-123').toMatch(/^[a-z]+-\d+$/);
expect(true).toBeTruthy();
expect(false).toBeFalsy();
expect(null).toBeNull();
expect(undefined).toBeUndefined();
expect(NaN).toBeNaN();
expect(() => {
  throw new Error('expected failure message');
}).toThrow('expected failure message');

// 2. JestAsymmetricMatchers provides asymmetric matchers like any, stringContaining, arrayContaining, objectContaining, and anything
const payload = {
  id: 101,
  title: 'sample contract test',
  items: ['alpha', 'beta', 'gamma'],
  metadata: { active: true, priority: 1 },
  arbitrary: 'present'
};

expect(payload).toEqual({
  id: expect.any(Number),
  title: expect.stringContaining('contract'),
  items: expect.arrayContaining(['beta']),
  metadata: expect.objectContaining({ active: true }),
  arbitrary: expect.anything()
});

// 3. Asymmetric matcher classes evaluate matching correctly
const stringMatcher = createStringContainingMatcher('contract');
assert.strictEqual(stringMatcher.asymmetricMatch('sample contract test'), true, 'StringContaining should match substring');
assert.strictEqual(stringMatcher.asymmetricMatch('other test'), false, 'StringContaining should not match non-substring');

const numberMatcher = createAnyMatcher(Number);
assert.strictEqual(numberMatcher.asymmetricMatch(12345), true, 'Any(Number) should match numbers');
assert.strictEqual(numberMatcher.asymmetricMatch('12345'), false, 'Any(Number) should not match strings');

const anythingMatcher = new Anything();
assert.strictEqual(anythingMatcher.asymmetricMatch('hello'), true, 'Anything should match strings');
assert.strictEqual(anythingMatcher.asymmetricMatch(0), true, 'Anything should match zero');
assert.strictEqual(anythingMatcher.asymmetricMatch(null), false, 'Anything should reject null');
assert.strictEqual(anythingMatcher.asymmetricMatch(undefined), false, 'Anything should reject undefined');

const arrayMatcher = new ArrayContaining(['alpha', 'gamma']);
assert.strictEqual(arrayMatcher.asymmetricMatch(['alpha', 'beta', 'gamma']), true, 'ArrayContaining should match subset array');
assert.strictEqual(arrayMatcher.asymmetricMatch(['beta', 'delta']), false, 'ArrayContaining should reject missing elements');

const objMatcher = new ObjectContaining({ active: true });
assert.strictEqual(objMatcher.asymmetricMatch({ active: true, priority: 1 }), true, 'ObjectContaining should match object subset');
assert.strictEqual(objMatcher.asymmetricMatch({ active: false, priority: 1 }), false, 'ObjectContaining should reject mismatched property');

const regexMatcher = new StringMatching(/^sample/);
assert.strictEqual(regexMatcher.asymmetricMatch('sample test'), true, 'StringMatching should match regexp');
assert.strictEqual(regexMatcher.asymmetricMatch('other test'), false, 'StringMatching should reject non-matching string');

// 4. Standalone utility functions (equals, subsetEquality, iterableEquality) verify structural and subset equality
assert.strictEqual(checkEquality({ a: 1, b: [2] }, { a: 1, b: [2] }), true, 'equals should return true for equal objects');
assert.strictEqual(checkEquality({ a: 1 }, { a: 2 }), false, 'equals should return false for unequal objects');

assert.strictEqual(checkSubset({ x: 10, y: 20, z: 30 }, { x: 10, z: 30 }), true, 'subsetEquality should return true for valid subset');
assert.strictEqual(checkSubset({ x: 10 }, { x: 99 }), false, 'subsetEquality should return false for differing values');

assert.strictEqual(checkIterableEquality(new Set([1, 2, 3]), new Set([3, 2, 1])), true, 'iterableEquality should match unordered sets');

// 5. getState and setState inspect and update matcher state
setState({ testRunId: 'sample-run-1' }, expect);
const state = getState(expect);
assert.strictEqual(state.testRunId, 'sample-run-1', 'getState should retrieve updated matcher state');

// 6. expect.extend registers custom matchers
registerCustomMatchers({
  toBePositiveEven(received) {
    const pass = typeof received === 'number' && received > 0 && received % 2 === 0;
    return {
      pass,
      message: () => pass
        ? `expected ${received} not to be a positive even number`
        : `expected ${received} to be a positive even number`
    };
  }
});

expect(8).toBePositiveEven();
expect(-4).not.toBePositiveEven();
expect(7).not.toBePositiveEven();

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

オリジンシーダー

匿名