Skip to content

Commit f629b57

Browse files
Enhance test reliability with fake timers in index.test.ts
- Implemented fake timers using vi.useFakeTimers() to control setTimeout behavior during tests. - Restored real timers and cleared pending timers in afterEach to ensure a clean test environment. These changes improve the reliability of tests by preventing unintended delays and ensuring proper timer management.
1 parent 9345894 commit f629b57

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

workers/main/src/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ describe('handleRunError', () => {
66
let processExitSpy: ReturnType<typeof vi.spyOn>;
77

88
beforeEach(() => {
9+
vi.useFakeTimers();
10+
911
// Mock process.exit to prevent actual process termination during tests
1012
processExitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
1113
throw new Error('process.exit called');
@@ -14,6 +16,8 @@ describe('handleRunError', () => {
1416

1517
afterEach(() => {
1618
processExitSpy.mockRestore();
19+
vi.clearAllTimers();
20+
vi.useRealTimers();
1721
});
1822

1923
it('should log the error', () => {

0 commit comments

Comments
 (0)