-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.spec.ts
75 lines (71 loc) · 2.37 KB
/
index.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
import { exec } from 'child_process';
describe('vitest-fail-on-console', () => {
const errorThrownMessage = () =>
`vitest-fail-on-console > Expected test not to call`;
const runFixture = async (fixtureName): Promise<{ stderr: string }> => {
const fixtureDirectory = `./tests/fixtures/${fixtureName}/`;
const testFilePath = `${fixtureDirectory}/index.spec.ts`;
const configFilePath = `${fixtureDirectory}/vitest.config.ts`;
const cmd = `./node_modules/.bin/vitest related ${testFilePath} -c ${configFilePath} --run`;
return new Promise((resolve) => {
exec(cmd, (error, stdout, stderr) => {
resolve({ stderr });
});
});
};
it.each([
['throw error', 'console.error() is called', {}, 'error', true],
[
'not throw error',
'console.error() is called',
{ shouldFailOnError: false },
'error-disabled',
false,
],
[
'not throw error',
'console.error() is called',
{ shouldFailOnError: true, skipTest: '/pattern/' },
'error-skip-test',
false,
],
[
'throw error',
'console.assert() is called with a failing assertion ',
{ shouldFailOnAssert: true },
'assert-failure',
true,
],
[
'not throw error',
'console.assert() is called with a passing assertion',
{ shouldFailOnAssert: true },
'assert-success',
false,
],
[
'throw error',
'console.error() is called in setTimeout()',
{ afterEachDelay: 100 },
'after-each-delay-failure',
true,
],
[
'not throw error',
'console.error() is called in setTimeout()',
{},
'after-each-delay-success',
false,
],
])(
'should %s when %s with options %s',
async (msgA, msgB, options, fixture, isErrorThrown) => {
const { stderr } = await runFixture(fixture);
expect(stderr).toEqual(
isErrorThrown
? expect.stringContaining(errorThrownMessage())
: expect.not.stringContaining(errorThrownMessage())
);
}
);
});