Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/mock/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export class FakeTimers {

if (!this._fakingTime) {
const toFake = Object.keys(this._fakeTimers.timers)
// Do not mock nextTick by default. It can still be mocked through userConfig.
// Do not mock timers internally used by node by default. It can still be mocked through userConfig.
.filter(
timer => timer !== 'nextTick',
timer => timer !== 'nextTick' && timer !== 'queueMicrotask',
) as (keyof FakeTimerWithContext['timers'])[]

if (this._userConfig?.toFake?.includes('nextTick') && isChildProcess()) {
Expand Down
27 changes: 27 additions & 0 deletions test/core/test/timers-queueMicrotask.test.ts
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')
})