Skip to content

Commit 561565d

Browse files
committed
skipn only
1 parent 550101f commit 561565d

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/internal/test_runner/harness.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,35 @@ function test(name, options, fn) {
132132
return subtest.start();
133133
}
134134

135-
function describe(name, options, fn) {
136-
const parent = testResources.get(executionAsyncId()) || setup(root);
137-
const suite = parent.createSubSuite(name, options, fn);
135+
function getParent() {
136+
return testResources.get(executionAsyncId()) || setup(root);
137+
}
138+
139+
function describe(name, options, fn, overrides) {
140+
const parent = getParent();
141+
const suite = parent.createSubSuite(name, options, fn, overrides);
138142
if (parent === root) {
139143
suite.run();
140144
}
145+
return suite;
146+
}
147+
148+
function it(name, options, fn, overrides) {
149+
return getParent().createSubtest(name, options, fn, overrides);
141150
}
142151

143-
function it(name, options, fn) {
144-
const parent = testResources.get(executionAsyncId()) || setup(root);
145-
parent.createSubtest(name, options, fn);
152+
function enrichMethod(method) {
153+
['skip', 'only'].forEach((keyword) => {
154+
method[keyword] = function(name, options, fn) {
155+
return method(name, options, fn, { [keyword]: true });
156+
}
157+
});
158+
159+
return method;
146160
}
147161

148162
module.exports = {
149163
test: FunctionPrototypeBind(test, root),
150-
describe,
151-
it,
164+
describe: enrichMethod(describe),
165+
it: enrichMethod(it),
152166
};

lib/internal/test_runner/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ class Suite extends Test {
473473
async run() {
474474
this.parent.activeSubtests++;
475475
this.startTime = hrtime();
476-
for (const subtest of this.subtests) {
476+
const subtests = this.skipped ? [] : this.subtests;
477+
for (const subtest of subtests) {
477478
await subtest.run();
478479
}
479480
this.pass();

0 commit comments

Comments
 (0)