-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
watcher.spec.ts
52 lines (46 loc) · 1.54 KB
/
watcher.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'
import { type ViteDevServer, createServer } from '../index'
const stubGetWatchedCode = /getWatched\(\) \{.+?return \{\};.+?\}/s
describe('watcher configuration', () => {
let server: ViteDevServer | undefined
afterEach(async () => {
if (server) {
await server.close()
server = undefined
}
})
it('when watcher is disabled, return noop watcher', async () => {
server = await createServer({
server: {
watch: null,
},
})
expect(server.watcher.getWatched.toString()).toMatch(stubGetWatchedCode)
})
it('when watcher is not disabled, return chokidar watcher', async () => {
server = await createServer({
server: {
watch: {},
},
})
expect(server.watcher.getWatched.toString()).not.toMatch(stubGetWatchedCode)
})
it('should watch the root directory, config file dependencies, dotenv files, and the public directory', async () => {
const root = fileURLToPath(
new URL('./fixtures/watcher/nested-root', import.meta.url),
)
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'),
]),
)
})
})