Skip to content

Commit

Permalink
test_runner: emit test-only diagnostic warning
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemccoll committed Feb 9, 2023
1 parent 5092346 commit 8292f1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ class Test extends AsyncResource {
}

if (testOnlyFlag && !this.only) {
skip = '\'only\' option not set';
skip = "'only' option not set";
} else if (!testOnlyFlag && (only || this.runOnlySubtests)) {
this.emitOnlyWarning = true;
}

if (skip) {
Expand All @@ -274,8 +276,8 @@ class Test extends AsyncResource {
this.passed = false;
this.error = null;
this.diagnostics = [];
this.message = typeof skip === 'string' ? skip :
typeof todo === 'string' ? todo : null;
this.message =
typeof skip === 'string' ? skip : typeof todo === 'string' ? todo : null;
this.activeSubtests = 0;
this.pendingSubtests = [];
this.readySubtests = new SafeMap();
Expand Down Expand Up @@ -710,6 +712,13 @@ class Test extends AsyncResource {
for (let i = 0; i < this.diagnostics.length; i++) {
this.reporter.diagnostic(this.nesting, kFilename, this.diagnostics[i]);
}

if (this.emitOnlyWarning) {
const warning =
"to use 'only' or 'runOnly' in the test runner" +
' run node with the --test-only command-line option.';
this.reporter.diagnostic(this.nesting, kFilename, warning);
}
}

reportStarted() {
Expand Down
3 changes: 3 additions & 0 deletions test/message/test_runner_output.out
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,13 @@ ok 52 - callback async throw after done
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: running subtest 3
ok 3 - running subtest 3
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: running subtest 4
ok 4 - running subtest 4
---
Expand All @@ -490,6 +492,7 @@ ok 53 - only is set but not in only mode
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: custom inspect symbol fail
not ok 54 - custom inspect symbol fail
---
Expand Down
3 changes: 3 additions & 0 deletions test/message/test_runner_output_cli.out
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,13 @@ TAP version 13
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: running subtest 3
ok 3 - running subtest 3
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: running subtest 4
ok 4 - running subtest 4
---
Expand All @@ -491,6 +493,7 @@ TAP version 13
---
duration_ms: *
...
# to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
# Subtest: custom inspect symbol fail
not ok 54 - custom inspect symbol fail
---
Expand Down
3 changes: 3 additions & 0 deletions test/message/test_runner_output_spec_reporter.out
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@
only is set but not in only mode
running subtest 1 (*ms)
running subtest 2 (*ms)
to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
running subtest 3 (*ms)
to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.
running subtest 4 (*ms)
only is set but not in only mode (*ms)
to use 'only' or 'runOnly' in the test runner run node with the --test-only command-line option.

custom inspect symbol fail (*ms)
customized
Expand Down

0 comments on commit 8292f1b

Please sign in to comment.