CodeSampleX

Ejemplo

@jest/schemas 29.6.3: SnapshotFormat

Muestra verificada para npm @jest/schemas 29.6.3: SnapshotFormat. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:8c0d2b0603882831e77b9e349b0c5f08712a4ac4bea6ea66a159836051d931cc

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify @jest/schemas.SnapshotFormat in pkg:npm/%40jest/schemas@29.6.3
Paquetes
Símbolos
  • @jest/schemas.SnapshotFormat
Creado
2026-08-27T15:25:02Z

Contrato

  1. SnapshotFormat provides a Strict TypeBox JSON schema for Jest snapshot formatting options
  2. validateSnapshotFormat validates full and partial snapshot format configuration objects
  3. validateSnapshotFormat accepts an empty configuration object with all default/optional settings
  4. validateSnapshotFormat rejects negative numbers for indent, maxDepth, and maxWidth
  5. validateSnapshotFormat rejects invalid types and unrecognized properties not defined in SnapshotFormat

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @jest/schemas.SnapshotFormat in 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:
  - @jest/schemas.SnapshotFormat

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:d9e8174a3867d576bb7676a8870d0e827b0c30e2e98777856c01d817115877e4","contract":["SnapshotFormat provides a Strict TypeBox JSON schema for Jest snapshot formatting options","validateSnapshotFormat validates full and partial snapshot format configuration objects","validateSnapshotFormat accepts an empty configuration object with all default/optional settings","validateSnapshotFormat rejects negative numbers for indent, maxDepth, and maxWidth","validateSnapshotFormat rejects invalid types and unrecognized properties not defined in SnapshotFormat"],"goal":"verify @jest/schemas.SnapshotFormat in pkg:npm/%40jest/schemas@29.6.3","kind":"HOW","packages":["pkg:npm/%40jest/schemas@29.6.3"],"schemaVersion":1,"symbols":["@jest/schemas.SnapshotFormat"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40jest/schemas@29.6.3"],"schemaVersion":1,"subject":"pkg:npm/%40jest/schemas@29.6.3","symbols":["@jest/schemas.SnapshotFormat"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "name": "verify-jest-schemas",
  "version": "1.0.0",
  "private": true,
  "description": "Verification sample for @jest/schemas SnapshotFormat",
  "main": "src/index.js",
  "dependencies": {
    "@jest/schemas": "29.6.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @jest/schemas.SnapshotFormat in pkg:npm/%40jest/schemas@29.6.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jest/schemas@29.6.3"
  ],
  "symbols": [
    "@jest/schemas.SnapshotFormat"
  ]
}
src/index.js
const { SnapshotFormat } = require('@jest/schemas');

/**
 * Validates a given options object against the SnapshotFormat schema specifications.
 *
 * @param {Record<string, unknown>} options
 * @returns {{ valid: boolean, errors: string[] }}
 */
function validateSnapshotFormat(options) {
  if (typeof options !== 'object' || options === null || Array.isArray(options)) {
    return {
      valid: false,
      errors: ['Options must be a non-null plain object']
    };
  }

  const errors = [];
  const schemaProps = SnapshotFormat.properties;

  for (const key of Object.keys(options)) {
    if (!Object.prototype.hasOwnProperty.call(schemaProps, key)) {
      errors.push(`Unrecognized 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(`Unrecognized theme property: "${themeKey}"`);
          } else if (val[themeKey] !== undefined && typeof val[themeKey] !== 'string') {
            errors.push(`Property "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)) {
        errors.push(`Option "${key}" must be a number`);
      } else if (propSchema.minimum !== undefined && val < propSchema.minimum) {
        errors.push(`Option "${key}" must be >= ${propSchema.minimum}`);
      }
    } else if (propSchema.type === 'null') {
      if (val !== null) {
        errors.push(`Option "${key}" must be null`);
      }
    }
  }

  return {
    valid: errors.length === 0,
    errors
  };
}

