Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jun 14, 2022
1 parent 6ae1d49 commit e9ea260
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
ERR_TEST_FAILURE,
},
} = require('internal/errors');
const test = require('internal/test_runner/harness');
const { test } = require('internal/test_runner/harness');
const { kSubtestsFailed } = require('internal/test_runner/test');
const {
isSupportedFileType,
Expand Down
15 changes: 10 additions & 5 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const { Test } = require('internal/test_runner/test');


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

function createProcessEventHandler(eventName, rootTest) {
return (err) => {
Expand Down Expand Up @@ -42,6 +44,9 @@ function createProcessEventHandler(eventName, rootTest) {
}

function setup(root) {
if (wasRootSetup) {
return root;
}
const hook = createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (resource instanceof Test) {
Expand Down Expand Up @@ -118,26 +123,26 @@ function setup(root) {

root.reporter.pipe(process.stdout);
root.reporter.version();

wasRootSetup = true;
return root;
}

const root = setup(new Test({ name: '<root>' }));

function test(name, options, fn) {
const subtest = this.createSubtest(name, options, fn);
const subtest = setup(root).createSubtest(name, options, fn);
return subtest.start();
}

function describe(name, options, fn) {
const parent = testResources.get(executionAsyncId()) || root;
const parent = testResources.get(executionAsyncId()) || setup(root);
const suite = parent.createSubSuite(name, options, fn);
if (parent === root) {
suite.run();
}
}

function it(name, options, fn) {
const parent = testResources.get(executionAsyncId()) || root;
const parent = testResources.get(executionAsyncId()) || setup(root);
parent.createSubtest(name, options, fn);
}

Expand Down

0 comments on commit e9ea260

Please sign in to comment.