Sample
@jest/fake-timers 30.4.1: LegacyFakeTimers
Verified sample for npm @jest/fake-timers 30.4.1: LegacyFakeTimers. The contract ran on node 22 · linux debian/x64 · docker and passed.
sha256:b288c253f03432c4c01efa407afd14b9072ca648f6172f46d2eb87a0ba884b5e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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-05 |
Case
HOW- Goal
- verify @jest/fake-timers.LegacyFakeTimers in pkg:npm/%40jest/fake-timers@30.4.1
- Packages
- Symbols
-
- @jest/fake-timers.LegacyFakeTimers
- Environment
- node 22.23.2
- Created
- 2026-09-05T23:53:57Z
Contract
- LegacyFakeTimers instantiates with mock and timer configuration, intercepts timer globals via useFakeTimers, and restores original implementations via useRealTimers
- advanceTimersByTime advances virtual clock by milliseconds and executes scheduled timers in chronological order
- advanceTimersToNextTimer progresses virtual time directly to the next scheduled timer expiration
- runAllTimers exhaustively executes all queued timers, ticks, immediates, and recursively scheduled timers
- runOnlyPendingTimers executes currently queued timers without running newly scheduled nested timers
- runAllTicks flushes queued microtasks scheduled via process.nextTick
- runAllImmediates flushes queued tasks scheduled via setImmediate
- clearAllTimers and getTimerCount track and cancel active scheduled timers and immediates
- reset and now manage virtual clock time and clear active timers
- runWithRealTimers temporarily restores native timer functions during callback execution
- dispose clears all timers and marks the fake timer instance as disposed
- runWithFakeTimers helper safely executes a scoped callback and restores native timers
Files
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Source
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/fake-timers.LegacyFakeTimers in pkg:npm/%40jest/fake-timers@30.4.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40jest/fake-timers@30.4.1
Demonstrate these symbols/APIs:
- @jest/fake-timers.LegacyFakeTimers
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:2d573f6e478fa619ba3464a9916936923c2b73204d02fd2f02c072684d65dec2","contract":["LegacyFakeTimers instantiates with mock and timer configuration, intercepts timer globals via useFakeTimers, and restores original implementations via useRealTimers","advanceTimersByTime advances virtual clock by milliseconds and executes scheduled timers in chronological order","advanceTimersToNextTimer progresses virtual time directly to the next scheduled timer expiration","runAllTimers exhaustively executes all queued timers, ticks, immediates, and recursively scheduled timers","runOnlyPendingTimers executes currently queued timers without running newly scheduled nested timers","runAllTicks flushes queued microtasks scheduled via process.nextTick","runAllImmediates flushes queued tasks scheduled via setImmediate","clearAllTimers and getTimerCount track and cancel active scheduled timers and immediates","reset and now manage virtual clock time and clear active timers","runWithRealTimers temporarily restores native timer functions during callback execution","dispose clears all timers and marks the fake timer instance as disposed","runWithFakeTimers helper safely executes a scoped callback and restores native timers"],"goal":"verify @jest/fake-timers.LegacyFakeTimers in pkg:npm/%40jest/fake-timers@30.4.1","kind":"HOW","packages":["pkg:npm/%40jest/fake-timers@30.4.1"],"schemaVersion":1,"symbols":["@jest/fake-timers.LegacyFakeTimers"]},"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/%40jest/fake-timers@30.4.1"],"schemaVersion":1,"subject":"pkg:npm/%40jest/fake-timers@30.4.1","symbols":["@jest/fake-timers.LegacyFakeTimers"],"verifierAdapter":"node-typescript@1"}
import { LegacyFakeTimers } from '@jest/fake-timers';
export { LegacyFakeTimers };
export function createLegacyFakeTimers(options = {}) {
const {
global = globalThis,
moduleMocker = {
fn: (impl) => {
const fn = (...args) => impl(...args);
return fn;
}
},
timerConfig = {
idToRef: (id) => id,
refToId: (ref) => ref
},
config = { rootDir: process.cwd() },
maxLoops
} = options;
return new LegacyFakeTimers({
global,
moduleMocker,
timerConfig,
config,
maxLoops
});
}
export function runWithFakeTimers(fn, options = {}) {
const fakeTimers = createLegacyFakeTimers(options);
fakeTimers.useFakeTimers();
try {
return fn(fakeTimers);
} finally {
fakeTimers.useRealTimers();
}
}
{
"name": "sample-jest-legacy-fake-timers",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-jest-legacy-fake-timers",
"version": "1.0.0",
"dependencies": {
"@jest/fake-timers": "30.4.1"
}
},
"node_modules/@babel/code-frame": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz",
"integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==",
"license": "MIT",
"dependencies": {
"@babel/helper-validator-identifier": "^7.29.7",
"js-tokens": "^4.0.0",
"picocolors": "^1.1.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
"integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@jest/fake-timers": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-30.4.1.tgz",
"integrity": "sha512-iW5umdmfPeWzehrVhugFQZqCchSCud5S1l2YT0O9ZhjRR0ExclANDZkiSBwzqtnlOn0J1JXvO+HZ6rkuyOVOgQ==",
"license": "MIT",
"dependencies": {
"@jest/types": "30.4.1",
"@sinonjs/fake-timers": "^15.4.0",
"@types/node": "*",
"jest-message-util": "30.4.1",
"jest-mock": "30.4.1",
"jest-util": "30.4.1"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.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/@jest/schemas": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-30.4.1.tgz",
"integrity": "sha512-i6b4qw5qnP8c5FEeBJg/uZQ4ddrkN6Ca8qISJh0pr7a5hfn3h3v5x60BEbOC7OYAGZNMs1LfFLwnW2CuK8F57Q==",
"license": "MIT",
"dependencies": {
"@sinclair/typebox": "^0.34.0"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
}
},
"node_modules/@jest/types": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-30.4.1.tgz",
"integrity": "sha512-f1x/vJXIfjOlEmejYpbkbgw1gOqpPECwMvMEtBqe47j7H2Hg8h8w3o3ikhSXq3MI15kg+oQ0exWO0uCtTNJLoQ==",
"license": "MIT",
"dependencies": {
"@jest/pattern": "30.4.0",
"@jest/schemas": "30.4.1",
"@types/istanbul-lib-coverage": "^2.0.6",
"@types/istanbul-reports": "^3.0.4",
"@types/node": "*",
"@types/yargs": "^17.0.33",
"chalk": "^4.1.2"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.34.52",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.52.tgz",
"integrity": "sha512-XiMQh7qqVlxZzcVD+kkGMNGMzcTrDMLWI7S4x7z1MkCkbDPrekpZXEUK0eZqZFMuHQg2a2DZOcDIh9o5v3Gonw==",
"license": "MIT"
},
"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": "15.4.0",
"resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-15.4.0.tgz",
"integrity": "sha512-DsG+8/LscQIQg68J6Ef3dv10u6nVyetYn923s3/sus5eaGfTo1of5WMZSLf0UJc9KDuKPilPH0UDJCjvNbDNCA==",
"license": "BSD-3-Clause",
"dependencies": {
"@sinonjs/commons": "^3.0.1"
}
},
"node_modules/@types/istanbul-lib-coverage": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
"integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==",
"license": "MIT"
},
"node_modules/@types/istanbul-lib-report": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz",
"integrity": "sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==",
"license": "MIT",
"dependencies": {
"@types/istanbul-lib-coverage": "*"
}
},
"node_modules/@types/istanbul-reports": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz",
"integrity": "sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==",
"license": "MIT",
"dependencies": {
"@types/istanbul-lib-report": "*"
}
},
"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/@types/stack-utils": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz",
"integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==",
"license": "MIT"
},
"node_modules/@types/yargs": {
"version": "17.0.35",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.35.tgz",
"integrity": "sha512-qUHkeCyQFxMXg79wQfTtfndEC+N9ZZg76HJftDJp+qH2tV7Gj4OJi7l+PiWwJ+pWtW8GwSmqsDj/oymhrTWXjg==",
"license": "MIT",
"dependencies": {
"@types/yargs-parser": "*"
}
},
"node_modules/@types/yargs-parser": {
"version": "21.0.3",
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz",
"integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==",
"license": "MIT"
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/ci-info": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.4.0.tgz",
"integrity": "sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/sibiraj-s"
}
],
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
"node_modules/escape-string-regexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
"integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"license": "ISC"
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/jest-message-util": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-30.4.1.tgz",
"integrity": "sha512-kwCKIvq0MCW1HzLoGola9Te6JUdzgV0loyKJ3Qghrkz9i5/RRIHsL95BMQc2HBBhlBKC4j22K9p11TGHH8RBpQ==",
"license": "MIT",
"dependencies": {
"@babel/code-frame": "^7.27.1",
"@jest/types": "30.4.1",
"@types/stack-utils": "^2.0.3",
"chalk": "^4.1.2",
"graceful-fs": "^4.2.11",
"jest-util": "30.4.1",
"picomatch": "^4.0.3",
"pretty-format": "30.4.1",
"slash": "^3.0.0",
"stack-utils": "^2.0.6"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
}
},
"node_modules/jest-mock": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-30.4.1.tgz",
"integrity": "sha512-/i8SVb8/NSB7RfNi8gfqu8gxLV23KaL5EpAttyb9iz8qWRIqXRLflycz/32wXsYkOnaUlx8NAKnJYtpsmXUmfw==",
"license": "MIT",
"dependencies": {
"@jest/types": "30.4.1",
"@types/node": "*",
"jest-util": "30.4.1"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.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/jest-util": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-30.4.1.tgz",
"integrity": "sha512-vjQb1sACEiv13DKJMDToJpzVW0joCsIQrmbg0fi7CyOOt+g9jTuQl2A216pWRBYhOVt53XbL/2LbMKg1BECWOw==",
"license": "MIT",
"dependencies": {
"@jest/types": "30.4.1",
"@types/node": "*",
"chalk": "^4.1.2",
"ci-info": "^4.2.0",
"graceful-fs": "^4.2.11",
"picomatch": "^4.0.3"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
}
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"license": "MIT"
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
"license": "ISC"
},
"node_modules/picomatch": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/pretty-format": {
"version": "30.4.1",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-30.4.1.tgz",
"integrity": "sha512-K6KiKMHTL4jjX4u3Kir2EW07nRfcqVTXIImx50wbjHQTcZPgg+gjVeNTIT3l3L1Rd4UefxfogquC9J37SoFyyw==",
"license": "MIT",
"dependencies": {
"@jest/schemas": "30.4.1",
"ansi-styles": "^5.2.0",
"react-is-18": "npm:react-is@^18.3.1",
"react-is-19": "npm:react-is@^19.2.5"
},
"engines": {
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
}
},
"node_modules/pretty-format/node_modules/ansi-styles": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/react-is-18": {
"name": "react-is",
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
"integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
"license": "MIT"
},
"node_modules/react-is-19": {
"name": "react-is",
"version": "19.2.8",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.8.tgz",
"integrity": "sha512-s5un28nYxKJw5gvUHyW5PCC28CvBqLu9r3cWgzHT4Vo/5fqqkFcdRYsGcKf50WMPpjjFZS5d76fn3YCo2njKwQ==",
"license": "MIT"
},
"node_modules/slash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
"integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/stack-utils": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz",
"integrity": "sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==",
"license": "MIT",
"dependencies": {
"escape-string-regexp": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"license": "MIT",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"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"
}
},
"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"
}
}
}
{
"name": "sample-jest-legacy-fake-timers",
"version": "1.0.0",
"description": "Clean-room verification sample for @jest/fake-timers LegacyFakeTimers",
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@jest/fake-timers": "30.4.1"
}
}
{
"schemaVersion": 1,
"goal": "verify @jest/fake-timers.LegacyFakeTimers in pkg:npm/%40jest/fake-timers@30.4.1",
"kind": "HOW",
"packages": [
"pkg:npm/%40jest/fake-timers@30.4.1"
],
"symbols": [
"@jest/fake-timers.LegacyFakeTimers"
]
}
import assert from 'node:assert/strict';
import { LegacyFakeTimers } from '@jest/fake-timers';
import { createLegacyFakeTimers, runWithFakeTimers } from '../index.mjs';
// 1. LegacyFakeTimers instantiates with mock and timer configuration, intercepts timer globals via useFakeTimers, and restores original implementations via useRealTimers
{
const originalSetTimeout = globalThis.setTimeout;
const originalClearTimeout = globalThis.clearTimeout;
const originalSetInterval = globalThis.setInterval;
const originalClearInterval = globalThis.clearInterval;
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
assert.notEqual(globalThis.setTimeout, originalSetTimeout);
assert.notEqual(globalThis.clearTimeout, originalClearTimeout);
assert.notEqual(globalThis.setInterval, originalSetInterval);
assert.notEqual(globalThis.clearInterval, originalClearInterval);
timers.useRealTimers();
assert.equal(globalThis.setTimeout, originalSetTimeout);
assert.equal(globalThis.clearTimeout, originalClearTimeout);
assert.equal(globalThis.setInterval, originalSetInterval);
assert.equal(globalThis.clearInterval, originalClearInterval);
}
// 2. advanceTimersByTime advances virtual clock by milliseconds and executes scheduled timers in chronological order
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const executionOrder = [];
setTimeout(() => { executionOrder.push('first'); }, 100);
setTimeout(() => { executionOrder.push('second'); }, 200);
timers.advanceTimersByTime(50);
assert.deepEqual(executionOrder, []);
assert.equal(timers.now(), 50);
timers.advanceTimersByTime(50);
assert.deepEqual(executionOrder, ['first']);
assert.equal(timers.now(), 100);
timers.advanceTimersByTime(100);
assert.deepEqual(executionOrder, ['first', 'second']);
assert.equal(timers.now(), 200);
timers.useRealTimers();
}
// 3. advanceTimersToNextTimer progresses virtual time directly to the next scheduled timer expiration
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const results = [];
setTimeout(() => { results.push(1); }, 150);
setTimeout(() => { results.push(2); }, 300);
timers.advanceTimersToNextTimer();
assert.deepEqual(results, [1]);
assert.equal(timers.now(), 150);
timers.advanceTimersToNextTimer();
assert.deepEqual(results, [1, 2]);
assert.equal(timers.now(), 300);
timers.useRealTimers();
}
// 4. runAllTimers exhaustively executes all queued timers, ticks, immediates, and recursively scheduled timers
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const sequence = [];
setTimeout(() => {
sequence.push('root');
setTimeout(() => {
sequence.push('nested');
}, 50);
}, 100);
timers.runAllTimers();
assert.deepEqual(sequence, ['root', 'nested']);
assert.equal(timers.getTimerCount(), 0);
timers.useRealTimers();
}
// 5. runOnlyPendingTimers executes currently queued timers without running newly scheduled nested timers
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const items = [];
setTimeout(() => {
items.push('initial');
setTimeout(() => {
items.push('child');
}, 50);
}, 100);
timers.runOnlyPendingTimers();
assert.deepEqual(items, ['initial']);
assert.equal(timers.getTimerCount(), 1);
timers.clearAllTimers();
assert.equal(timers.getTimerCount(), 0);
timers.useRealTimers();
}
// 6. runAllTicks flushes queued microtasks scheduled via process.nextTick
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const ticks = [];
process.nextTick(() => { ticks.push('t1'); });
process.nextTick(() => { ticks.push('t2'); });
timers.runAllTicks();
assert.deepEqual(ticks, ['t1', 't2']);
timers.useRealTimers();
}
// 7. runAllImmediates flushes queued tasks scheduled via setImmediate
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const immediates = [];
setImmediate(() => { immediates.push('imm1'); });
setImmediate(() => { immediates.push('imm2'); });
timers.runAllImmediates();
assert.deepEqual(immediates, ['imm1', 'imm2']);
timers.useRealTimers();
}
// 8. clearAllTimers and getTimerCount track and cancel active scheduled timers and immediates
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const timer1 = setTimeout(() => {}, 100);
const timer2 = setInterval(() => {}, 200);
setImmediate(() => {});
assert.equal(timers.getTimerCount(), 3);
clearTimeout(timer1);
assert.equal(timers.getTimerCount(), 2);
timers.clearAllTimers();
assert.equal(timers.getTimerCount(), 0);
timers.useRealTimers();
}
// 9. reset and now manage virtual clock time and clear active timers
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
setTimeout(() => {}, 500);
timers.advanceTimersByTime(500);
assert.equal(timers.now(), 500);
timers.reset();
assert.equal(timers.now(), 0);
assert.equal(timers.getTimerCount(), 0);
timers.useRealTimers();
}
// 10. runWithRealTimers temporarily restores native timer functions during callback execution
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
const fakeSetTimeout = globalThis.setTimeout;
let executed = false;
timers.runWithRealTimers(() => {
assert.notEqual(globalThis.setTimeout, fakeSetTimeout);
executed = true;
});
assert.equal(executed, true);
assert.equal(globalThis.setTimeout, fakeSetTimeout);
timers.useRealTimers();
}
// 11. dispose clears all timers and marks the fake timer instance as disposed
{
const timers = createLegacyFakeTimers();
timers.useFakeTimers();
setTimeout(() => {}, 100);
assert.equal(timers.getTimerCount(), 1);
timers.dispose();
assert.equal(timers.getTimerCount(), 0);
timers.useRealTimers();
}
// 12. runWithFakeTimers helper safely executes a scoped callback and restores native timers
{
const originalSetTimeout = globalThis.setTimeout;
let callbackRan = false;
runWithFakeTimers(fakeTimers => {
assert.notEqual(globalThis.setTimeout, originalSetTimeout);
setTimeout(() => { callbackRan = true; }, 100);
fakeTimers.runAllTimers();
assert.equal(callbackRan, true);
});
assert.equal(globalThis.setTimeout, originalSetTimeout);
}
console.log('All @jest/fake-timers.LegacyFakeTimers contract assertions passed.');
Origin Seeder
anonymous