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

Feature ignore file #2036 #2173

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ program
.option('--use_strict', 'enforce strict mode')
.option('--watch-extensions <ext>,...', 'additional extensions to monitor with --watch', list, [])
.option('--delay', 'wait for async suite definition')
.option('--ignore-file <ignore-file-path>', 'specifies ignore file', './default.mochaignore')

program.name = 'mocha';

Expand Down Expand Up @@ -278,6 +279,10 @@ if (program.growl) mocha.growl();

if (program.asyncOnly) mocha.asyncOnly();

// --ignore-file

if (program.ignoreFile) mocha.ignoreFile(program.ignoreFile);

// --delay

if (program.delay) mocha.delay();
Expand Down
8 changes: 8 additions & 0 deletions lib/default.mochaignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Mocha ignore tests file
*/
module.exports = {
skipTests: [
// Enter titles here, separated by ','
]
};
13 changes: 13 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ Mocha.prototype.asyncOnly = function() {
return this;
};

/**
* Loads ignore file
*
* @param {String} ignoreFile
* @return {Mocha}
* @api public
*/
Mocha.prototype.ignoreFile = function(ignoreFile) {
this.options.ignoreFile = ignoreFile;
return this;
};

/**
* Disable syntax highlighting (in browser).
*
Expand Down Expand Up @@ -475,6 +487,7 @@ Mocha.prototype.run = function(fn) {
runner.ignoreLeaks = options.ignoreLeaks !== false;
runner.fullStackTrace = options.fullStackTrace;
runner.asyncOnly = options.asyncOnly;
runner.ignoreList = require(options.ignoreFile || './default.mochaignore');
runner.allowUncaught = options.allowUncaught;
if (options.grep) {
runner.grep(options.grep, options.invert);
Expand Down
17 changes: 17 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Runner(suite, delay) {
this.started = false;
this.total = suite.total();
this.failures = 0;
this.ignoreList = this.ignoreList || require('./default.mochaignore');
this.on('test end', function(test) {
self.checkGlobals(test);
});
Expand Down Expand Up @@ -211,6 +212,17 @@ Runner.prototype.checkGlobals = function(test) {
}
};

/**
* Checks if we need to ignore test.
*
* @api private
* @param {Test} test
* @return {Boolean} result of search in skip list.
*/
Runner.prototype.isInIgnoreList = function(test) {
return indexOf(this.ignoreList.skipTests, test.title, 0) !== -1;
};

/**
* Fail the given `test`.
*
Expand Down Expand Up @@ -485,6 +497,11 @@ Runner.prototype.runTests = function(suite, fn) {
return fn();
}

// check if we need to ignore
if (self.isInIgnoreList(test)) {
return next();
}

// grep
var match = self._grep.test(test.fullTitle());
if (self._invert) {
Expand Down