CodeSampleX

Exemple

@jest/pattern 30.4.0: TestPathPatterns, TestPathPatternsExecutor

Échantillon vérifié pour npm @jest/pattern 30.4.0: TestPathPatterns, TestPathPatternsExecutor. Le contrat s'est exécuté sur node 22 · linux alpine/x64 …

sha256:1a693cfc489ce28680d3206a91df234ac7daf2698d7b1ddb579b963206196ee9

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/%40jest/pattern@30.4.0
Paquets
Symboles
  • TestPathPatterns
  • TestPathPatternsExecutor
Environnement
node 22.23.2
Créé
2026-08-27T22:47:39Z

Contrat

  1. TestPathPatterns can be constructed with pattern strings and correctly reports isSet, isValid, toPretty, and toJSON
  2. TestPathPatterns reports isValid as false when given an invalid regex pattern
  3. TestPathPatternsExecutor created from empty patterns matches any absolute path within or outside rootDir
  4. TestPathPatternsExecutor matches paths against relative pattern strings against rootDir
  5. TestPathPatternsExecutor correctly handles patterns with leading dot-slash prefix matching relative to rootDir

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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/%40jest/pattern@30.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40jest/pattern@30.4.0
Demonstrate these symbols/APIs:
  - TestPathPatterns
  - TestPathPatternsExecutor

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:abc0a642a03fd9c653ea24dcbb88f3b48fea1d8eee147fbc416e0e3e4ff97de0","contract":["TestPathPatterns can be constructed with pattern strings and correctly reports isSet, isValid, toPretty, and toJSON","TestPathPatterns reports isValid as false when given an invalid regex pattern","TestPathPatternsExecutor created from empty patterns matches any absolute path within or outside rootDir","TestPathPatternsExecutor matches paths against relative pattern strings against rootDir","TestPathPatternsExecutor correctly handles patterns with leading dot-slash prefix matching relative to rootDir"],"goal":"verify pkg:npm/%40jest/pattern@30.4.0","kind":"HOW","packages":["pkg:npm/%40jest/pattern@30.4.0"],"schemaVersion":1,"symbols":["TestPathPatterns","TestPathPatternsExecutor"]},"contractCommand":["node","test/contract.js"],"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/pattern@30.4.0"],"schemaVersion":1,"subject":"pkg:npm/%40jest/pattern@30.4.0","symbols":["TestPathPatterns","TestPathPatternsExecutor"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-jest-pattern",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-pattern",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@jest/pattern": "30.4.0"
      }
    },
    "node_modules/@jest/pattern": {
      "version": "30.4.0",
      "resolved": "https://registry.npmjs.org/@jest/pattern/-/pattern-30.4.0.tgz",
      "integrity": "sha512-RAWn3+f9u8BsHijKJ71uHcFp6vmyEt6VvoWXkl6hKF3qVIuWNmudVjg12DlBPGup/frIl5UcUlH5HfEuvHpEXg==",
      "license": "MIT",
      "dependencies": {
        "@types/node": "*",
        "jest-regex-util": "30.4.0"
      },
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/@types/node": {
      "version": "26.4.0",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-26.4.0.tgz",
      "integrity": "sha512-faiGnoIrLH/V8cibOMEAZ8pMw6oXqSukl29ra4mN8GdaB2ZewzeaLj+INpV5N+Z1eKWzY+IzaIZH2EIR6YZRNQ==",
      "license": "MIT",
      "dependencies": {
        "undici-types": "~8.3.0"
      }
    },
    "node_modules/jest-regex-util": {
      "version": "30.4.0",
      "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-30.4.0.tgz",
      "integrity": "sha512-mWlvLviKIgIQ8VCuM1xRdD0TWp3zlzionlmDBjuXVBs+VkmXq6FgW9T4Emr7oGz/Rk6feDCGyiugolcQEyp3mg==",
      "license": "MIT",
      "engines": {
        "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
      }
    },
    "node_modules/undici-types": {
      "version": "8.3.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
      "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-jest-pattern",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for @jest/pattern TestPathPatterns and TestPathPatternsExecutor",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@jest/pattern": "30.4.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40jest/pattern@30.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jest/pattern@30.4.0"
  ],
  "symbols": [
    "TestPathPatterns",
    "TestPathPatternsExecutor"
  ]
}
src/index.js
const { TestPathPatterns, TestPathPatternsExecutor } = require('@jest/pattern');

/**
 * Creates a TestPathPatterns instance from an array of pattern strings.
 * @param {string[]} patterns
 * @returns {TestPathPatterns}
 */
function createPathPatterns(patterns = []) {
  return new TestPathPatterns(patterns);
}

/**
 * Creates a TestPathPatternsExecutor instance for the given patterns and root directory.
 * @param {string[]} patterns
 * @param {string} rootDir
 * @returns {TestPathPatternsExecutor}
 */
function createPathMatcher(patterns, rootDir) {
  const testPatterns = createPathPatterns(patterns);
  return testPatterns.toExecutor({ rootDir });
}

/**
 * Tests whether an absolute path matches given patterns relative to rootDir.
 * @param {string[]} patterns
 * @param {string} rootDir
 * @param {string} absPath
 * @returns {boolean}
 */
