Skip to content

Commit

Permalink
--forbid-only and --forbid-pending now handle suites properly (#3578)
Browse files Browse the repository at this point in the history
* fail-fast when .only encountered in Suite w/ --forbid-only
* fail-fast when .skip encountered in Suite w/ --forbid-pending
* move importing chai to the top of the file to avoid timeout

Signed-off-by: Outsider <outsideris@gmail.com>
  • Loading branch information
outsideris authored and boneskull committed Dec 7, 2018
1 parent 99af03c commit a113b85
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 30 deletions.
25 changes: 25 additions & 0 deletions lib/interfaces/common.js
Expand Up @@ -12,6 +12,22 @@ var utils = require('../utils');
* @return {Object} An object containing common functions.
*/
module.exports = function(suites, context, mocha) {
/**
* Check if the suite should be tested.
*
* @private
* @param {Suite} suite - suite to check
* @returns {boolean}
*/
function shouldBeTested(suite) {
return (
!mocha.options.grep ||
(mocha.options.grep &&
mocha.options.grep.test(suite.fullTitle()) &&
!mocha.options.invert)
);
}

return {
/**
* This is only present if flag --delay is passed into Mocha. It triggers
Expand Down Expand Up @@ -108,8 +124,17 @@ module.exports = function(suites, context, mocha) {
suite.file = opts.file;
suites.unshift(suite);
if (opts.isOnly) {
if (mocha.options.forbidOnly && shouldBeTested(suite)) {
throw new Error('`.only` forbidden');
}

suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
}
if (suite.pending) {
if (mocha.options.forbidPending && shouldBeTested(suite)) {
throw new Error('Pending test forbidden');
}
}
if (typeof opts.fn === 'function') {
var result = opts.fn.call(suite);
if (typeof result !== 'undefined') {
Expand Down
@@ -0,0 +1,3 @@
'use strict';

describe.only('forbid only - suite marked with only', function() {});
@@ -0,0 +1,3 @@
'use strict';

describe.skip('forbid pending - suite marked with skip', function() {});
2 changes: 1 addition & 1 deletion test/integration/helpers.js
Expand Up @@ -64,7 +64,7 @@ module.exports = {
var result = JSON.parse(res.output);
result.code = res.code;
} catch (err) {
return fn(err);
return fn(new Error('output is not valid JSON:\n\n' + res.output));
}

fn(null, result);
Expand Down

0 comments on commit a113b85

Please sign in to comment.