-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
json.test.ts
51 lines (42 loc) · 1.45 KB
/
json.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
import { resolve } from 'pathe'
import { execa } from 'execa'
import { describe, expect, it } from 'vitest'
describe('json reporter', async () => {
const root = resolve(__dirname, '../fixtures')
const skip = (process.platform === 'win32' || process.platform === 'darwin') && process.env.CI
it.skipIf(skip)('generates correct report', async () => {
const { stdout } = await execa('npx', ['vitest', 'run', 'json-fail', '--reporter=json'], {
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
stdio: 'pipe',
}).catch(e => e)
const data = JSON.parse(stdout)
expect(data.testResults).toHaveLength(1)
expect(data.testResults[0].assertionResults).toHaveLength(1)
const result = data.testResults[0].assertionResults[0]
delete result.duration
expect(result).toMatchSnapshot()
}, 40000)
it.skipIf(skip).each([
['passed', 'all-passing-or-skipped'],
['skipped', 'all-skipped'],
['failed', 'some-failing'],
])('resolves to "%s" status for test file "%s"', async (expected, file) => {
const { stdout } = await execa('npx', ['vitest', 'run', file, '--reporter=json'], {
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
stdio: 'pipe',
}).catch(e => e)
const data = JSON.parse(stdout)
expect(data.testResults).toHaveLength(1)
expect(data.testResults[0].status).toBe(expected)
}, 40000)
})