/
runner.test.ts
98 lines (86 loc) · 2.78 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
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: {
allowJs: true,
include: ['**/*.test-d.*'],
},
}, [], 'typecheck')
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()
}
})
}, 30_000)
it('typecheks with custom tsconfig', async () => {
const { stderr } = await runVitestCli(
{ cwd: root, env: { ...process.env, CI: 'true' } },
'typecheck',
'--run',
'--dir',
resolve(__dirname, '..', './failing'),
'--config',
resolve(__dirname, './vitest.custom.config.ts'),
)
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')
}, 30_000)
it('typechecks empty "include" but with tests', async () => {
const { stderr } = await runVitestCli(
{
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
},
'typecheck',
'--run',
'--dir',
resolve(__dirname, '..', './failing'),
'--config',
resolve(__dirname, './vitest.empty.config.ts'),
)
expect(stderr.replace(resolve(__dirname, '..'), '<root>')).toMatchSnapshot()
}, 30_000)
})