-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exclude
queueMicrotask
from default fake timers to not break n…
…ode fetch (#7505)
- Loading branch information
Showing
4 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, onTestFinished, test, vi } from 'vitest' | ||
|
||
test(`node fetch works without fake timers`, async () => { | ||
expect(await Response.json('ok').json()).toBe('ok') | ||
}) | ||
|
||
test(`node fetch works with fake timers`, async () => { | ||
vi.useFakeTimers() | ||
onTestFinished(() => { | ||
vi.useRealTimers() | ||
}) | ||
expect(await Response.json('ok').json()).toBe('ok') | ||
}) | ||
|
||
// skipped since this might cause a weird OOM on CI | ||
test.skip(`node fetch timeouts with fake queueMicrotask`, async () => { | ||
vi.useFakeTimers({ toFake: ['queueMicrotask'] }) | ||
onTestFinished(() => { | ||
vi.useRealTimers() | ||
}) | ||
expect( | ||
await Promise.race([ | ||
new Promise(r => setTimeout(() => r('timeout'), 200)), | ||
Response.json('ok').json(), | ||
]), | ||
).toBe('timeout') | ||
}) |