/
runner.test.ts
49 lines (41 loc) · 1.38 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
import { resolve } from 'pathe'
import fg from 'fast-glob'
import { expect, it } from 'vitest'
import { runVitest } from '../../test-utils'
const root = resolve(__dirname, '../fixtures')
const files = await fg('**/*.test.ts', { cwd: root, dot: true })
it.each(files)('should fail %s', async (file) => {
const { stderr } = await runVitest({ root }, [file])
expect(stderr).toBeTruthy()
const msg = String(stderr)
.split(/\n/g)
.reverse()
.filter(i => i.includes('Error: ') && !i.includes('Command failed') && !i.includes('stackStr') && !i.includes('at runTest'))
.map(i => i.trim().replace(root, '<rootDir>'),
).join('\n')
expect(msg).toMatchSnapshot(file)
}, 30_000)
it('should report coverage when "coverag.reportOnFailure: true" and tests fail', async () => {
const { stdout } = await runVitest({
root,
coverage: {
enabled: true,
provider: 'istanbul',
reportOnFailure: true,
reporter: ['text'],
},
}, [files[0]])
expect(stdout).toMatch('Coverage report from istanbul')
})
it('should not report coverage when "coverag.reportOnFailure: false" and tests fail', async () => {
const { stdout } = await runVitest({
root,
coverage: {
enabled: true,
provider: 'istanbul',
reportOnFailure: false,
reporter: ['text'],
},
}, [files[0]])
expect(stdout).not.toMatch('Coverage report from istanbul')
})