Skip to content

Commit

Permalink
skipn only
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Jun 15, 2022
1 parent 550101f commit 561565d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
30 changes: 22 additions & 8 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,35 @@ function test(name, options, fn) {
return subtest.start();
}

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

function describe(name, options, fn, overrides) {
const parent = getParent();
const suite = parent.createSubSuite(name, options, fn, overrides);
if (parent === root) {
suite.run();
}
return suite;
}

function it(name, options, fn, overrides) {
return getParent().createSubtest(name, options, fn, overrides);
}

function it(name, options, fn) {
const parent = testResources.get(executionAsyncId()) || setup(root);
parent.createSubtest(name, options, fn);
function enrichMethod(method) {
['skip', 'only'].forEach((keyword) => {
method[keyword] = function(name, options, fn) {
return method(name, options, fn, { [keyword]: true });
}
});

return method;
}

module.exports = {
test: FunctionPrototypeBind(test, root),
describe,
it,
describe: enrichMethod(describe),
it: enrichMethod(it),
};
3 changes: 2 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ class Suite extends Test {
async run() {
this.parent.activeSubtests++;
this.startTime = hrtime();
for (const subtest of this.subtests) {
const subtests = this.skipped ? [] : this.subtests;
for (const subtest of subtests) {
await subtest.run();
}
this.pass();
Expand Down

0 comments on commit 561565d

Please sign in to comment.