CodeSampleX

Beispiel

@vitest/pretty-format 4.1.11: format, plugins, DEFAULT_OPTIONS

Verifiziertes Beispiel für npm @vitest/pretty-format 4.1.11: format, plugins, DEFAULT_OPTIONS. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und…

sha256:c5c2ef3ea1ed23b1f2c5fb4909ba2913d70f1425ce2d29c9f74c42e19c4702b0

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-28

Fall

HOW
Ziel
verify pkg:npm/%40vitest/pretty-format@4.1.11
Pakete
Symbole
  • format
  • plugins
  • DEFAULT_OPTIONS
Umgebung
node 22.23.2
Erstellt
2026-08-28T06:13:23Z

Contract

  1. format serializes primitive values including strings, numbers, booleans, symbols, null, undefined, and BigInt
  2. format serializes plain objects and nested arrays with standard indentation
  3. format serializes Set and Map collections with entry representations
  4. format detects circular references and marks recursive pointers as Circular
  5. format respects maxDepth option by truncating objects beyond depth limit
  6. format min option outputs compact single-line JSON-like representation
  7. format custom indent option controls spaces per indentation level
  8. format printFunctionName option controls whether function names are printed
  9. format supports custom plugins implementing test and serialize hooks
  10. format integrates with built-in ReactElement plugin to format JSX-like element structures
  11. DEFAULT_OPTIONS exports default configuration parameters

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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/pretty-format@4.1.11
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/pretty-format@4.1.11
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:4b5339435ac937d847b7caa669c8f0b02e9be5c7fb80b33ea5c190d8b02cc124","constraints":{"executionContext":"node"},"contract":["format serializes primitive values including strings, numbers, booleans, symbols, null, undefined, and BigInt","format serializes plain objects and nested arrays with standard indentation","format serializes Set and Map collections with entry representations","format detects circular references and marks recursive pointers as Circular","format respects maxDepth option by truncating objects beyond depth limit","format min option outputs compact single-line JSON-like representation","format custom indent option controls spaces per indentation level","format printFunctionName option controls whether function names are printed","format supports custom plugins implementing test and serialize hooks","format integrates with built-in ReactElement plugin to format JSX-like element structures","DEFAULT_OPTIONS exports default configuration parameters"],"goal":"verify pkg:npm/%40vitest/pretty-format@4.1.11","kind":"HOW","packages":["pkg:npm/%40vitest/pretty-format@4.1.11"],"schemaVersion":1,"symbols":["format","plugins","DEFAULT_OPTIONS"]},"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/pretty-format@4.1.11"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/pretty-format@4.1.11","symbols":["format","plugins","DEFAULT_OPTIONS"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { format, plugins, DEFAULT_OPTIONS } from '@vitest/pretty-format';

export { format, plugins, DEFAULT_OPTIONS };

export function formatWithCustomPlugin(value, plugin) {
  return format(value, { plugins: [plugin] });
}

export function formatMinified(value) {
  return format(value, { min: true });
}
package-lock.json
{
  "name": "sample-vitest-pretty-format",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-pretty-format",
      "version": "1.0.0",
      "dependencies": {
        "@vitest/pretty-format": "4.1.11"
      }
    },
    "node_modules/@vitest/pretty-format": {
      "version": "4.1.11",
      "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.11.tgz",
      "integrity": "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==",
      "license": "MIT",
      "dependencies": {
        "tinyrainbow": "^3.1.0"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/tinyrainbow": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.1.tgz",
      "integrity": "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-pretty-format",
  "version": "1.0.0",
  "description": "Clean-room verification sample for @vitest/pretty-format",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@vitest/pretty-format": "4.1.11"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40vitest/pretty-format@4.1.11",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/pretty-format@4.1.11"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { format, plugins, DEFAULT_OPTIONS } from '@vitest/pretty-format';
import { formatWithCustomPlugin, formatMinified } from '../index.mjs';

// 1. format serializes primitive values including strings, numbers, booleans, symbols, null, undefined, and BigInt
{
  assert.equal(format('hello world'), '"hello world"');
  assert.equal(format(42), '42');
  assert.equal(format(true), 'true');
  assert.equal(format(null), 'null');
  assert.equal(format(undefined), 'undefined');
  assert.equal(format(Symbol('testKey')), 'Symbol(testKey)');
  assert.equal(format(12345678901234567890n), '12345678901234567890n');
}

// 2. format serializes plain objects and nested arrays with standard indentation
{
  const obj = {
    str: 'value',
    num: 10,
    list: [1, 2],
  };
  const expected = [
    'Object {',
    '  "list": Array [',
    '    1,',
    '    2,',
    '  ],',
    '  "num": 10,',
    '  "str": "value",',
    '}',
  ].join('\n');
  assert.equal(format(obj), expected);
}

// 3. format serializes Set and Map collections with entry representations
{
  const set = new Set(['alpha', 'beta']);
  const setFormatted = format(set);
  assert.ok(setFormatted.includes('Set {'));
  assert.ok(setFormatted.includes('"alpha",'));
  assert.ok(setFormatted.includes('"beta",'));

  const map = new Map([['k1', 'v1'], ['k2', 'v2']]);
  const mapFormatted = format(map);
  assert.ok(mapFormatted.includes('Map {'));
  assert.ok(mapFormatted.includes('"k1" => "v1",'));
  assert.ok(mapFormatted.includes('"k2" => "v2",'));
}

// 4. format detects circular references and marks recursive pointers as Circular
{
  const circular = { name: 'root' };
  circular.self = circular;
  const result = format(circular);
  assert.ok(result.includes('"self": [Circular]'));
}

// 5. format respects maxDepth option by truncating objects beyond depth limit
{
  const deeplyNested = {
    level1: {
      level2: {
        level3: 'deep',
      },
    },
  };
  const shallow = format(deeplyNested, { maxDepth: 1 });
  assert.ok(shallow.includes('"level1": [Object]'));
  assert.ok(!shallow.includes('level3'));
}

// 6. format min option outputs compact single-line JSON-like representation
{
  const data = { a: 1, b: 'two' };
  const minified = format(data, { min: true });
  assert.equal(minified, '{"a": 1, "b": "two"}');
  assert.equal(formatMinified(data), '{"a": 1, "b": "two"}');
}

// 7. format custom indent option controls spaces per indentation level
{
  const data = { x: 1 };
  const formatted4 = format(data, { indent: 4 });
  const expected4 = 'Object {\n    "x": 1,\n}';
  assert.equal(formatted4, expected4);
}

// 8. format printFunctionName option controls whether function names are printed
{
  function sampleFunction() {}
  assert.equal(format(sampleFunction, { printFunctionName: true }), '[Function sampleFunction]');
  assert.equal(format(sampleFunction, { printFunctionName: false }), '[Function]');
}

// 9. format supports custom plugins implementing test and serialize hooks
{
  const customPlugin = {
    test(val) {
      return val && typeof val === 'object' && val.__customBrand === 'Money';
    },
    serialize(val, config, indentation, depth, refs, printer) {
      return `${val.currency} ${val.amount.toFixed(2)}`;
    },
  };

  const payload = {
    price: { __customBrand: 'Money', currency: 'USD', amount: 99.5 },
  };
  const result = format(payload, { plugins: [customPlugin] });
  assert.ok(result.includes('"price": USD 99.50'));

  const resultHelper = formatWithCustomPlugin(payload, customPlugin);
  assert.ok(resultHelper.includes('"price": USD 99.50'));
}

// 10. format integrates with built-in ReactElement plugin to format JSX-like element structures
{
  const element = {
    $$typeof: Symbol.for('react.element'),
    type: 'div',
    props: { className: 'alert-box', children: 'Notice' },
    key: null,
    ref: null,
  };
  const result = format(element, { plugins: [plugins.ReactElement] });
  assert.ok(result.includes('<div'));
  assert.ok(result.includes('className="alert-box"'));
  assert.ok(result.includes('Notice'));
}

// 11. DEFAULT_OPTIONS exports default configuration parameters
{
  assert.equal(DEFAULT_OPTIONS.indent, 2);
  assert.equal(DEFAULT_OPTIONS.min, false);
  assert.equal(DEFAULT_OPTIONS.printFunctionName, true);
  assert.equal(DEFAULT_OPTIONS.escapeString, true);
}

console.log('All @vitest/pretty-format contract assertions passed.');

Ursprungs-Seeder

anonym