module.exports = {
  SnapshotFormat,
  validateSnapshotFormat
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { SnapshotFormat, validateSnapshotFormat } = require('../src/index.js');

// 1. SnapshotFormat provides a Strict TypeBox JSON schema for Jest snapshot formatting options
assert.strictEqual(typeof SnapshotFormat, 'object', 'SnapshotFormat schema should be an object');
assert.strictEqual(SnapshotFormat.type, 'object', 'SnapshotFormat schema type should be object');
assert.ok(SnapshotFormat.properties, 'SnapshotFormat schema should expose properties');
assert.strictEqual(typeof SnapshotFormat.properties.indent, 'object', 'SnapshotFormat indent property should be defined');
assert.strictEqual(SnapshotFormat.properties.indent.minimum, 0, 'SnapshotFormat indent minimum should be 0');
assert.strictEqual(SnapshotFormat.properties.maxDepth.minimum, 0, 'SnapshotFormat maxDepth minimum should be 0');
assert.strictEqual(SnapshotFormat.properties.maxWidth.minimum, 0, 'SnapshotFormat maxWidth minimum should be 0');
assert.strictEqual(SnapshotFormat.properties.theme.type, 'object', 'SnapshotFormat theme property should be an object');

// 2. validateSnapshotFormat validates full and partial snapshot format configuration objects
const fullValidConfig = {
  callToJSON: true,
  compareKeys: null,
  escapeRegex: false,
  escapeString: true,
  highlight: true,
  indent: 4,
  maxDepth: 5,
  maxWidth: 120,
  min: false,
  printBasicPrototype: false,
  printFunctionName: true,
  theme: {
    comment: 'gray',
    content: 'reset',
    prop: 'yellow',
    tag: 'cyan',
    value: 'green'
  }
};
const fullResult = validateSnapshotFormat(fullValidConfig);
assert.strictEqual(fullResult.valid, true, 'Full valid configuration should pass validation');
assert.strictEqual(fullResult.errors.length, 0, 'No errors for valid configuration');

const partialValidConfig = {
  indent: 2,
  printFunctionName: false
};
const partialResult = validateSnapshotFormat(partialValidConfig);
assert.strictEqual(partialResult.valid, true, 'Partial valid configuration should pass validation');

// 3. validateSnapshotFormat accepts an empty configuration object with all default/optional settings
const emptyResult = validateSnapshotFormat({});
assert.strictEqual(emptyResult.valid, true, 'Empty configuration should be valid as all fields are optional');

// 4. validateSnapshotFormat rejects negative numbers for indent, maxDepth, and maxWidth
const negativeNumbersConfig = {
  indent: -1,
  maxDepth: -5,
  maxWidth: -10
};
const negativeResult = validateSnapshotFormat(negativeNumbersConfig);
assert.strictEqual(negativeResult.valid, false, 'Negative numeric values should fail validation');
assert.ok(negativeResult.errors.some(err => err.includes('indent')), 'Error message must mention indent');
assert.ok(negativeResult.errors.some(err => err.includes('maxDepth')), 'Error message must mention maxDepth');
assert.ok(negativeResult.errors.some(err => err.includes('maxWidth')), 'Error message must mention maxWidth');

// 5. validateSnapshotFormat rejects invalid types and unrecognized properties not defined in SnapshotFormat
const invalidTypesAndUnknownProps = {
  callToJSON: 'yes',
  unknownOption: 123,
  theme: {
    unknownThemeKey: 'red',
    comment: 100
  }
};
const invalidResult = validateSnapshotFormat(invalidTypesAndUnknownProps);
assert.strictEqual(invalidResult.valid, false, 'Invalid types and unknown properties should fail validation');
assert.ok(invalidResult.errors.some(err => err.includes('callToJSON')), 'Error message must mention callToJSON');
assert.ok(invalidResult.errors.some(err => err.includes('unknownOption')), 'Error message must mention unknownOption');
assert.ok(invalidResult.errors.some(err => err.includes('unknownThemeKey')), 'Error message must mention unknownThemeKey');
assert.ok(invalidResult.errors.some(err => err.includes('theme.comment')), 'Error message must mention theme.comment');

const nonObjectResult = validateSnapshotFormat(null);
assert.strictEqual(nonObjectResult.valid, false, 'Non-object input should fail validation');

console.log('All contract tests passed successfully.');

Seeder de origen

anónimo