CodeSampleX

샘플

@vitest/mocker 4.1.11: collectModuleExports

검증된 샘플 — npm @vitest/mocker 4.1.11: collectModuleExports. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: @vitest/mocker package.json declares…

sha256:2841beea57f307ff86fabf1cf5252801c33f16bb4a4daa230cb96cfecd4274b9

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-01

케이스

HOW
목표
verify collectModuleExports in pkg:npm/%40vitest/mocker@4.1.11
패키지
심벌
  • collectModuleExports
환경
node 22.23.2
생성일
2026-09-01T19:55:00Z

컨트랙트

  1. @vitest/mocker package.json declares export mappings and version 4.1.11
  2. @vitest/mocker/transforms exports collectModuleExports and initSyntaxLexers functions
  3. initSyntaxLexers initializes WebAssembly syntax lexers successfully
  4. collectModuleExports extracts named and default exports from ECMAScript module syntax
  5. collectModuleExports extracts named exports and re-exports from CommonJS module syntax
  6. collectModuleExports returns an empty array for module code with no exports
  7. collectModuleExports appends discovered exports to an existing exports accumulator array without duplicates
  8. collectModuleExports deduplicates exported identifier names

파일

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

소스 아티팩트 내려받기 (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 collectModuleExports in pkg:npm/%40vitest/mocker@4.1.11
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/mocker@4.1.11
Demonstrate these symbols/APIs:
  - collectModuleExports

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:77bb001305a66422c26b3327040621bb2ff84891713a0d7f102852d528606e94","contract":["@vitest/mocker package.json declares export mappings and version 4.1.11","@vitest/mocker/transforms exports collectModuleExports and initSyntaxLexers functions","initSyntaxLexers initializes WebAssembly syntax lexers successfully","collectModuleExports extracts named and default exports from ECMAScript module syntax","collectModuleExports extracts named exports and re-exports from CommonJS module syntax","collectModuleExports returns an empty array for module code with no exports","collectModuleExports appends discovered exports to an existing exports accumulator array without duplicates","collectModuleExports deduplicates exported identifier names"],"goal":"verify collectModuleExports in pkg:npm/%40vitest/mocker@4.1.11","kind":"HOW","packages":["pkg:npm/%40vitest/mocker@4.1.11"],"schemaVersion":1,"symbols":["collectModuleExports"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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/mocker@4.1.11"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/mocker@4.1.11","symbols":["collectModuleExports"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vitest-mocker-collect-module-exports",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-mocker-collect-module-exports",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vitest/mocker": "4.1.11"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.6.0",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz",
      "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==",
      "license": "MIT"
    },
    "node_modules/@types/estree": {
      "version": "1.0.9",
      "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",
      "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==",
      "license": "MIT"
    },
    "node_modules/@vitest/mocker": {
      "version": "4.1.11",
      "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.11.tgz",
      "integrity": "sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ==",
      "license": "MIT",
      "dependencies": {
        "@vitest/spy": "4.1.11",
        "estree-walker": "^3.0.3",
        "magic-string": "^0.30.21"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      },
      "peerDependencies": {
        "msw": "^2.4.9",
        "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
      },
      "peerDependenciesMeta": {
        "msw": {
          "optional": true
        },
        "vite": {
          "optional": true
        }
      }
    },
    "node_modules/@vitest/spy": {
      "version": "4.1.11",
      "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.11.tgz",
      "integrity": "sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA==",
      "license": "MIT",
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/estree-walker": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
      "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
      "license": "MIT",
      "dependencies": {
        "@types/estree": "^1.0.0"
      }
    },
    "node_modules/magic-string": {
      "version": "0.30.21",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
      "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.5"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-mocker-collect-module-exports",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "@vitest/mocker": "4.1.11"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify collectModuleExports in pkg:npm/%40vitest/mocker@4.1.11",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/mocker@4.1.11"
  ],
  "symbols": [
    "collectModuleExports"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import { collectModuleExports, initSyntaxLexers } from '@vitest/mocker/transforms';

const require = createRequire(import.meta.url);

// Contract 1: @vitest/mocker package.json declares export mappings and version 4.1.11
{
  const pkgJsonPath = require.resolve('@vitest/mocker/package.json');
  assert.ok(fs.existsSync(pkgJsonPath));
  const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
  assert.strictEqual(pkgJson.name, '@vitest/mocker');
  assert.strictEqual(pkgJson.version, '4.1.11');
  assert.ok(pkgJson.exports && pkgJson.exports['./transforms']);
}

// Contract 2: @vitest/mocker/transforms exports collectModuleExports and initSyntaxLexers functions
{
  assert.strictEqual(typeof collectModuleExports, 'function');
  assert.strictEqual(typeof initSyntaxLexers, 'function');
}

// Contract 3: initSyntaxLexers initializes WebAssembly syntax lexers successfully
{
  await initSyntaxLexers();
}

// Contract 4: collectModuleExports extracts named and default exports from ECMAScript module syntax
{
  const esmCode = `
    export const PI = 3.14159;
    export let count = 0;
    export function compute() { return 42; }
    export class Service {}
    const internalValue = 'test';
    export { internalValue as aliasValue };
    export default function main() {}
  `;
  const exportsList = collectModuleExports('sample-module.mjs', esmCode, 'module');
  assert.ok(Array.isArray(exportsList));
  assert.deepStrictEqual(exportsList.sort(), ['PI', 'Service', 'aliasValue', 'compute', 'count', 'default'].sort());
}

// Contract 5: collectModuleExports extracts named exports and re-exports from CommonJS module syntax
{
  const cjsCode = `
    exports.alpha = 1;
    module.exports.beta = 2;
    Object.defineProperty(exports, 'gamma', { value: 3 });
    Object.defineProperty(module.exports, 'delta', { value: 4 });
  `;
  const exportsList = collectModuleExports('sample-module.cjs', cjsCode, 'commonjs');
  assert.ok(Array.isArray(exportsList));
  assert.deepStrictEqual(exportsList.sort(), ['alpha', 'beta', 'delta', 'gamma'].sort());
}

// Contract 6: collectModuleExports returns an empty array for module code with no exports
{
  const noExportsEsm = `
    const a = 1;
    const b = 2;
    function helper() { return a + b; }
  `;
  const esmResult = collectModuleExports('no-exports.mjs', noExportsEsm, 'module');
  assert.deepStrictEqual(esmResult, []);

  const noExportsCjs = `
    const x = 10;
    console.log(x);
  `;
  const cjsResult = collectModuleExports('no-exports.cjs', noExportsCjs, 'commonjs');
  assert.deepStrictEqual(cjsResult, []);
}

// Contract 7: collectModuleExports appends discovered exports to an existing exports accumulator array without duplicates
{
  const initialAccumulator = ['existingExport'];
  const code = `export const extraExport = 'ok';`;
  const result = collectModuleExports('accum.mjs', code, 'module', initialAccumulator);
  assert.deepStrictEqual(result.sort(), ['existingExport', 'extraExport'].sort());
}

// Contract 8: collectModuleExports deduplicates exported identifier names
{
  const duplicateAccumulator = ['dup', 'dup'];
  const code = `export const dup = 1;`;
  const result = collectModuleExports('dup.mjs', code, 'module', duplicateAccumulator);
  assert.deepStrictEqual(result, ['dup']);
}

console.log('All @vitest/mocker collectModuleExports contract tests passed.');

오리진 시더

익명