forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-runner-coverage-default-exclusion.mjs
More file actions
116 lines (103 loc) · 4.48 KB
/
test-runner-coverage-default-exclusion.mjs
File metadata and controls
116 lines (103 loc) · 4.48 KB
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
113
114
115
116
import '../common/index.mjs';
import { before, describe, it } from 'node:test';
import assert from 'node:assert';
import { spawnSync } from 'node:child_process';
import { cp } from 'node:fs/promises';
import tmpdir from '../common/tmpdir.js';
import fixtures from '../common/fixtures.js';
const skipIfNoInspector = {
skip: !process.features.inspector ? 'inspector disabled' : false
};
tmpdir.refresh();
async function setupFixtures() {
const fixtureDir = fixtures.path('test-runner', 'coverage-default-exclusion');
await cp(fixtureDir, tmpdir.path, { recursive: true });
}
describe('test runner coverage default exclusion', skipIfNoInspector, () => {
before(async () => {
await setupFixtures();
});
it('should override default exclusion setting --test-coverage-exclude', async () => {
const report = [
'# start of coverage report',
'# ---------------------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# ---------------------------------------------------------------------------',
'# file-test.js | 100.00 | 100.00 | 100.00 | ',
'# file.test.mjs | 100.00 | 100.00 | 100.00 | ',
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
'# test.cjs | 100.00 | 100.00 | 100.00 | ',
'# test | | | | ',
'# not-matching-test-name.js | 100.00 | 100.00 | 100.00 | ',
'# ---------------------------------------------------------------------------',
'# all files | 91.89 | 100.00 | 83.33 | ',
'# ---------------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
const args = [
'--test',
'--experimental-test-coverage',
'--test-coverage-exclude=!test/**',
'--test-reporter=tap',
];
const result = spawnSync(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
});
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});
it('should exclude test files from coverage by default', async () => {
const report = [
'# start of coverage report',
'# --------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# --------------------------------------------------------------',
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
'# --------------------------------------------------------------',
'# all files | 66.67 | 100.00 | 50.00 | ',
'# --------------------------------------------------------------',
'# end of coverage report',
].join('\n');
const args = [
'--test',
'--experimental-test-coverage',
'--test-reporter=tap',
];
const result = spawnSync(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
});
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});
it('should exclude ts test files when using --experimental-strip-types', async () => {
const report = [
'# start of coverage report',
'# --------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# --------------------------------------------------------------',
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7',
'# --------------------------------------------------------------',
'# all files | 66.67 | 100.00 | 50.00 | ',
'# --------------------------------------------------------------',
'# end of coverage report',
].join('\n');
const args = [
'--test',
'--experimental-test-coverage',
'--experimental-strip-types',
'--disable-warning=ExperimentalWarning',
'--test-reporter=tap',
];
const result = spawnSync(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: tmpdir.path
});
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});
});