Skip to content

Commit d1d64c6

Browse files
committed
enh: cleanup tests
remove conosle logs, organize covereage into subtests, try to fool codecov into realizing the tests are fine.
1 parent 3a0f72e commit d1d64c6

3 files changed

Lines changed: 153 additions & 60 deletions

File tree

doc/node.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,10 @@ files must meet \fBboth\fR criteria to be included in the coverage report.
14041404
Require a minimum percent of covered lines. If code coverage does not reach
14051405
the threshold specified, the process will exit with code \fB1\fR.
14061406
.
1407+
.It Fl -test-files-glob
1408+
A glob pattern that configures the test runner to only run tests whose filename
1409+
matches the provided glob.
1410+
.
14071411
.It Fl -test-force-exit
14081412
Configures the test runner to exit the process once all known tests have
14091413
finished executing even if the event loop would otherwise remain active.

test/parallel/test-runner-cli.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ for (const isolation of ['none', 'process']) {
9191
assert.strictEqual(child.signal, null);
9292
assert.strictEqual(child.stderr.toString(), '');
9393
const stdout = child.stdout.toString();
94-
process.stderr.write(stdout);
9594

9695
assert.match(stdout, /ok 1 - index-test\.spec\.cjs this should pass/);
9796
assert.match(stdout, /ok 2 - index-test\.spec\.js this should pass/);
@@ -100,7 +99,7 @@ for (const isolation of ['none', 'process']) {
10099
}
101100

102101
{
103-
// Should ignore glob override when targeted file passed in
102+
// Should ignore test-files-glob when positionals passed in
104103
const args = [
105104
'--test',
106105
'--test-reporter=tap',
@@ -114,12 +113,32 @@ for (const isolation of ['none', 'process']) {
114113
assert.strictEqual(child.signal, null);
115114
assert.strictEqual(child.stderr.toString(), '');
116115
const stdout = child.stdout.toString();
117-
process.stderr.write(stdout);
118116

119117
assert.match(stdout, /ok 1 - index-test\.js should not run/);
120118
assert.doesNotMatch(stdout, /ok 2 - /);
121119
}
122120

121+
{
122+
// Should fail when test-files-glob is empty
123+
const args = [
124+
'--test',
125+
'--test-reporter=tap',
126+
'--test-files-glob',
127+
`--test-isolation=${isolation}`,
128+
];
129+
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'custom-files-glob') });
130+
131+
process.stdout.write('stdout' + '\n');
132+
process.stdout.write(child.stdout.toString() + '\n');
133+
process.stdout.write('stderr' + '\n');
134+
process.stdout.write(child.stderr.toString() + '\n');
135+
136+
assert.strictEqual(child.status, 9);
137+
assert.strictEqual(child.signal, null);
138+
assert.strictEqual(child.stdout.toString(), '');
139+
assert.match(child.stderr.toString(), /--test-files-glob requires an argument/);
140+
}
141+
123142
for (const type of ['strip', 'transform']) {
124143
{
125144
// Should match files with "-test.(c|m)(t|j)s" suffix when typescript support is enabled
@@ -172,6 +191,29 @@ for (const isolation of ['none', 'process']) {
172191
assert.doesNotMatch(stdout, /ok 4 - /);
173192
}
174193
}
194+
195+
{
196+
// Should fail if --test-files-glob empty
197+
const args = [
198+
'--test',
199+
'--test-reporter=tap',
200+
'--no-warnings',
201+
'--test-files-glob=',
202+
`--experimental-${type}-types`,
203+
`--test-isolation=${isolation}`,
204+
];
205+
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'custom-files-glob') });
206+
207+
if (!process.config.variables.node_use_amaro) {
208+
// e.g. Compiled with `--without-amaro`.
209+
assert.strictEqual(child.status, 1);
210+
} else {
211+
assert.strictEqual(child.status, 9);
212+
assert.strictEqual(child.signal, null);
213+
assert.strictEqual(child.stdout.toString(), '');
214+
assert.match(child.stderr.toString(), /--test-files-glob= requires an argument/);
215+
}
216+
}
175217
}
176218

