Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorColin Ihrig <cjihrig@gmail.com>2022-04-04 17:14:49 +0300
committerGitHub <noreply@github.com>2022-04-04 17:14:49 +0300
commit54819f08e0c469528901d81a9cee546ea518a5c3 (patch)
treee1e9093b64489985f5c8f779e202b3f0e698b9af /lib
parent0c9273d1266bbe67fcdc423913fc8c83c259aa83 (diff)
test_runner: support 'only' tests
This commit introduces a CLI flag and test runner functionality to support running a subset of tests that are indicated by an 'only' option passed to the test. PR-URL: https://github.com/nodejs/node/pull/42514 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/test_runner/test.js33
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js
index e2dddf5cc20..3e632cc1c52 100644
--- a/lib/internal/test_runner/test.js
+++ b/lib/internal/test_runner/test.js
@@ -13,6 +13,7 @@ const {
ERR_TEST_FAILURE,
},
} = require('internal/errors');
+const { getOptionValue } = require('internal/options');
const { TapStream } = require('internal/test_runner/tap_stream');
const { createDeferredPromise } = require('internal/util');
const { isPromise } = require('internal/util/types');
@@ -26,6 +27,7 @@ const kSubtestsFailed = 'subtestsFailed';
const kTestCodeFailure = 'testCodeFailure';
const kDefaultIndent = ' ';
const noop = FunctionPrototype;
+const testOnlyFlag = getOptionValue('--test-only');
class TestContext {
#test;
@@ -38,6 +40,10 @@ class TestContext {
this.#test.diagnostic(message);
}
+ runOnly(value) {
+ this.#test.runOnlySubtests = !!value;
+ }
+
skip(message) {
this.#test.skip(message);
}
@@ -57,8 +63,8 @@ class Test extends AsyncResource {
constructor(options) {
super('Test');
- let { fn, name, parent } = options;
- const { concurrency, skip, todo } = options;
+ let { fn, name, parent, skip } = options;
+ const { concurrency, only, todo } = options;
if (typeof fn !== 'function') {
fn = noop;
@@ -72,19 +78,13 @@ class Test extends AsyncResource {
parent = null;
}
- if (skip) {
- fn = noop;
- }
-
- this.fn = fn;
- this.name = name;
- this.parent = parent;
-
if (parent === null) {
this.concurrency = 1;
this.indent = '';
this.indentString = kDefaultIndent;
+ this.only = testOnlyFlag;
this.reporter = new TapStream();
+ this.runOnlySubtests = this.only;
this.testNumber = 0;
} else {
const indent = parent.parent === null ? parent.indent :
@@ -93,7 +93,9 @@ class Test extends AsyncResource {
this.concurrency = parent.concurrency;
this.indent = indent;
this.indentString = parent.indentString;
+ this.only = only ?? !parent.runOnlySubtests;
this.reporter = parent.reporter;
+ this.runOnlySubtests = !this.only;
this.testNumber = parent.subtests.length + 1;
}
@@ -101,6 +103,17 @@ class Test extends AsyncResource {
this.concurrency = concurrency;
}
+ if (testOnlyFlag && !this.only) {
+ skip = '\'only\' option not set';
+ }
+
+ if (skip) {
+ fn = noop;
+ }
+
+ this.fn = fn;
+ this.name = name;
+ this.parent = parent;
this.cancelled = false;
this.skipped = !!skip;
this.isTodo = !!todo;