/
runner.test.ts
88 lines (77 loc) · 2.55 KB
/
runner.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { resolve } from 'pathe'
import fg from 'fast-glob'
import { execa } from 'execa'
import { describe, expect, it } from 'vitest'
describe('stacktraces should respect sourcemaps', async () => {
const root = resolve(__dirname, '../fixtures')
const files = await fg('*.test.*', { cwd: root })
for (const file of files) {
it(file, async () => {
// in Windows child_process is very unstable, we skip testing it
if (process.platform === 'win32' && process.env.CI)
return
const { stderr } = await execa('npx', ['vitest', 'run', file], {
cwd: root,
reject: false,
stdio: 'pipe',
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
})
expect(stderr).toBeTruthy()
const lines = String(stderr).split(/\n/g)
const index = lines.findIndex(val => val.includes(`${file}:`))
const msg = lines.slice(index, index + 8).join('\n')
expect(msg).toMatchSnapshot(file)
}, 30000)
}
})
describe('stacktraces should pick error frame if present', async () => {
const root = resolve(__dirname, '../fixtures')
const files = ['frame.spec.imba']
for (const file of files) {
it(file, async () => {
// in Windows child_process is very unstable, we skip testing it
if (process.platform === 'win32' && process.env.CI)
return
const { stderr } = await execa('npx', ['vitest', 'run', file], {
cwd: root,
reject: false,
stdio: 'pipe',
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
})
expect(stderr).toBeTruthy()
const lines = String(stderr).split(/\n/g)
const index = lines.findIndex(val => val.includes('FAIL'))
const msg = lines.slice(index, index + 8).join('\n')
expect(msg).toMatchSnapshot(file)
}, 30000)
}
})
describe('stacktrace should print error frame source file correctly', async () => {
const root = resolve(__dirname, '../fixtures')
const testFile = resolve(root, './error-in-deps.test.js')
it('error-in-deps', async () => {
// in Windows child_process is very unstable, we skip testing it
if (process.platform === 'win32' && process.env.CI)
return
const { stderr } = await execa('npx', ['vitest', 'run', testFile], {
cwd: root,
reject: false,
stdio: 'pipe',
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
})
// expect to print framestack of foo.js
expect(stderr).toMatchSnapshot('error-in-deps')
}, 30000)
})