CodeSampleX

Exemplo

@jest/pattern 30.4.0: TestPathPatternsExecutor

Amostra verificada para npm @jest/pattern 30.4.0: TestPathPatternsExecutor. O contrato rodou em node 22 · linux debian/x64 · docker e passou.

sha256:1e72664b4cdcdac756a442fa4b62f51e37f575afec149098e2dcdf2d159a258b

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-03

Caso

HOW
Objetivo
verify @jest/pattern.TestPathPatternsExecutor in pkg:npm/%40jest/pattern@30.4.0
Pacotes
Símbolos
  • @jest/pattern.TestPathPatternsExecutor
Ambiente
node 22.23.2
Criado
2026-09-03T04:30:13Z

Contrato

  1. TestPathPatternsExecutor can be instantiated directly with TestPathPatterns and rootDir options, exposing the patterns property
  2. TestPathPatternsExecutor reports isSet false, isValid true, toPretty empty, and matches any path when patterns are empty
  3. TestPathPatternsExecutor matches absolute paths against relative patterns within rootDir and reports isSet true
  4. TestPathPatternsExecutor supports leading dot-slash patterns anchored to the root directory relative path
  5. TestPathPatternsExecutor reports isValid false and throws SyntaxError on isMatch when patterns contain invalid regex syntax

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/pattern.TestPathPatternsExecutor in 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:
  - @jest/pattern.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:a2c5c568d3d6ff706a86c437ce76bbfae9f63810f35b75fb53c5a81df22fa4c9","contract":["TestPathPatternsExecutor can be instantiated directly with TestPathPatterns and rootDir options, exposing the patterns property","TestPathPatternsExecutor reports isSet false, isValid true, toPretty empty, and matches any path when patterns are empty","TestPathPatternsExecutor matches absolute paths against relative patterns within rootDir and reports isSet true","TestPathPatternsExecutor supports leading dot-slash patterns anchored to the root directory relative path","TestPathPatternsExecutor reports isValid false and throws SyntaxError on isMatch when patterns contain invalid regex syntax"],"goal":"verify @jest/pattern.TestPathPatternsExecutor in pkg:npm/%40jest/pattern@30.4.0","kind":"HOW","packages":["pkg:npm/%40jest/pattern@30.4.0"],"schemaVersion":1,"symbols":["@jest/pattern.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":["@jest/pattern.TestPathPatternsExecutor"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-jest-pattern-executor",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-jest-pattern-executor",
      "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.1",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-26.4.1.tgz",
      "integrity": "sha512-k97ENvZWtvA6yqz5/FS6a7duDgOPEeOQOc2iKS/nY6mX6qJUKtLnWzQS+Xj6tXweyj6ZcTAK2Qecetnvi9nCLA==",
      "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-executor",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for @jest/pattern 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 @jest/pattern.TestPathPatternsExecutor in pkg:npm/%40jest/pattern@30.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40jest/pattern@30.4.0"
  ],
  "symbols": [
    "@jest/pattern.TestPathPatternsExecutor"
  ]
}
src/index.js
const { TestPathPatterns, TestPathPatternsExecutor } = require('@jest/pattern');

/**
 * Creates a TestPathPatternsExecutor directly with patterns and root directory.
 * @param {string[]} patterns
 * @param {string} rootDir
 * @returns {TestPathPatternsExecutor}
 */
function createExecutor(patterns = [], rootDir = '/') {
  const pathPatterns = new TestPathPatterns(patterns);
  return new TestPathPatternsExecutor(pathPatterns, { rootDir });
}

/**
 * Checks whether an absolute path matches the patterns relative to rootDir.
 * @param {TestPathPatternsExecutor} executor
 * @param {string} absPath
 * @returns {boolean}
 */
function testPath(executor, absPath) {
  return executor.isMatch(absPath);
}

module.exports = {
  TestPathPatterns,
  TestPathPatternsExecutor,
  createExecutor,
  testPath,
};
test/contract.js
const assert = require('node:assert');
const {
  TestPathPatterns,
  TestPathPatternsExecutor,
  createExecutor,
  testPath,
} = require('../src/index.js');

// 1. TestPathPatternsExecutor can be instantiated directly with TestPathPatterns and rootDir options, exposing the patterns property
{
  const patterns = new TestPathPatterns(['src/.*', 'test/.*']);
  const executor = new TestPathPatternsExecutor(patterns, { rootDir: '/workspace/project' });

  assert.strictEqual(executor instanceof TestPathPatternsExecutor, true);
  assert.strictEqual(executor.patterns, patterns);
  assert.deepStrictEqual(executor.patterns.patterns, ['src/.*', 'test/.*']);
}

// 2. TestPathPatternsExecutor reports isSet false, isValid true, toPretty empty, and matches any path when patterns are empty
{
  const emptyExecutor = createExecutor([], '/workspace/project');

  assert.strictEqual(emptyExecutor.isSet(), false);
  assert.strictEqual(emptyExecutor.isValid(), true);
  assert.strictEqual(emptyExecutor.toPretty(), '');

  assert.strictEqual(testPath(emptyExecutor, '/workspace/project/src/index.js'), true);
  assert.strictEqual(testPath(emptyExecutor, '/anywhere/else/file.txt'), true);
}

// 3. TestPathPatternsExecutor matches absolute paths against relative patterns within rootDir and reports isSet true
{
  const rootDir = '/workspace/project';
  const patterns = ['src/components/.*', 'tests/.*\\.spec\\.js'];
  const executor = createExecutor(patterns, rootDir);

  assert.strictEqual(executor.isSet(), true);
  assert.strictEqual(executor.isValid(), true);
  assert.strictEqual(executor.toPretty(), 'src/components/.*|tests/.*\\.spec\\.js');

  // Matching paths
  assert.strictEqual(testPath(executor, '/workspace/project/src/components/Button.jsx'), true);
  assert.strictEqual(testPath(executor, '/workspace/project/tests/Button.spec.js'), true);

  // Non-matching paths
  assert.strictEqual(testPath(executor, '/workspace/project/docs/api.md'), false);
  assert.strictEqual(testPath(executor, '/workspace/project/src/utils/math.js'), false);
}

// 4. TestPathPatternsExecutor supports leading dot-slash patterns anchored to the root directory relative path
{
  const rootDir = '/workspace/project';
  const dotSlashExecutor = createExecutor(['./src/api'], rootDir);

  assert.strictEqual(dotSlashExecutor.isSet(), true);
  assert.strictEqual(dotSlashExecutor.isValid(), true);

  // Leading ./ is anchored at the start of the path relative to rootDir
  assert.strictEqual(testPath(dotSlashExecutor, '/workspace/project/src/api/client.js'), true);
  assert.strictEqual(testPath(dotSlashExecutor, '/workspace/project/submodule/src/api/client.js'), false);
}

// 5. TestPathPatternsExecutor reports isValid false and throws SyntaxError on isMatch when patterns contain invalid regex syntax
{
  const invalidExecutor = createExecutor(['[unclosed-bracket('], '/workspace/project');

  assert.strictEqual(invalidExecutor.isSet(), true);
  assert.strictEqual(invalidExecutor.isValid(), false);
  assert.throws(
    () => {
      testPath(invalidExecutor, '/workspace/project/src/index.js');
    },
    {
      name: 'SyntaxError',
    }
  );
}

console.log('Contract assertions passed successfully.');

Seeder de origem

anônimo