示例
@vitest/expect 2.1.9: Any
已验证示例 — npm @vitest/expect 2.1.9: Any. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert Any constructor throws TypeError when called without…
sha256:3a2e82b8325337c7750537c7a7c32680a656f33c649fd8fbce6c4e49cae5967a
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-03 |
案例
HOW- 目标
- verify @vitest/expect.Any in pkg:npm/%40vitest/expect@2.1.9
- 符号
-
- @vitest/expect.Any
- 环境
- node 22.23.2
- 创建时间
- 2026-09-03T15:57:56Z
契约
- assert Any constructor throws TypeError when called without arguments or with undefined
- assert Any matches primitive types String, Number, Boolean, BigInt, and Symbol
- assert Any matches Function and Object instances while rejecting non-matching types
- assert Any matches standard and custom constructor instances via instanceof
- assert Any returns expected type names and formatted matcher string representations
- assert Any integrates with deep equality comparison across nested objects and arrays
文件
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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 @vitest/expect.Any in pkg:npm/%40vitest/expect@2.1.9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40vitest/expect@2.1.9
Demonstrate these symbols/APIs:
- @vitest/expect.Any
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.
{"case":{"caseId":"case:sha256:0e4528d848456ba50efb20cbe8e62863e9f76ad4895caf52d8384c328989bd7d","contract":["assert Any constructor throws TypeError when called without arguments or with undefined","assert Any matches primitive types String, Number, Boolean, BigInt, and Symbol","assert Any matches Function and Object instances while rejecting non-matching types","assert Any matches standard and custom constructor instances via instanceof","assert Any returns expected type names and formatted matcher string representations","assert Any integrates with deep equality comparison across nested objects and arrays"],"goal":"verify @vitest/expect.Any in pkg:npm/%40vitest/expect@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"symbols":["@vitest/expect.Any"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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@2.1.9"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/expect@2.1.9","symbols":["@vitest/expect.Any"],"verifierAdapter":"node-typescript@1"}
import { Any, equals } from '@vitest/expect';
/**
* Creates an Any asymmetric matcher instance for the given constructor function.
* Throws TypeError if constructor is undefined.
*
* @param {Function} expected - The constructor function to match against.
* @returns {Any} The asymmetric matcher instance.
*/
export function createAnyMatcher(expected) {
return new Any(expected);
}
/**
* Checks whether the target value matches the expected constructor using Any.
*
* @param {unknown} value - The value to test.
* @param {Function} expected - The constructor function.
* @returns {boolean} True if the value matches the constructor.
*/
export function matchesAny(value, expected) {
const matcher = new Any(expected);
return matcher.asymmetricMatch(value);
}
/**
* Compares an actual value or structure against expected structure containing Any matchers.
*
* @param {unknown} actual - The actual value or object.
* @param {unknown} expected - The expected value or schema containing matchers.
* @returns {boolean} True if values match.
*/
export function matchStructure(actual, expected) {
return equals(actual, expected);
}
export { Any, equals };
{
"name": "sample-vitest-expect-any",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-vitest-expect-any",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@vitest/expect": "2.1.9"
}
},
"node_modules/@vitest/expect": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.9.tgz",
"integrity": "sha512-UJCIkTBenHeKT1TTlKMJWy1laZewsRIzYighyYiJKZreqtdxSos/S1t+ktRMQWu2CKqaarrkeszJx1cgC5tGZw==",
"license": "MIT",
"dependencies": {
"@vitest/spy": "2.1.9",
"@vitest/utils": "2.1.9",
"chai": "^5.1.2",
"tinyrainbow": "^1.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@vitest/pretty-format": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.9.tgz",
"integrity": "sha512-KhRIdGV2U9HOUzxfiHmY8IFHTdqtOhIzCpd8WRdJiE7D/HUcZVD0EgQCVjm+Q9gkUXWgBvMmTtZgIG48wq7sOQ==",
"license": "MIT",
"dependencies": {
"tinyrainbow": "^1.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@vitest/spy": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.9.tgz",
"integrity": "sha512-E1B35FwzXXTs9FHNK6bDszs7mtydNi5MIfUWpceJ8Xbfb1gBMscAnwLbEu+B44ed6W3XjL9/ehLPHR1fkf1KLQ==",
"license": "MIT",
"dependencies": {
"tinyspy": "^3.0.2"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@vitest/utils": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz",
"integrity": "sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==",
"license": "MIT",
"dependencies": {
"@vitest/pretty-format": "2.1.9",
"loupe": "^3.1.2",
"tinyrainbow": "^1.2.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": "1.2.0",
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz",
"integrity": "sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/tinyspy": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz",
"integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
}
}
}
{
"name": "sample-vitest-expect-any",
"version": "1.0.0",
"description": "Clean-room verification sample for @vitest/expect Any asymmetric matcher",
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"license": "MIT-0",
"dependencies": {
"@vitest/expect": "2.1.9"
}
}
{
"schemaVersion": 1,
"goal": "verify @vitest/expect.Any in pkg:npm/%40vitest/expect@2.1.9",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/expect@2.1.9"
],
"symbols": [
"@vitest/expect.Any"
]
}
import assert from 'node:assert/strict';
import {
Any,
equals,
createAnyMatcher,
matchesAny,
matchStructure,
} from '../index.mjs';
async function runContract() {
// 1. assert Any constructor throws TypeError when called without arguments or with undefined
assert.throws(
() => new Any(),
(err) => err instanceof TypeError && err.message.includes('any() expects to be passed a constructor function')
);
assert.throws(
() => createAnyMatcher(undefined),
(err) => err instanceof TypeError && err.message.includes('any() expects to be passed a constructor function')
);
// 2. assert Any matches primitive types String, Number, Boolean, BigInt, and Symbol
const strMatcher = new Any(String);
assert.strictEqual(strMatcher.asymmetricMatch('sample string'), true);
assert.strictEqual(strMatcher.asymmetricMatch(new String('boxed')), true);
assert.strictEqual(strMatcher.asymmetricMatch(123), false);
assert.strictEqual(strMatcher.asymmetricMatch(null), false);
assert.strictEqual(matchesAny('checked via helper', String), true);
const numMatcher = new Any(Number);
assert.strictEqual(numMatcher.asymmetricMatch(42), true);
assert.strictEqual(numMatcher.asymmetricMatch(3.14159), true);
assert.strictEqual(numMatcher.asymmetricMatch(NaN), true);
assert.strictEqual(numMatcher.asymmetricMatch(Infinity), true);
assert.strictEqual(numMatcher.asymmetricMatch(new Number(7)), true);
assert.strictEqual(numMatcher.asymmetricMatch('42'), false);
const boolMatcher = new Any(Boolean);
assert.strictEqual(boolMatcher.asymmetricMatch(true), true);
assert.strictEqual(boolMatcher.asymmetricMatch(false), true);
assert.strictEqual(boolMatcher.asymmetricMatch(new Boolean(false)), true);
assert.strictEqual(boolMatcher.asymmetricMatch(1), false);
assert.strictEqual(boolMatcher.asymmetricMatch(0), false);
const bigIntMatcher = new Any(BigInt);
assert.strictEqual(bigIntMatcher.asymmetricMatch(100n), true);
assert.strictEqual(bigIntMatcher.asymmetricMatch(100), false);
const symbolMatcher = new Any(Symbol);
assert.strictEqual(symbolMatcher.asymmetricMatch(Symbol('key')), true);
assert.strictEqual(symbolMatcher.asymmetricMatch('key'), false);
// 3. assert Any matches Function and Object instances while rejecting non-matching types
const fnMatcher = new Any(Function);
assert.strictEqual(fnMatcher.asymmetricMatch(() => {}), true);
assert.strictEqual(fnMatcher.asymmetricMatch(async function() {}), true);
assert.strictEqual(fnMatcher.asymmetricMatch(class TempClass {}), true);
assert.strictEqual(fnMatcher.asymmetricMatch({}), false);
const objMatcher = new Any(Object);
assert.strictEqual(objMatcher.asymmetricMatch({ key: 'val' }), true);
assert.strictEqual(objMatcher.asymmetricMatch([1, 2, 3]), true);
assert.strictEqual(objMatcher.asymmetricMatch('string'), false);
assert.strictEqual(objMatcher.asymmetricMatch(42), false);
// 4. assert Any matches standard and custom constructor instances via instanceof
class CustomUser {
constructor(name) {
this.name = name;
}
}
class OtherEntity {}
const dateMatcher = new Any(Date);
assert.strictEqual(dateMatcher.asymmetricMatch(new Date()), true);
assert.strictEqual(dateMatcher.asymmetricMatch('2026-09-03'), false);
const regexMatcher = new Any(RegExp);
assert.strictEqual(regexMatcher.asymmetricMatch(/test/i), true);
assert.strictEqual(regexMatcher.asymmetricMatch('test'), false);
const errorMatcher = new Any(Error);
assert.strictEqual(errorMatcher.asymmetricMatch(new Error('failure')), true);
assert.strictEqual(errorMatcher.asymmetricMatch(new TypeError('type fail')), true);
assert.strictEqual(errorMatcher.asymmetricMatch({ message: 'failure' }), false);
const userMatcher = new Any(CustomUser);
assert.strictEqual(userMatcher.asymmetricMatch(new CustomUser('test')), true);
assert.strictEqual(userMatcher.asymmetricMatch(new OtherEntity()), false);
// 5. assert Any returns expected type names and formatted matcher string representations
assert.strictEqual(new Any(String).toString(), 'Any');
assert.strictEqual(new Any(String).getExpectedType(), 'string');
assert.strictEqual(new Any(Number).getExpectedType(), 'number');
assert.strictEqual(new Any(Boolean).getExpectedType(), 'boolean');
assert.strictEqual(new Any(Function).getExpectedType(), 'function');
assert.strictEqual(new Any(Object).getExpectedType(), 'object');
assert.strictEqual(new Any(Date).getExpectedType(), 'Date');
assert.strictEqual(new Any(CustomUser).getExpectedType(), 'CustomUser');
assert.strictEqual(new Any(String).toAsymmetricMatcher(), 'Any<String>');
assert.strictEqual(new Any(Number).toAsymmetricMatcher(), 'Any<Number>');
assert.strictEqual(new Any(Date).toAsymmetricMatcher(), 'Any<Date>');
assert.strictEqual(new Any(CustomUser).toAsymmetricMatcher(), 'Any<CustomUser>');
// 6. assert Any integrates with deep equality comparison across nested objects and arrays
const payload = {
id: 101,
meta: {
createdAt: new Date(),
tags: ['alpha', 'beta'],
},
handler: () => true,
};
const schema = {
id: new Any(Number),
meta: {
createdAt: new Any(Date),
tags: new Any(Array),
},
handler: new Any(Function),
};
assert.strictEqual(matchStructure(payload, schema), true);
assert.strictEqual(equals(payload, schema), true);
const mismatchedPayload = {
id: 'not-a-number',
meta: payload.meta,
handler: payload.handler,
};
assert.strictEqual(equals(mismatchedPayload, schema), false);
assert.strictEqual(
equals([1, 'abc', false], [new Any(Number), new Any(String), new Any(Boolean)]),
true
);
console.log('Contract assertions passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
原始种子者
匿名