-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.test.ts
112 lines (101 loc) · 5.84 KB
/
index.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
import { execSync } from 'child_process';
import { existsSync, readFileSync, rmSync } from 'fs';
import { beforeEach, expect, test } from 'vitest';
import { outputFile } from './vite.test-config';
beforeEach(cleanup);
test('writes a report', () => {
expect(existsSync(outputFile)).toBe(false);
try {
execSync('yarn test --config test/vite.test-config.ts', {
stdio: 'inherit',
});
} catch (_) {
// Ignore exit codes
}
expect(existsSync(outputFile)).toBe(true);
const contents = readFileSync(outputFile, 'utf-8');
const stable = removeCwd(removeLineNumbers(removeDurations(contents)));
expect(stable).toMatchInlineSnapshot(`
"<testExecutions version=\\"1\\">
<file path=\\"test/fixtures/animals.test.ts\\">
<testCase name=\\"animals - dogs say woof\\" duration=\\"123\\" />
<testCase name=\\"animals - figure out what rabbits say\\">
<skipped message=\\"figure out what rabbits say\\" />
</testCase>
<testCase name=\\"animals - flying ones - cat can fly\\" duration=\\"123\\">
<failure message=\\"expected false to be true // Object.is equality\\">
<![CDATA[AssertionError: expected false to be true // Object.is equality
at <process-cwd>/test/fixtures/animals.test.ts:15:47
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1938:36
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1826:26
at runTest (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:487:40)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runFiles (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:610:5)
at async startTests (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:617:3)
at async <process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:661:9]]>
</failure>
</testCase>
<testCase name=\\"animals - flying ones - bird can fly\\" duration=\\"123\\" />
</file>
<file path=\\"test/fixtures/math.test.ts\\">
<testCase name=\\"math - sum\\" duration=\\"123\\" />
<testCase name=\\"math - multiply\\" duration=\\"123\\" />
<testCase name=\\"math - slow calculation\\" duration=\\"123\\" />
<testCase name=\\"math - tricky calculation of "16 / 4"\\" duration=\\"123\\">
<failure message=\\"expected 4 to deeply equal 8\\">
<![CDATA[AssertionError: expected 4 to deeply equal 8
at <process-cwd>/test/fixtures/math.test.ts:15:42
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1938:36
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1826:26
at runTest (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:487:40)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runFiles (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:610:5)
at async startTests (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:617:3)
at async <process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:661:9
at async withEnv (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:171:5)]]>
</failure>
</testCase>
<testCase name=\\"math - complex calculation\\" duration=\\"123\\">
<error message=\\"16.divideByTwo is not a function\\">
<![CDATA[TypeError: 16.divideByTwo is not a function
at <process-cwd>/test/fixtures/math.test.ts:18:38
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1938:36
at <process-cwd>/node_modules/vitest/dist/chunk-runtime-chain.eb764dff.mjs:1826:26
at runTest (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:487:40)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runSuite (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:570:13)
at async runFiles (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:610:5)
at async startTests (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:617:3)
at async <process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:661:9
at async withEnv (<process-cwd>/node_modules/vitest/dist/vendor-entry.78de67ab.mjs:171:5)]]>
</error>
</testCase>
<testCase name=\\"math - random numbers are unstable\\">
<skipped message=\\"random numbers are unstable\\" />
</testCase>
<testCase name=\\"math - learn square roots\\">
<skipped message=\\"learn square roots\\" />
</testCase>
<testCase name=\\"math - divide - basic\\" duration=\\"123\\" />
<testCase name=\\"math - divide - by zero\\" duration=\\"123\\" />
</file>
</testExecutions>"
`);
});
function cleanup() {
if (existsSync(outputFile)) {
rmSync(outputFile);
}
}
function removeDurations(report: string) {
return report.replace(/duration="\d*"/g, 'duration="123"');
}
function removeCwd(report: string) {
return report.replace(new RegExp(process.cwd(), 'g'), '<process-cwd>');
}
function removeLineNumbers(report: string) {
return report.replace(/\.js:\d*:\d*/g, '.js');
}