Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: disable isolate for unit test #17448

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
chore: simplify code
  • Loading branch information
bluwy committed Jun 13, 2024
commit d9edc0c92ab59833d4113be975e3dbb176f28ac8
20 changes: 4 additions & 16 deletions packages/vite/src/node/server/__tests__/watcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { type ViteDevServer, createServer } from '../index'

const stubGetWatchedCode = /getWatched\(\) \{.+?return \{\};.+?\}/s
Expand Down Expand Up @@ -39,9 +39,9 @@ describe('watcher configuration', () => {
)
server = await createServer({ root })
await new Promise((resolve) => server!.watcher.once('ready', resolve))
// At this point, there's still a chance that chokidar has not watch all the necessary directories yet
// so we have to retry here for a bit
await withRetry(() => {
// Perform retries here as chokidar may still not be completely watching all directories
// after the `ready` event
await vi.waitFor(() => {
const watchedDirs = Object.keys(server!.watcher.getWatched())
expect(watchedDirs).toEqual(
expect.arrayContaining([
Expand All @@ -54,15 +54,3 @@ describe('watcher configuration', () => {
})
})
})

async function withRetry(func: () => Promise<void> | void): Promise<void> {
const maxTries = process.env.CI ? 3 : 1
for (let tries = 0; tries < maxTries; tries++) {
try {
await func()
return
} catch {}
await new Promise((r) => setTimeout(r, 50))
}
await func()
}