Skip to content

Commit

Permalink
chore: add retry
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jun 12, 2024
1 parent 4f17ceb commit 62bdf6f
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions packages/vite/src/node/server/__tests__/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,30 @@ describe('watcher configuration', () => {
)
server = await createServer({ root })
await new Promise((resolve) => server!.watcher.once('ready', resolve))
const watchedDirs = Object.keys(server.watcher.getWatched())
expect(watchedDirs).toEqual(
expect.arrayContaining([
root,
resolve(root, '../config-deps'),
resolve(root, '../custom-env'),
resolve(root, '../custom-public'),
]),
)
// 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(() => {
const watchedDirs = Object.keys(server!.watcher.getWatched())
expect(watchedDirs).toEqual(
expect.arrayContaining([
root,
resolve(root, '../config-deps'),
resolve(root, '../custom-env'),
resolve(root, '../custom-public'),
]),
)
})
})
})

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()
}

0 comments on commit 62bdf6f

Please sign in to comment.