/
custom-reporter.spec.ts
80 lines (65 loc) · 3.05 KB
/
custom-reporter.spec.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
import { execa } from 'execa'
import { resolve } from 'pathe'
import { describe, expect, test } from 'vitest'
const customTsReporterPath = resolve(__dirname, '../src/custom-reporter.ts')
const customJSReporterPath = resolve(__dirname, '../src/custom-reporter.js')
async function run(...runOptions: string[]): Promise<string> {
const root = resolve(__dirname, '..')
const { stdout } = await execa('npx', ['vitest', 'run', ...runOptions], {
cwd: root,
env: {
...process.env,
CI: 'true',
NO_COLOR: 'true',
},
windowsHide: false,
})
return stdout
}
async function runWithRetry(...runOptions: string[]) {
const count = 3
for (let i = count; i >= 0; i--) {
try {
return await run(...runOptions)
}
catch (e) {
if (i <= 0)
throw e
}
}
}
describe.concurrent('custom reporters', () => {
// On Windows and macOS child_process is very unstable, we skip testing it as the functionality is tested on Linux
if ((process.platform === 'win32' || process.platform === 'darwin') && process.env.CI)
return test.skip('skip on windows')
const TIMEOUT = 60_000
test('custom reporter instances defined in configuration works', async () => {
const stdout = await runWithRetry('--config', 'custom-reporter.vitest.config.ts')
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
test('load no base on root custom reporter instances defined in configuration works', async () => {
const stdout = await runWithRetry('--config', './reportTest2/custom-reporter-path.vitest.config.ts')
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
test('package.json dependencies reporter instances defined in configuration works', async () => {
const stdout = await runWithRetry('--config', 'deps-reporter.vitest.config.ts')
expect(stdout).includes('hello from package reporter')
}, TIMEOUT)
test('a path to a custom reporter defined in configuration works', async () => {
const stdout = await runWithRetry('--config', 'custom-reporter-path.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
test('custom TS reporters using ESM given as a CLI argument works', async () => {
const stdout = await runWithRetry('--config', 'without-custom-reporter.vitest.config.ts', '--reporter', customTsReporterPath)
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
test('custom JS reporters using CJS given as a CLI argument works', async () => {
const stdout = await runWithRetry('--config', 'without-custom-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
test('overrides reporters by given a CLI argument --reporter works', async () => {
const stdout = await runWithRetry('--config', 'deps-reporter.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).not.includes('hello from package reporter')
expect(stdout).includes('hello from custom reporter')
}, TIMEOUT)
})