-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
runner.test.ts
126 lines (112 loc) · 3.64 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { resolve } from 'pathe'
import fg from 'fast-glob'
import { describe, expect, it } from 'vitest'
import { runVitest, runVitestCli } from '../../test-utils'
describe('should fail', async () => {
const root = resolve(__dirname, '../failing')
const files = await fg('*.test-d.*', { cwd: root })
it('typecheck files', async () => {
const { stderr } = await runVitest({
root,
dir: './failing',
typecheck: {
enabled: true,
allowJs: true,
include: ['**/*.test-d.*'],
},
}, [])
expect(stderr).toBeTruthy()
const lines = String(stderr).split(/\n/g)
const msg = lines
.filter(i => i.includes('TypeCheckError: '))
.reverse()
.join('\n')
.trim()
.replace(root, '<rootDir>')
expect(stderr).not.toMatch('files found, exiting with code')
expect(msg).toMatchSnapshot()
files.forEach((file) => {
expect(String(stderr)).toMatch(`${file}:`)
})
lines.forEach((line, idx) => {
if (line.includes('TypeCheckError')) {
const msg = lines.slice(idx - 1, idx + 7).join('\n')
expect(msg).toMatchSnapshot()
}
})
})
it('typecheks with custom tsconfig', async () => {
const { stderr } = await runVitestCli(
{ cwd: root, env: { ...process.env, CI: 'true' } },
'--run',
'--dir',
resolve(__dirname, '..', './failing'),
'--config',
resolve(__dirname, './vitest.custom.config.ts'),
'--typecheck.enabled',
)
expect(stderr).toBeTruthy()
const lines = String(stderr).split(/\n/g)
const msg = lines
.filter(i => i.includes('TypeCheckError: '))
.reverse()
.join('\n')
.trim()
.replace(root, '<rootDir>')
expect(stderr).not.toMatch('files found, exiting with code')
// only one test file is failed, because only one is included in tsconfig
// + file with .only modifier
expect(msg).toMatchSnapshot()
expect(stderr).toContain('FAIL fail.test-d.ts') // included in tsconfig
expect(stderr).toContain('FAIL only.test-d.ts') // .only
// not included in tsconfig
expect(stderr).not.toContain('expect-error.test-d.ts')
expect(stderr).not.toContain('js-fail.test-d.js')
expect(stderr).not.toContain('js.test-d.js')
expect(stderr).not.toContain('test.test-d.ts')
})
it('typechecks empty "include" but with tests', async () => {
const { stderr } = await runVitestCli(
{
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
},
'--run',
'--dir',
resolve(__dirname, '..', './failing'),
'--config',
resolve(__dirname, './vitest.empty.config.ts'),
'--typecheck.enabled',
)
expect(stderr.replace(resolve(__dirname, '..'), '<root>')).toMatchSnapshot()
})
})
describe('ignoreSourceErrors', () => {
it('disabled', async () => {
const vitest = await runVitestCli(
{
cwd: resolve(__dirname, '../fixtures/source-error'),
},
'--run',
)
expect(vitest.stdout).toContain('Unhandled Errors')
expect(vitest.stderr).toContain('Unhandled Source Error')
expect(vitest.stderr).toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
})
it('enabled', async () => {
const vitest = await runVitestCli(
{
cwd: resolve(__dirname, '../fixtures/source-error'),
},
'--run',
'--typecheck.ignoreSourceErrors',
)
expect(vitest.stdout).not.toContain('Unhandled Errors')
expect(vitest.stderr).not.toContain('Unhandled Source Error')
expect(vitest.stderr).not.toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
})
})