샘플
@sinonjs/fake-timers 10.3.0: withGlobal
검증된 샘플 — npm @sinonjs/fake-timers 10.3.0: withGlobal. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: withGlobal returns a FakeTimers instance…
sha256:74c73af412a84b53fc22939a8ba115de693938a7869da88466963307183bc743
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-26 |
케이스
HOW- 목표
- verify withGlobal in pkg:npm/%40sinonjs/fake-timers@10.3.0
- 심벌
-
- withGlobal
- 환경
- node 22.23.2
- 생성일
- 2026-08-26T10:36:43Z
컨트랙트
- withGlobal returns a FakeTimers instance bound to the provided custom global object
- install on withGlobal context overrides timer functions on custom global without modifying ambient globalThis
- custom global setTimeout executes callbacks when clock is advanced with tick
- custom global setInterval executes repeatedly at intervals until clearInterval
- clock runAll exhausts all pending timers on the bound custom global context
- clock setSystemTime adjusts custom global Date now without triggering pending timers
- clock.uninstall restores original timer functions on the custom global object
- withGlobal createClock creates an independent clock within the custom global context
- withGlobal allows re-binding to a different target global context
파일
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
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 withGlobal in pkg:npm/%40sinonjs/fake-timers@10.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40sinonjs/fake-timers@10.3.0
Demonstrate these symbols/APIs:
- withGlobal
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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.
{"case":{"caseId":"case:sha256:68872acf4aa00a124f8929fdbdcfe2da23e1df9418ab9058fccc2beec9b49e30","constraints":{"executionContext":"node"},"contract":["withGlobal returns a FakeTimers instance bound to the provided custom global object","install on withGlobal context overrides timer functions on custom global without modifying ambient globalThis","custom global setTimeout executes callbacks when clock is advanced with tick","custom global setInterval executes repeatedly at intervals until clearInterval","clock runAll exhausts all pending timers on the bound custom global context","clock setSystemTime adjusts custom global Date now without triggering pending timers","clock.uninstall restores original timer functions on the custom global object","withGlobal createClock creates an independent clock within the custom global context","withGlobal allows re-binding to a different target global context"],"goal":"verify withGlobal in pkg:npm/%40sinonjs/fake-timers@10.3.0","kind":"HOW","packages":["pkg:npm/%40sinonjs/fake-timers@10.3.0"],"schemaVersion":1,"symbols":["withGlobal"]},"contractCommand":["node","test/contract.mjs"],"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/%40sinonjs/fake-timers@10.3.0"],"schemaVersion":1,"subject":"pkg:npm/%40sinonjs/fake-timers@10.3.0","symbols":["withGlobal"],"verifierAdapter":"node-typescript@1"}
import FakeTimers from '@sinonjs/fake-timers';
export const { withGlobal } = FakeTimers;
/**
* Creates a scoped FakeTimers instance bound to a custom global context.
*
* @param {object} customGlobal - Global object to bind timers to
* @returns {object} Scoped FakeTimers instance with install, createClock, withGlobal
*/
export function bindCustomGlobal(customGlobal) {
return withGlobal(customGlobal);
}
export default {
withGlobal,
bindCustomGlobal,
};
{
"name": "sample-fake-timers-with-global",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-fake-timers-with-global",
"version": "1.0.0",
"dependencies": {
"@sinonjs/fake-timers": "10.3.0"
}
},
"node_modules/@sinonjs/commons": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz",
"integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==",
"license": "BSD-3-Clause",
"dependencies": {
"type-detect": "4.0.8"
}
},
"node_modules/@sinonjs/fake-timers": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz",
"integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==",
"license": "BSD-3-Clause",
"dependencies": {
"@sinonjs/commons": "^3.0.0"
}
},
"node_modules/type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"license": "MIT",
"engines": {
"node": ">=4"
}
}
}
}
{
"name": "sample-fake-timers-with-global",
"version": "1.0.0",
"type": "module",
"private": true,
"dependencies": {
"@sinonjs/fake-timers": "10.3.0"
}
}
{
"schemaVersion": 1,
"goal": "verify withGlobal in pkg:npm/%40sinonjs/fake-timers@10.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40sinonjs/fake-timers@10.3.0"
],
"symbols": [
"withGlobal"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import FakeTimers, { withGlobal, bindCustomGlobal } from '../index.mjs';
function createMockGlobal() {
return {
Date: globalThis.Date,
setTimeout: globalThis.setTimeout,
clearTimeout: globalThis.clearTimeout,
setInterval: globalThis.setInterval,
clearInterval: globalThis.clearInterval,
setImmediate: globalThis.setImmediate,
clearImmediate: globalThis.clearImmediate,
hrtime: globalThis.process.hrtime,
performance: globalThis.performance,
};
}
// Contract 1: withGlobal returns a FakeTimers instance bound to the provided custom global object
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
assert.strictEqual(typeof withGlobal, 'function');
assert.strictEqual(typeof bound, 'object');
assert.strictEqual(typeof bound.install, 'function');
assert.strictEqual(typeof bound.createClock, 'function');
assert.strictEqual(typeof bound.withGlobal, 'function');
assert.strictEqual(typeof bound.timers, 'object');
}
// Contract 2: install on withGlobal context overrides timer functions on custom global without modifying ambient globalThis
{
const mockGlobal = createMockGlobal();
const originalGlobalSetTimeout = globalThis.setTimeout;
const originalMockSetTimeout = mockGlobal.setTimeout;
const bound = bindCustomGlobal(mockGlobal);
const clock = bound.install({ now: 2000 });
assert.notStrictEqual(mockGlobal.setTimeout, originalMockSetTimeout);
assert.strictEqual(globalThis.setTimeout, originalGlobalSetTimeout);
assert.strictEqual(mockGlobal.Date.now(), 2000);
clock.uninstall();
assert.strictEqual(mockGlobal.setTimeout, originalMockSetTimeout);
}
// Contract 3: custom global setTimeout executes callbacks when clock is advanced with tick
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
const clock = bound.install({ now: 1000 });
let called = false;
let receivedArgs = [];
mockGlobal.setTimeout((a, b) => {
called = true;
receivedArgs = [a, b];
}, 300, 'val1', 42);
assert.strictEqual(called, false);
clock.tick(299);
assert.strictEqual(called, false);
assert.strictEqual(mockGlobal.Date.now(), 1299);
clock.tick(1);
assert.strictEqual(called, true);
assert.deepEqual(receivedArgs, ['val1', 42]);
assert.strictEqual(mockGlobal.Date.now(), 1300);
clock.uninstall();
}
// Contract 4: custom global setInterval executes repeatedly at intervals until clearInterval
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
const clock = bound.install({ now: 0 });
let counter = 0;
const intervalId = mockGlobal.setInterval(() => {
counter++;
}, 100);
clock.tick(250);
assert.strictEqual(counter, 2);
mockGlobal.clearInterval(intervalId);
clock.tick(300);
assert.strictEqual(counter, 2);
clock.uninstall();
}
// Contract 5: clock runAll exhausts all pending timers on the bound custom global context
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
const clock = bound.install({ now: 0 });
const executionLog = [];
mockGlobal.setTimeout(() => executionLog.push('second'), 200);
mockGlobal.setTimeout(() => executionLog.push('first'), 50);
mockGlobal.setTimeout(() => executionLog.push('third'), 350);
clock.runAll();
assert.deepEqual(executionLog, ['first', 'second', 'third']);
assert.strictEqual(mockGlobal.Date.now(), 350);
clock.uninstall();
}
// Contract 6: clock setSystemTime adjusts custom global Date now without triggering pending timers
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
const clock = bound.install({ now: 1000 });
let triggered = false;
mockGlobal.setTimeout(() => {
triggered = true;
}, 500);
clock.setSystemTime(5000);
assert.strictEqual(mockGlobal.Date.now(), 5000);
assert.strictEqual(triggered, false);
clock.tick(500);
assert.strictEqual(triggered, true);
clock.uninstall();
}
// Contract 7: clock.uninstall restores original timer functions on the custom global object
{
const mockGlobal = createMockGlobal();
const originalDate = mockGlobal.Date;
const originalSetTimeout = mockGlobal.setTimeout;
const originalClearTimeout = mockGlobal.clearTimeout;
const originalSetInterval = mockGlobal.setInterval;
const originalClearInterval = mockGlobal.clearInterval;
const bound = withGlobal(mockGlobal);
const clock = bound.install();
assert.notStrictEqual(mockGlobal.Date, originalDate);
assert.notStrictEqual(mockGlobal.setTimeout, originalSetTimeout);
clock.uninstall();
assert.strictEqual(mockGlobal.Date, originalDate);
assert.strictEqual(mockGlobal.setTimeout, originalSetTimeout);
assert.strictEqual(mockGlobal.clearTimeout, originalClearTimeout);
assert.strictEqual(mockGlobal.setInterval, originalSetInterval);
assert.strictEqual(mockGlobal.clearInterval, originalClearInterval);
}
// Contract 8: withGlobal createClock creates an independent clock within the custom global context
{
const mockGlobal = createMockGlobal();
const bound = withGlobal(mockGlobal);
const clock = bound.createClock(1500);
assert.strictEqual(clock.now, 1500);
let ran = false;
clock.setTimeout(() => {
ran = true;
}, 100);
clock.tick(100);
assert.strictEqual(ran, true);
assert.strictEqual(clock.now, 1600);
}
// Contract 9: withGlobal allows re-binding to a different target global context
{
const contextA = createMockGlobal();
const contextB = createMockGlobal();
const boundA = withGlobal(contextA);
const boundB = boundA.withGlobal(contextB);
const clockB = boundB.install({ now: 3000 });
assert.strictEqual(contextB.Date.now(), 3000);
assert.strictEqual(contextA.Date, globalThis.Date);
clockB.uninstall();
}
console.log('All contracts passed.');
오리진 시더
익명