CodeSampleX

샘플

@vitest/mocker 3.2.7: RedirectedModule

검증된 샘플 — npm @vitest/mocker 3.2.7: RedirectedModule. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: RedirectedModule creates instance with raw…

sha256:f3bd66dec3b1bb300fa5c56b459527e8a4a1fca0af3c91e5794b255a2f82ef25

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

실행 증거

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

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

검증 실행 환경

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

케이스

HOW
목표
verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7
패키지
심벌
  • @vitest/mocker.RedirectedModule
생성일
2026-08-23T14:53:30Z

컨트랙트

  1. RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'
  2. RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type
  3. RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data
  4. MockerRegistry registers and resolves RedirectedModule instances by url and id

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7
Kind: HOW

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

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:175d879f1656ded2dd5233447ba14bbe44f0892925d54b2a63c6545ee96243c4","contract":["RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'","RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type","RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data","MockerRegistry registers and resolves RedirectedModule instances by url and id"],"goal":"verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7","kind":"HOW","packages":["pkg:npm/%40vitest/mocker@3.2.7"],"schemaVersion":1,"symbols":["@vitest/mocker.RedirectedModule"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40vitest/mocker@3.2.7"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/mocker@3.2.7","symbols":["@vitest/mocker.RedirectedModule"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vitest-mocker-redirected-module",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-mocker-redirected-module",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vitest/mocker": "3.2.7"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "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": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.7.tgz",
      "integrity": "sha512-Trr0hYO9CM3Wj6ksWHRhK9IZpIY6wTMO5u/MqXurMxT57sWBaOPEtP3Oq60ihZuh5JsiagKfz95OcxdEP6dBrA==",
      "license": "MIT",
      "dependencies": {
        "@vitest/spy": "3.2.7",
        "estree-walker": "^3.0.3",
        "magic-string": "^0.30.17"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      },
      "peerDependencies": {
        "msw": "^2.4.9",
        "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
      },
      "peerDependenciesMeta": {
        "msw": {
          "optional": true
        },
        "vite": {
          "optional": true
        }
      }
    },
    "node_modules/@vitest/spy": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.7.tgz",
      "integrity": "sha512-Q2eQGI6d2L/hBtZ0qNuKcAGid68XK6cv1xsoaIma6PaJhHPoqcEJhYpXZ/5myCMqkNgtP6UKuBhbc0nHKnrkuQ==",
      "license": "MIT",
      "dependencies": {
        "tinyspy": "^4.0.3"
      },
      "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"
      }
    },
    "node_modules/tinyspy": {
      "version": "4.0.4",
      "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.4.tgz",
      "integrity": "sha512-azl+t0z7pw/z958Gy9svOTuzqIk6xq+NSheJzn5MMWtWTFywIacg2wUlzKFGtt3cthx0r2SxMK0yzJOR0IES7Q==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-mocker-redirected-module",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@vitest/mocker": "3.2.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/mocker@3.2.7"
  ],
  "symbols": [
    "@vitest/mocker.RedirectedModule"
  ]
}
src/index.mjs
import { RedirectedModule, MockerRegistry } from "@vitest/mocker";

export function createRedirectedModule(raw, id, url, redirect) {
  return new RedirectedModule(raw, id, url, redirect);
}

export function serializeRedirectedModule(module) {
  return module.toJSON();
}

export function deserializeRedirectedModule(data) {
  return RedirectedModule.fromJSON(data);
}

export function registerRedirect(registry, raw, id, url, redirect) {
  return registry.register("redirect", raw, id, url, redirect);
}

export { RedirectedModule, MockerRegistry };
test/contract.mjs
import assert from "node:assert/strict";
import { RedirectedModule, MockerRegistry } from "@vitest/mocker";
import {
  createRedirectedModule,
  serializeRedirectedModule,
  deserializeRedirectedModule,
  registerRedirect
} from "../src/index.mjs";

// Test 1: RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'
{
  const raw = "axios";
  const id = "/mock/path/node_modules/axios/index.js";
  const url = "/@mock/axios";
  const redirect = "/mock/path/mocks/axios.js";

  const module = createRedirectedModule(raw, id, url, redirect);
  assert.equal(module instanceof RedirectedModule, true);
  assert.equal(module.type, "redirect");
  assert.equal(module.raw, raw);
  assert.equal(module.id, id);
  assert.equal(module.url, url);
  assert.equal(module.redirect, redirect);
}

// Test 2: RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type
{
  const raw = "lodash";
  const id = "/project/node_modules/lodash/index.js";
  const url = "/@mock/lodash";
  const redirect = "/project/mocks/lodash.js";

  const module = new RedirectedModule(raw, id, url, redirect);
  const serialized = serializeRedirectedModule(module);

  assert.deepEqual(serialized, {
    type: "redirect",
    url: "/@mock/lodash",
    raw: "lodash",
    id: "/project/node_modules/lodash/index.js",
    redirect: "/project/mocks/lodash.js"
  });
}

// Test 3: RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data
{
  const serialized = {
    type: "redirect",
    url: "/@mock/service",
    raw: "my-service",
    id: "/app/src/service.js",
    redirect: "/app/src/__mocks__/service.js"
  };

  const reconstructed = deserializeRedirectedModule(serialized);
  assert.equal(reconstructed instanceof RedirectedModule, true);
  assert.equal(reconstructed.type, "redirect");
  assert.equal(reconstructed.raw, serialized.raw);
  assert.equal(reconstructed.id, serialized.id);
  assert.equal(reconstructed.url, serialized.url);
  assert.equal(reconstructed.redirect, serialized.redirect);
}

// Test 4: MockerRegistry registers and resolves RedirectedModule instances by url and id
{
  const registry = new MockerRegistry();
  const raw = "database";
  const id = "/app/src/db.js";
  const url = "/@mock/db";
  const redirect = "/app/test/mock-db.js";

  const registered = registerRedirect(registry, raw, id, url, redirect);
  assert.equal(registered instanceof RedirectedModule, true);
  assert.equal(registered.type, "redirect");

  assert.equal(registry.has(url), true);
  assert.equal(registry.get(url), registered);
  assert.equal(registry.getById(id), registered);

  // Deserialized registration
  const serialized = registered.toJSON();
  const registry2 = new MockerRegistry();
  const registeredFromJSON = registry2.register(serialized);
  assert.equal(registeredFromJSON instanceof RedirectedModule, true);
  assert.equal(registry2.has(url), true);
  assert.equal(registry2.get(url)?.redirect, redirect);
  assert.equal(registry2.getById(id)?.redirect, redirect);
}

console.log("All @vitest/mocker.RedirectedModule contract tests passed successfully.");

오리진 시더

익명