vitest plugin: a mod's Date.now() windows cannot be tested portably, only $.clock.now() follows mock.clock
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 43/100
- Type d'issue
- Fonctionnalité
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- javascript, typescript
- Domaine
- developer-experience, testing-qa
Piste de recherche
Start with the README’s guidance for mock.clock, $.clock.now(), and portable tests; the issue does not name repository files to change. Reproduce the reported behavior with the minimal example under both Vitest and claude plugin test, then review the three proposed options and their portability tradeoffs. Done when the issue’s preferred behavior is decided and the relevant documentation or behavior is covered by tests on both runners.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Problem
A mod that reads the wall clock with Date.now() cannot be tested for time windows (toast every 15 s, retry after 30 s) in a test that runs under both the vitest plugin and claude plugin test. mock.clock(on, { now }) and clock.advance(ms) move only the kit's clock ($.clock); the mod's Date.now() stays the real wall clock under both runners, and a portable test (portable: "error", only claude-code/testing) has no other way to move it: vi.setSystemTime is not available there.
So tests that step past such a window are blocked in the migration to one test set (#41). The legacy kit allowed vi.setSystemTime; the migrated plugin keeps those tests on the legacy kit meanwhile. No workaround was added (no vitest-only layer for them, no source change to the mod).
Found while migrating dprint in kwitsch/claude-plugins-development (#41, draft PR kwitsch/claude-plugins-development#193). 7 of its 28 notice tests step the wall clock (vi.setSystemTime(T0 + 16_000) etc.); the other 21 (41 test cases) are migrated and pass under both runners.
Versions
@kwitsch/vitest-plugin-claude-code-mod0.18.0- Claude Code 2.1.336 (
claude plugin test) - vitest 5.1.2, Node 26.14.0, Linux (WSL2)
Minimal reproduction
package.json: { "name": "repro-date", "version": "0.0.1", "type": "module" }; plugin/hooks/hooks.json: { "modules": ["./register.js"] }; plugin/.claude-plugin/plugin.json: name repro-date; the mod src/register.js is copied to plugin/hooks/register.js:
export const register = (on) => {
on("session.start", async ($, e, next) => {
await $.ui.toast(String(Date.now()));
return next(e);
});
};
vitest.config.ts: plugins: [claudeCodeMod({ mod: "./src/register.js", portable: "error" })].
claude-tests/date.test.ts:
import { expect, mock, test } from "claude-code/testing";
const START = { source: "startup", cwd: "/proj", surface: "terminal", isInteractive: true };
const T0 = Date.UTC(2026, 10, 5, 12);
test("Date.now() in the mod follows mock.clock", async ($, on) => {
const toasts: unknown[] = [];
const clock = mock.clock(on, { now: T0 });
on("ui.toast", (_$, e) => (toasts.push(Number(e.text)), { value: undefined }));
on("session.start", async () => ({ cwd: "/proj" }));
await $.session.start(START);
await clock.advance(16_000);
await $.session.start(START);
expect(toasts).toEqual([T0, T0 + 16_000]);
});
vitest (vitest run):
AssertionError: expected [ 1796331072139, 1796331072141 ] to deeply equal [ 1793880000000, 1793880016000 ]
claude plugin test (copy of plugin/ with the test in test/):
(fail) Date.now() in the mod follows mock.clock [32.28ms]
Expected: [1793880000000, 1793880016000]
Received: [1796331072600, 1796331072603]
Both runners behave the same: this is a missing function, not a divergence.
What works
Replacing Date.now() with await $.clock.now() in the same mod passes under both runners (vitest: 1 passed; claude plugin test: (pass) Date.now() in the mod follows mock.clock). So a mod can be tested portably if it reads the time through $.clock.now(). That is a change of the shipped mod (an extra engine call per read, in dprint's case on the Bash hook path, where the mod today makes no engine call after a successful probe), so it was not done in the migration PR without a decision.
Expected / options
One of:
- Document in the README that a mod's
Date.now()is the real clock and that$.clock.now()is the way to make time testable (and is covered bymock.clock), so migrating plugins know to change the mod. - Let the vitest plugin move
Date.now()inside the mod sandbox together withmock.clock(not possible underclaude plugin test, so tests relying on it would not be portable;portable: "error"would have to reject them). - A conformance test that pins the
$.clock.now()behaviour on both runners.
Preferred decision to make in this issue: whether plugins should move from Date.now() to $.clock.now() (then dprint does so in its own change and the 7 tests migrate) or whether the kit provides something else.
Relations
- Part of #41; blocks the last 7 tests of kwitsch/claude-plugins-development#193 (dprint).
- Tests:
dprint/tests/notice.test.ts(the tests withvi.setSystemTime: "a config in an ancestor below the git root counts...", "one toast per 15 s across hooks and dirs...", "worktree tools check the dir their result names...", "a failed probe is cached for 30 s...", "a rejecting env.get is cached as a failed probe for 30 s...", "same dir after the toast window is not re-checked...", "worktree tool output in the engine's { result } shape...").
- Langage dominant
- TypeScript
- Étoiles
- 0
- Forks
- 0
- Merge moyen
- 29 min
- PR mergées (30 j)
- 138
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de kwitsch/claude-code-plugin-tooling
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
kwitsch/claude-code-plugin-tooling#219 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 69/100
kwitsch/claude-code-plugin-tooling#210 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 54/100
kwitsch/claude-code-plugin-tooling#212 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
kwitsch/claude-code-plugin-tooling#209 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
kwitsch/claude-code-plugin-tooling#208 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de kwitsch/claude-code-plugin-tooling
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
makecindy/cindy#15342 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Les mainteneurs répondent en général sous 1 jour
-
no-repo-link tool-submission
Difficulté 1/5 Moins d'une heure Accessibilité débutants 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
-
bug needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Priyanshu-byte-coder/devtrack#4067 ·
Les mainteneurs répondent en général sous 1 jour