177219
{

test/parallel/test-runner-coverage.js

Lines changed: 104 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -584,66 +584,113 @@ test('coverage with directory and file named "file"', skipIfNoInspector, () => {
584584
assertIncludesReport(result, 'start of coverage report');
585585
});
586586

587-
test('overrides default excludes when --test-files-glob is used', skipIfNoInspector, () => {
588-
const report = [
589-
'# start of coverage report',
590-
'# ------------------------------------------------------------------',
591-
'# file | line % | branch % | funcs % | uncovered lines',
592-
'# ------------------------------------------------------------------',
593-
'# test | | | | ',
594-
'# fixtures | | | | ',
595-
'# test-runner | | | | ',
596-
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
597-
'# v8-coverage | | | | ',
598-
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
599-
'# ------------------------------------------------------------------',
600-
'# all files | 75.00 | 66.67 | 100.00 | ',
601-
'# ------------------------------------------------------------------',
602-
'# end of coverage report',
603-
].join('\n');
587+
test('correctly prints coverage report with --test-files-glob pattern supplied', skipIfNoInspector, async (t) => {
588+
await t.test('overrides default excludes when --test-files-glob is used', () => {
589+
const report = [
590+
'# start of coverage report',
591+
'# ------------------------------------------------------------------',
592+
'# file | line % | branch % | funcs % | uncovered lines',
593+
'# ------------------------------------------------------------------',
594+
'# test | | | | ',
595+
'# fixtures | | | | ',
596+
'# test-runner | | | | ',
597+
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
598+
'# v8-coverage | | | | ',
599+
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
600+
'# ------------------------------------------------------------------',
601+
'# all files | 75.00 | 66.67 | 100.00 | ',
602+
'# ------------------------------------------------------------------',
603+
'# end of coverage report',
604+
].join('\n');
605+
606+
if (common.isWindows) {
607+
report = report.replaceAll('/', '\\');
608+
}
604609

605-
const args = [
606-
'--test',
607-
'--experimental-test-coverage',
608-
'--test-files-glob=**/test-runner/coverage.js',
609-
'--test-reporter=tap',
610-
];
611-
const result = spawnSync(process.execPath, args);
610+
const args = [
611+
'--test',
612+
'--experimental-test-coverage',
613+
'--test-files-glob=**/test-runner/coverage.js',
614+
'--test-reporter=tap',
615+
];
616+
const result = spawnSync(process.execPath, args);
612617

613-
assert.strictEqual(result.stderr.toString(), '');
614-
assert(result.stdout.toString().includes(report));
615-
assert.strictEqual(result.status, 0);
616-
});
618+
assert.strictEqual(result.stderr.toString(), '');
619+
assert(result.stdout.toString().includes(report));
620+
assert.strictEqual(result.status, 0);
621+
});
617622

618-
test('does not override explicit excludes when --test-files-glob is used', skipIfNoInspector, () => {
619-
const report = [
620-
'# start of coverage report',
621-
'# --------------------------------------------------------------------------------------------',
622-
'# file | line % | branch % | funcs % | uncovered lines',
623-
'# --------------------------------------------------------------------------------------------',
624-
'# test | | | | ',
625-
'# fixtures | | | | ',
626-
'# test-runner | | | | ',
627-
'# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72',
628-
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
629-
'# v8-coverage | | | | ',
630-
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
631-
'# --------------------------------------------------------------------------------------------',
632-
'# all files | 78.35 | 43.75 | 60.00 | ',
633-
'# --------------------------------------------------------------------------------------------',
634-
'# end of coverage report',
635-
].join('\n');
623+
await t.test('does not override excludes when --test-files-glob is used and --test-coverage-exclude is empty', () => {
624+
const report = [
625+
'# start of coverage report',
626+
'# --------------------------------------------------------------------------------------------',
627+
'# file | line % | branch % | funcs % | uncovered lines',
628+
'# --------------------------------------------------------------------------------------------',
629+
'# test | | | | ',
630+
'# fixtures | | | | ',
631+
'# test-runner | | | | ',
632+
'# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72',
633+
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
634+
'# v8-coverage | | | | ',
635+
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
636+
'# --------------------------------------------------------------------------------------------',
637+
'# all files | 78.35 | 43.75 | 60.00 | ',
638+
'# --------------------------------------------------------------------------------------------',
639+
'# end of coverage report',
640+
].join('\n');
641+
642+
if (common.isWindows) {
643+
report = report.replaceAll('/', '\\');
644+
}
636645

637-
const args = [
638-
'--test',
639-
'--experimental-test-coverage',
640-
'--test-files-glob=**/test-runner/coverage.js',
641-
'--test-coverage-exclude=!test/**',
642-
'--test-reporter=tap',
643-
];
644-
const result = spawnSync(process.execPath, args);
646+
const args = [
647+
'--test',
648+
'--experimental-test-coverage',
649+
'--test-files-glob=**/test-runner/coverage.js',
650+
'--test-coverage-exclude=""',
651+
'--test-reporter=tap',
652+
];
653+
const result = spawnSync(process.execPath, args);
645654

646-
assert.strictEqual(result.stderr.toString(), '');
647-
assert(result.stdout.toString().includes(report));
648-
assert.strictEqual(result.status, 0);
655+
assert.strictEqual(result.stderr.toString(), '');
656+
assert(result.stdout.toString().includes(report));
657+
assert.strictEqual(result.status, 0);
658+
});
659+
660+
await t.test('does not override excludes when --test-files-glob and --test-coverage-exclude are used', () => {
661+
const report = [
662+
'# start of coverage report',
663+
'# --------------------------------------------------------------------------------------------',
664+
'# file | line % | branch % | funcs % | uncovered lines',
665+
'# --------------------------------------------------------------------------------------------',
666+
'# test | | | | ',
667+
'# fixtures | | | | ',
668+
'# test-runner | | | | ',
669+
'# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72',
670+
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
671+
'# v8-coverage | | | | ',
672+
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
673+
'# --------------------------------------------------------------------------------------------',
674+
'# all files | 78.35 | 43.75 | 60.00 | ',
675+
'# --------------------------------------------------------------------------------------------',
676+
'# end of coverage report',
677+
].join('\n');
678+
679+
if (common.isWindows) {
680+
report = report.replaceAll('/', '\\');
681+
}
682+
683+
const args = [
684+
'--test',
685+
'--experimental-test-coverage',
686+
'--test-files-glob=**/test-runner/coverage.js',
687+
'--test-coverage-exclude=!test/**',
688+
'--test-reporter=tap',
689+
];
690+
const result = spawnSync(process.execPath, args);
691+
692+
assert.strictEqual(result.stderr.toString(), '');
693+
assert(result.stdout.toString().includes(report));
694+
assert.strictEqual(result.status, 0);
695+
});
649696
});

0 commit comments

Comments
 (0)