Skip to content

Commit e2c5df2

Browse files
committed
fix: ensure sequential downloads complete instantly in tests by mocking delay
1 parent cfbd636 commit e2c5df2

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/renderer/pages/backup/__tests__/BackupCreateFlow.spec.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import legacyDownload from "js-file-download";
99

1010
vi.mock("js-file-download");
1111

12+
// Make delay a no-op so sequential downloads complete instantly in tests
13+
vi.mock("shared/tools", async (importOriginal) => ({
14+
...(await importOriginal<typeof import("shared/tools")>()),
15+
delay: () => Promise.resolve(),
16+
}));
17+
1218
// Mock environment
1319
vi.mock("shared/environment", () => ({
1420
default: {
@@ -335,18 +341,15 @@ describe("<BackupCreateFlow /> sequential individual download", () => {
335341
fireEvent.click(screen.getByRole("button", { name: /create backup/i }));
336342

337343
// All 11 files should be downloaded. Chromium blocks simultaneous
338-
// programmatic downloads above ~10; the sequential approach (one every
339-
// 200ms) avoids that entirely. 11 files → ~2200ms total.
340-
await waitFor(
341-
() => {
342-
expect(downloadedFiles).toHaveLength(modelCount);
343-
},
344-
{ timeout: 5000 }
345-
);
344+
// programmatic downloads above ~10; the sequential approach (one per
345+
// 200ms in production, instant in tests) avoids that entirely.
346+
await waitFor(() => {
347+
expect(downloadedFiles).toHaveLength(modelCount);
348+
});
346349

347350
// Verify each model file was included
348351
modelNames.forEach((name) => {
349352
expect(downloadedFiles).toContain(`${name}.yml`);
350353
});
351-
}, 15000); // 11 files × 200ms = ~2200ms, plus test overhead
354+
});
352355
});

0 commit comments

Comments
 (0)