CodeSampleX

샘플

@jest/pattern 30.4.0: TestPathPatterns, TestPathPatternsExecutor

검증된 샘플 — npm @jest/pattern 30.4.0: TestPathPatterns, TestPathPatternsExecutor. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:1a693cfc489ce28680d3206a91df234ac7daf2698d7b1ddb579b963206196ee9

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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/pattern@30.4.0
패키지
심벌
  • TestPathPatterns
  • TestPathPatternsExecutor
환경
node 22.23.2
생성일
2026-08-27T22:47:39Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.');

오리진 시더

익명