diff --git a/index.js b/index.js index 366f4aa28..4a411c3be 100644 --- a/index.js +++ b/index.js @@ -77,3 +77,4 @@ module.exports.before = runner.addBeforeHook.bind(runner); module.exports.after = runner.addAfterHook.bind(runner); module.exports.beforeEach = runner.addBeforeEachHook.bind(runner); module.exports.afterEach = runner.addAfterEachHook.bind(runner); +module.exports.skip = runner.addSkippedTest.bind(runner); diff --git a/lib/logger.js b/lib/logger.js index c7382b309..1b1397bbe 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -39,6 +39,11 @@ x.test = function (props) { return; } + if (props.skip) { + log.write(' ' + chalk.cyan('- ' + props.title)); + return; + } + // if (runner.stats.testCount === 1) { // return; // } diff --git a/lib/runner.js b/lib/runner.js index 1615d9ddd..241a96fa3 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -90,7 +90,19 @@ Runner.prototype.addAfterEachHook = function (title, cb) { }); }; +Runner.prototype.addSkippedTest = function (title, cb) { + var test = new Test(title, cb); + test.skip = true; + + this.tests.concurrent.push(test); +}; + Runner.prototype._runTestWithHooks = function (test) { + if (test.skip) { + this._addTestResult(test); + return Promise.resolve(); + } + var beforeHooks = this.tests.beforeEach.map(function (hook) { var title = hook.title || 'beforeEach for "' + test.title + '"'; hook = new Test(title, hook.fn); @@ -162,7 +174,8 @@ Runner.prototype._addTestResult = function (test) { duration: test.duration, title: test.title, error: test.assertError, - type: test.type + type: test.type, + skip: test.skip }; this.results.push(props); diff --git a/test/test.js b/test/test.js index 0e7809dac..8dd632ced 100644 --- a/test/test.js +++ b/test/test.js @@ -857,6 +857,30 @@ test('test types and titles', function (t) { runner.run().then(t.end); }); +test('skip test', function (t) { + t.plan(3); + + var runner = new Runner(); + var arr = []; + + runner.addTest(function (a) { + arr.push('a'); + a.end(); + }); + + runner.addSkippedTest(function (a) { + arr.push('b'); + a.end(); + }); + + runner.run().then(function () { + t.is(runner.stats.testCount, 1); + t.is(runner.stats.passCount, 1); + t.same(arr, ['a']); + t.end(); + }); +}); + test('ES2015 support', function (t) { t.plan(1);