Skip to content

Commit 41fd96f

Browse files
author
vdemedes
committed
add test.skip()
1 parent b55a05a commit 41fd96f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ module.exports.before = runner.addBeforeHook.bind(runner);
7777
module.exports.after = runner.addAfterHook.bind(runner);
7878
module.exports.beforeEach = runner.addBeforeEachHook.bind(runner);
7979
module.exports.afterEach = runner.addAfterEachHook.bind(runner);
80+
module.exports.skip = runner.addSkippedTest.bind(runner);

lib/logger.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ x.test = function (props) {
3939
return;
4040
}
4141

42+
if (props.skip) {
43+
log.write(' ' + chalk.cyan('- ' + props.title));
44+
return;
45+
}
46+
4247
// if (runner.stats.testCount === 1) {
4348
// return;
4449
// }

lib/runner.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,19 @@ Runner.prototype.addAfterEachHook = function (title, cb) {
9090
});
9191
};
9292

93+
Runner.prototype.addSkippedTest = function (title, cb) {
94+
var test = new Test(title, cb);
95+
test.skip = true;
96+
97+
this.tests.concurrent.push(test);
98+
};
99+
93100
Runner.prototype._runTestWithHooks = function (test) {
101+
if (test.skip) {
102+
this._addTestResult(test);
103+
return Promise.resolve();
104+
}
105+
94106
var beforeHooks = this.tests.beforeEach.map(function (hook) {
95107
var title = hook.title || 'beforeEach for "' + test.title + '"';
96108
hook = new Test(title, hook.fn);
@@ -162,7 +174,8 @@ Runner.prototype._addTestResult = function (test) {
162174
duration: test.duration,
163175
title: test.title,
164176
error: test.assertError,
165-
type: test.type
177+
type: test.type,
178+
skip: test.skip
166179
};
167180

168181
this.results.push(props);

test/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,30 @@ test('test types and titles', function (t) {
857857
runner.run().then(t.end);
858858
});
859859

860+
test('skip test', function (t) {
861+
t.plan(3);
862+
863+
var runner = new Runner();
864+
var arr = [];
865+
866+
runner.addTest(function (a) {
867+
arr.push('a');
868+
a.end();
869+
});
870+
871+
runner.addSkippedTest(function (a) {
872+
arr.push('b');
873+
a.end();
874+
});
875+
876+
runner.run().then(function () {
877+
t.is(runner.stats.testCount, 1);
878+
t.is(runner.stats.passCount, 1);
879+
t.same(arr, ['a']);
880+
t.end();
881+
});
882+
});
883+
860884
test('ES2015 support', function (t) {
861885
t.plan(1);
862886

0 commit comments

Comments
 (0)