function matchesPattern(patterns, rootDir, absPath) {
  const executor = createPathMatcher(patterns, rootDir);
  return executor.isMatch(absPath);
}

/**
 * Returns a human-friendly representation of the patterns.
 * @param {string[]} patterns
 * @returns {string}
 */
function formatPatterns(patterns) {
  const testPatterns = createPathPatterns(patterns);
  return testPatterns.toPretty();
}

/**
 * Checks if all patterns in the array are valid regular expressions.
 * @param {string[]} patterns
 * @returns {boolean}
 */
function validatePatterns(patterns) {
  const testPatterns = createPathPatterns(patterns);
  return testPatterns.isValid();
}

module.exports = {
  TestPathPatterns,
  TestPathPatternsExecutor,
  createPathPatterns,
  createPathMatcher,
  matchesPattern,
  formatPatterns,
  validatePatterns,
};
test/contract.js
const assert = require('node:assert');
const {
  TestPathPatterns,
  TestPathPatternsExecutor,
  createPathPatterns,
  createPathMatcher,
  matchesPattern,
  formatPatterns,
  validatePatterns,
} = require('../src/index.js');

// 1. TestPathPatterns can be constructed with pattern strings and correctly reports isSet, isValid, toPretty, and toJSON
const emptyPatterns = createPathPatterns([]);
assert.strictEqual(emptyPatterns.isSet(), false);
assert.strictEqual(emptyPatterns.isValid(), true);
assert.strictEqual(emptyPatterns.toPretty(), '');
assert.deepStrictEqual(emptyPatterns.toJSON(), {
  patterns: [],
  type: 'TestPathPatterns',
});

const samplePatterns = createPathPatterns(['test/.*\\.spec\\.js', 'src/components/.*']);
assert.strictEqual(samplePatterns.isSet(), true);
assert.strictEqual(samplePatterns.isValid(), true);
assert.strictEqual(samplePatterns.toPretty(), 'test/.*\\.spec\\.js|src/components/.*');
assert.strictEqual(formatPatterns(['test/.*\\.spec\\.js', 'src/components/.*']), 'test/.*\\.spec\\.js|src/components/.*');
assert.deepStrictEqual(samplePatterns.toJSON(), {
  patterns: ['test/.*\\.spec\\.js', 'src/components/.*'],
  type: 'TestPathPatterns',
});

// 2. TestPathPatterns reports isValid as false when given an invalid regex pattern
const invalidPatterns = createPathPatterns(['[invalid-regex(']);
assert.strictEqual(invalidPatterns.isSet(), true);
assert.strictEqual(invalidPatterns.isValid(), false);
assert.strictEqual(validatePatterns(['[invalid-regex(']), false);
assert.strictEqual(validatePatterns(['valid/path']), true);

// 3. TestPathPatternsExecutor created from empty patterns matches any absolute path within or outside rootDir
const rootDir = '/workspace/project';
const emptyExecutor = emptyPatterns.toExecutor({ rootDir });
assert.strictEqual(emptyExecutor.isSet(), false);
assert.strictEqual(emptyExecutor.isValid(), true);
assert.strictEqual(emptyExecutor.isMatch('/workspace/project/src/index.js'), true);
assert.strictEqual(emptyExecutor.isMatch('/workspace/project/test/unit.test.js'), true);
assert.strictEqual(emptyExecutor.isMatch('/outside/other.js'), true);
assert.strictEqual(matchesPattern([], rootDir, '/workspace/project/src/index.js'), true);

// 4. TestPathPatternsExecutor matches paths against relative pattern strings against rootDir
const executor = samplePatterns.toExecutor({ rootDir });
assert.strictEqual(executor.isSet(), true);
assert.strictEqual(executor.isValid(), true);
assert.strictEqual(executor.toPretty(), 'test/.*\\.spec\\.js|src/components/.*');

assert.strictEqual(executor.isMatch('/workspace/project/src/components/Button.tsx'), true);
assert.strictEqual(executor.isMatch('/workspace/project/test/Button.spec.js'), true);
assert.strictEqual(executor.isMatch('/workspace/project/docs/readme.md'), false);
assert.strictEqual(executor.isMatch('/workspace/project/src/utils/math.ts'), false);

assert.strictEqual(matchesPattern(['test/.*\\.spec\\.js', 'src/components/.*'], rootDir, '/workspace/project/src/components/Button.tsx'), true);
assert.strictEqual(matchesPattern(['test/.*\\.spec\\.js', 'src/components/.*'], rootDir, '/workspace/project/docs/readme.md'), false);

// 5. TestPathPatternsExecutor correctly handles patterns with leading dot-slash prefix matching relative to rootDir
const dotSlashPatterns = createPathPatterns(['./test/unit']);
const dotSlashExecutor = dotSlashPatterns.toExecutor({ rootDir });
assert.strictEqual(dotSlashExecutor.isMatch('/workspace/project/test/unit/app.test.js'), true);
assert.strictEqual(dotSlashExecutor.isMatch('/workspace/project/other/test/unit/app.test.js'), false);
assert.strictEqual(matchesPattern(['./test/unit'], rootDir, '/workspace/project/test/unit/app.test.js'), true);
assert.strictEqual(matchesPattern(['./test/unit'], rootDir, '/workspace/project/other/test/unit/app.test.js'), false);

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

Seeder d'origine

anonyme