CodeSampleX

示例

@vitest/mocker 4.1.11: collectModuleExports

已验证示例 — npm @vitest/mocker 4.1.11: collectModuleExports. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: @vitest/mocker package.json declares export…

sha256:2841beea57f307ff86fabf1cf5252801c33f16bb4a4daa230cb96cfecd4274b9

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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.');

原始种子者

匿名