Skip to content
Source
Sign inSign up
pingdotgg/t3code

test(web): isolate diff worker idle clock #22259

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/22259/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 1 changed file with 6 additions and 1 deletion.

x
0 of 1 viewed, 1 left
6 additions and 1 deletionapps/web/src/components/diffs/StyledDiffCodeView.browser.test.tsxModified
View file
@@ -184,7 +184,6 @@
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
// Pins the pool at two workers whatever machine runs the suite.
Object.defineProperty(navigator, "hardwareConcurrency", { configurable: true, value: 2 });
- vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
const initialize = WorkerPoolManager.prototype.initialize;
vi.spyOn(WorkerPoolManager.prototype, "initialize").mockImplementation(function (
this: WorkerPoolManager,
@@ -197,6 +196,7 @@
});
​
afterEach(async () => {
+ if (!vi.isFakeTimers()) vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
await unmountAll();
await vi.runOnlyPendingTimersAsync();
vi.useRealTimers();
@@ -228,6 +228,9 @@
expect(pool.getFileResultCache(files[1]!)).toBeDefined();
await vi.waitFor(() => expect(codeFile("answer.ts")).toContain("answer"));
​
+ // Worker startup uses real time. Only advance the clock once highlighting
+ // has finished, so idle expiry cannot also expire a worker startup timer.
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
await view.render(renderViews(1));
expect(pool.getStats().totalWorkers).toBe(2);
expect(testState.terminations).toBe(0);
@@ -249,6 +252,7 @@