Пример
@jest/schemas 29.6.3: SnapshotFormat
Проверенный пример — npm @jest/schemas 29.6.3: SnapshotFormat. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден.
sha256:c96f49fe39bcdbda0eee1950f8597a57d4a6da64daaa87f896d2b6bdc4ea07d2
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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/%40jest/schemas@29.6.3
- Пакеты
- Символы
-
- SnapshotFormat
- Окружение
- node 22.23.2
- Создан
- 2026-08-27T15:22:44Z
Контракт
- SnapshotFormat schema defines valid Jest snapshot format options with type object and defined properties
- validateSnapshotFormat validates compliant snapshot formatting options
- validateSnapshotFormat accepts empty configuration object as all SnapshotFormat fields are optional
- validateSnapshotFormat rejects non-object inputs and invalid option types
- validateSnapshotFormat rejects negative values for indent, maxDepth, and maxWidth
- validateSnapshotFormat rejects unrecognized options and invalid theme properties
- createSnapshotConfig merges valid partial configuration with default formatting settings
- createSnapshotConfig throws TypeError when provided invalid configuration
Файлы
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 pkg:npm/%40jest/schemas@29.6.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40jest/schemas@29.6.3
Demonstrate these symbols/APIs:
- SnapshotFormat
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.
{"case":{"caseId":"case:sha256:2a20a43c7c898a56eec5941ca3699cbe758d7b57a71230600786c5bdd0caa55c","constraints":{"executionContext":"node"},"contract":["SnapshotFormat schema defines valid Jest snapshot format options with type object and defined properties","validateSnapshotFormat validates compliant snapshot formatting options","validateSnapshotFormat accepts empty configuration object as all SnapshotFormat fields are optional","validateSnapshotFormat rejects non-object inputs and invalid option types","validateSnapshotFormat rejects negative values for indent, maxDepth, and maxWidth","validateSnapshotFormat rejects unrecognized options and invalid theme properties","createSnapshotConfig merges valid partial configuration with default formatting settings","createSnapshotConfig throws TypeError when provided invalid configuration"],"goal":"verify pkg:npm/%40jest/schemas@29.6.3","kind":"HOW","packages":["pkg:npm/%40jest/schemas@29.6.3"],"schemaVersion":1,"symbols":["SnapshotFormat"]},"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/%40jest/schemas@29.6.3"],"schemaVersion":1,"subject":"pkg:npm/%40jest/schemas@29.6.3","symbols":["SnapshotFormat"],"verifierAdapter":"node-typescript@1"}
{
"name": "verify-jest-schemas",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "verify-jest-schemas",
"version": "1.0.0",
"dependencies": {
"@jest/schemas": "29.6.3"
}
},
"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"
}
}
}
{
"name": "verify-jest-schemas",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of @jest/schemas",
"main": "src/index.js",
"dependencies": {
"@jest/schemas": "29.6.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40jest/schemas@29.6.3",
"kind": "HOW",
"packages": [
"pkg:npm/%40jest/schemas@29.6.3"
],
"symbols": [
"SnapshotFormat"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { SnapshotFormat } = require('@jest/schemas');
/**
* Validates a snapshot format configuration object against the SnapshotFormat schema.
*
* @param {unknown} options - Configuration options to validate.
* @returns {{ valid: boolean, errors: string[] }} Result of validation.
*/
function validateSnapshotFormat(options) {
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
return {
valid: false,
errors: ['SnapshotFormat options must be a plain object']
};
}
const errors = [];
const schemaProps = SnapshotFormat.properties;
for (const key of Object.keys(options)) {
if (!Object.prototype.hasOwnProperty.call(schemaProps, key)) {
errors.push(`Unknown option: "${key}"`);
continue;
}
const val = options[key];
if (val === undefined) {
continue;
}
const propSchema = schemaProps[key];
if (key === 'theme') {
if (typeof val !== 'object' || val === null || Array.isArray(val)) {
errors.push('Option "theme" must be an object');
} else {
const themeProps = propSchema.properties;
for (const themeKey of Object.keys(val)) {
if (!Object.prototype.hasOwnProperty.call(themeProps, themeKey)) {
errors.push(`Unknown theme option: "${themeKey}"`);
} else if (val[themeKey] !== undefined && typeof val[themeKey] !== 'string') {
errors.push(`Option "theme.${themeKey}" must be a string`);
}
}
}
} else if (propSchema.type === 'boolean') {
if (typeof val !== 'boolean') {
errors.push(`Option "${key}" must be a boolean`);
}
} else if (propSchema.type === 'number') {
if (typeof val !== 'number' || Number.isNaN(val) || (propSchema.minimum !== undefined && val < propSchema.minimum)) {
errors.push(`Option "${key}" must be a number >= ${propSchema.minimum ?? 0}`);
}
} else if (propSchema.type === 'null') {
if (val !== null) {
errors.push(`Option "${key}" must be null`);
}
}
}
return {
valid: errors.length === 0,
errors
};
}
/**
* Creates a normalized snapshot format configuration applying defaults.
*
* @param {Record<string, unknown>} [customConfig={}] - Partial configuration to normalize.
* @returns {Record<string, unknown>} Normalized configuration object.
* @throws {TypeError} If validation against SnapshotFormat schema fails.
*/
function createSnapshotConfig(customConfig = {}) {
const result = validateSnapshotFormat(customConfig);
if (!result.valid) {
throw new TypeError(`Invalid SnapshotFormat configuration: ${result.errors.join('; ')}`);
}
const defaults = {
callToJSON: true,
escapeRegex: false,
escapeString: true,
highlight: false,
indent: 2,
maxDepth: 10,
maxWidth: 80,
min: false,
printBasicPrototype: true,
printFunctionName: true,
theme: {
comment: 'gray',
content: 'reset',
prop: 'yellow',
tag: 'cyan',
value: 'green'
}
};
const merged = { ...defaults, ...customConfig };
if (customConfig.theme && typeof customConfig.theme === 'object') {
merged.theme = { ...defaults.theme, ...customConfig.theme };
}
return merged;
}
module.exports = {
SnapshotFormat,
validateSnapshotFormat,
createSnapshotConfig
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { SnapshotFormat, validateSnapshotFormat, createSnapshotConfig } = require('../src/index.js');
// 1. Symbol & Schema structure verification
assert.strictEqual(typeof SnapshotFormat, 'object', 'SnapshotFormat should be an object');
assert.strictEqual(SnapshotFormat.type, 'object', 'SnapshotFormat schema type should be object');
assert.ok(SnapshotFormat.properties, 'SnapshotFormat schema should define properties');
assert.strictEqual(typeof SnapshotFormat.properties.indent, 'object', 'indent schema property should exist');
assert.strictEqual(SnapshotFormat.properties.indent.minimum, 0, 'indent minimum should be 0');
assert.strictEqual(SnapshotFormat.properties.theme.type, 'object', 'theme property should be type object');
assert.strictEqual(typeof validateSnapshotFormat, 'function', 'validateSnapshotFormat should be a function');
assert.strictEqual(typeof createSnapshotConfig, 'function', 'createSnapshotConfig should be a function');
// 2. Validate valid snapshot format configuration
const validConfig = {
callToJSON: true,
escapeRegex: false,
escapeString: true,
highlight: false,
indent: 4,
maxDepth: 20,
maxWidth: 120,
min: false,
printBasicPrototype: true,
printFunctionName: true,
theme: {
comment: 'dim',
content: 'reset',
prop: 'cyan',
tag: 'blue',
value: 'yellow'
}
};
const validResult = validateSnapshotFormat(validConfig);
assert.deepStrictEqual(validResult, {
valid: true,
errors: []
}, 'Valid configuration should pass validation without errors');
// 3. Accept empty configuration object (all fields are optional in SnapshotFormat)
const emptyResult = validateSnapshotFormat({});
assert.strictEqual(emptyResult.valid, true, 'Empty configuration should be valid');
assert.strictEqual(emptyResult.errors.length, 0, 'Empty configuration should produce no errors');
// 4. Reject non-object inputs and null
assert.strictEqual(validateSnapshotFormat(null).valid, false, 'null should be rejected');
assert.strictEqual(validateSnapshotFormat('invalid').valid, false, 'string should be rejected');
assert.strictEqual(validateSnapshotFormat(123).valid, false, 'number should be rejected');
assert.strictEqual(validateSnapshotFormat([]).valid, false, 'array should be rejected');
// 5. Reject invalid option types and negative indentation
const invalidTypesConfig = {
callToJSON: 'not-a-boolean',
indent: -1,
compareKeys: 'not-null'
};
const invalidTypesResult = validateSnapshotFormat(invalidTypesConfig);
assert.strictEqual(invalidTypesResult.valid, false, 'Invalid types must fail validation');
assert.ok(invalidTypesResult.errors.some(e => e.includes('callToJSON')), 'Should report error for non-boolean callToJSON');
assert.ok(invalidTypesResult.errors.some(e => e.includes('indent')), 'Should report error for negative indent');
assert.ok(invalidTypesResult.errors.some(e => e.includes('compareKeys')), 'Should report error for non-null compareKeys');
// 6. Reject unknown options and unrecognized theme properties
const unknownPropsConfig = {
extraProperty: true,
theme: {
unknownField: 'value',
comment: 100
}
};
const unknownPropsResult = validateSnapshotFormat(unknownPropsConfig);
assert.strictEqual(unknownPropsResult.valid, false, 'Unknown properties must fail validation');
assert.ok(unknownPropsResult.errors.some(e => e.includes('extraProperty')), 'Should report error for extraProperty');
assert.ok(unknownPropsResult.errors.some(e => e.includes('unknownField')), 'Should report error for unknown theme field');
assert.ok(unknownPropsResult.errors.some(e => e.includes('theme.comment')), 'Should report error for non-string theme comment');
// 7. createSnapshotConfig applies defaults for partial configuration
const partialConfig = { indent: 4, min: true, theme: { tag: 'magenta' } };
const resolvedConfig = createSnapshotConfig(partialConfig);
assert.strictEqual(resolvedConfig.indent, 4, 'indent should be customized');
assert.strictEqual(resolvedConfig.min, true, 'min should be customized');
assert.strictEqual(resolvedConfig.callToJSON, true, 'callToJSON should have default true');
assert.strictEqual(resolvedConfig.theme.tag, 'magenta', 'theme.tag should be customized');
assert.strictEqual(resolvedConfig.theme.comment, 'gray', 'theme.comment should have default gray');
// 8. createSnapshotConfig throws TypeError on invalid configuration
assert.throws(
() => createSnapshotConfig({ indent: -5 }),
TypeError,
'createSnapshotConfig should throw TypeError on invalid input'
);
console.log('All contract assertions passed successfully.');
Исходный сидер
аноним