-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
file-watching.test.ts
65 lines (47 loc) · 1.97 KB
/
file-watching.test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
import { readFileSync, writeFileSync } from 'fs'
import { afterEach, expect, test } from 'vitest'
import { startWatchMode, waitFor } from './utils'
const EDIT_COMMENT = '// Modified by file-watching.test.ts\n\n'
const sourceFile = 'fixtures/math.ts'
const sourceFileContent = readFileSync(sourceFile, 'utf-8')
const testFile = 'fixtures/math.test.ts'
const testFileContent = readFileSync(testFile, 'utf-8')
const configFile = 'fixtures/vitest.config.ts'
const configFileContent = readFileSync(configFile, 'utf-8')
afterEach(() => {
writeFileSync(sourceFile, sourceFileContent, 'utf8')
writeFileSync(testFile, testFileContent, 'utf8')
writeFileSync(configFile, configFileContent, 'utf8')
})
test('editing source file triggers re-run', async () => {
const vitest = await startWatchMode()
writeFileSync(sourceFile, `${EDIT_COMMENT}${sourceFileContent}`, 'utf8')
await waitFor(() => {
expect(vitest.getOutput()).toContain('RERUN math.ts')
expect(vitest.getOutput()).toContain('1 passed')
})
})
test('editing test file triggers re-run', async () => {
const vitest = await startWatchMode()
writeFileSync(testFile, `${EDIT_COMMENT}${testFileContent}`, 'utf8')
await waitFor(() => {
expect(vitest.getOutput()).toMatch('RERUN math.test.ts')
expect(vitest.getOutput()).toMatch('1 passed')
})
})
test('editing config file triggers re-run', async () => {
const vitest = await startWatchMode()
writeFileSync(configFile, `${EDIT_COMMENT}${configFileContent}`, 'utf8')
await waitFor(() => {
expect(vitest.getOutput()).toMatch('Restarting due to config changes')
expect(vitest.getOutput()).toMatch('2 passed')
})
})
test('editing config file reloads new changes', async () => {
const vitest = await startWatchMode()
writeFileSync(configFile, configFileContent.replace('reporters: \'verbose\'', 'reporters: \'tap\''), 'utf8')
await waitFor(() => {
expect(vitest.getOutput()).toMatch('TAP version')
expect(vitest.getOutput()).toMatch('ok 2')
})
})