Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--forbid-only and --forbid-pending now handle suites properly #3578

Merged
merged 3 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/interfaces/common.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

describe.only('forbid only - suite marked with only', function() {});
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading