Skip to content

Commit e9ea260

Browse files
committed
fixes
1 parent 6ae1d49 commit e9ea260

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/internal/main/test_runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const {
2020
ERR_TEST_FAILURE,
2121
},
2222
} = require('internal/errors');
23-
const test = require('internal/test_runner/harness');
23+
const { test } = require('internal/test_runner/harness');
2424
const { kSubtestsFailed } = require('internal/test_runner/test');
2525
const {
2626
isSupportedFileType,

lib/internal/test_runner/harness.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const { Test } = require('internal/test_runner/test');
1414

1515

1616
const testResources = new SafeMap();
17+
const root = new Test({ name: '<root>' });
18+
let wasRootSetup = false;
1719

1820
function createProcessEventHandler(eventName, rootTest) {
1921
return (err) => {
@@ -42,6 +44,9 @@ function createProcessEventHandler(eventName, rootTest) {
4244
}
4345

4446
function setup(root) {
47+
if (wasRootSetup) {
48+
return root;
49+
}
4550
const hook = createHook({
4651
init(asyncId, type, triggerAsyncId, resource) {
4752
if (resource instanceof Test) {
@@ -118,26 +123,26 @@ function setup(root) {
118123

119124
root.reporter.pipe(process.stdout);
120125
root.reporter.version();
126+
127+
wasRootSetup = true;
121128
return root;
122129
}
123130

124-
const root = setup(new Test({ name: '<root>' }));
125-
126131
function test(name, options, fn) {
127-
const subtest = this.createSubtest(name, options, fn);
132+
const subtest = setup(root).createSubtest(name, options, fn);
128133
return subtest.start();
129134
}
130135

131136
function describe(name, options, fn) {
132-
const parent = testResources.get(executionAsyncId()) || root;
137+
const parent = testResources.get(executionAsyncId()) || setup(root);
133138
const suite = parent.createSubSuite(name, options, fn);
134139
if (parent === root) {
135140
suite.run();
136141
}
137142
}
138143

139144
function it(name, options, fn) {
140-
const parent = testResources.get(executionAsyncId()) || root;
145+
const parent = testResources.get(executionAsyncId()) || setup(root);
141146
parent.createSubtest(name, options, fn);
142147
}
143148

0 commit comments

Comments
 (0)