Skip to content

Commit

Permalink
Merge branch 'master' into issue/3289
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull authored Apr 4, 2018
2 parents 401dea4 + 9ba8eca commit 93be397
Show file tree
Hide file tree
Showing 29 changed files with 547 additions and 688 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# 5.0.5 / 2018-03-22

Welcome [@outsideris] to the team!

## :bug: Fixes

- [#3096]: Fix `--bail` failing to bail within hooks ([@outsideris])
- [#3184]: Don't skip too many suites (using `describe.skip()`) ([@outsideris])

## :book: Documentation

- [#3133]: Improve docs regarding "pending" behavior ([@ematicipo])
- [#3276], [#3274]: Fix broken stuff in `CHANGELOG.md` ([@tagoro9], [@honzajavorek])

## :nut_and_bolt: Other

- [#3208]: Improve test coverage for AMD users ([@outsideris])
- [#3267]: Remove vestiges of PhantomJS from CI ([@anishkny])
- [#2952]: Fix a debug message ([@boneskull])

[#3096]: https://github.com/mochajs/mocha/issues/3096
[#3184]: https://github.com/mochajs/mocha/issues/3184
[#3133]: https://github.com/mochajs/mocha/issues/3133
[#3276]: https://github.com/mochajs/mocha/pull/3276
[#3274]: https://github.com/mochajs/mocha/pull/3274
[#3208]: https://github.com/mochajs/mocha/issues/3208
[#2952]: https://github.com/mochajs/mocha/issues/2952
[#3267]: https://github.com/mochajs/mocha/pull/3267

[@ematicipo]: https://github.com/ematicipo
[@tagoro9]: https://github.com/tagoro9
[@honzajavorek]: https://github.com/honajavorek
[@anishkny]: https://github.com/anishkny

# 5.0.4 / 2018-03-07

## :bug: Fixes
Expand Down
15 changes: 12 additions & 3 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const program = require('commander');
const path = require('path');
const fs = require('fs');
const minimatch = require('minimatch');
const resolve = path.resolve;
const exists = fs.existsSync;
const Mocha = require('../');
Expand Down Expand Up @@ -200,12 +201,13 @@ program
.option('--trace-deprecation', 'show stack traces on deprecations')
.option('--trace-warnings', 'show stack traces on node process warnings')
.option('--use_strict', 'enforce strict mode')
.option('--watch-extensions <ext>,...', 'additional extensions to monitor with --watch', list, [])
.option('--watch-extensions <ext>,...', 'specify extensions to monitor with --watch', list, [])
.option('--delay', 'wait for async suite definition')
.option('--allow-uncaught', 'enable uncaught errors to propagate')
.option('--forbid-only', 'causes test marked with only to fail the suite')
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
.option('--file <file>', 'include a file to be ran during the suite', collect, []);
.option('--file <file>', 'include a file to be ran during the suite', collect, [])
.option('--exclude <file>', 'a file or glob pattern to ignore', collect, []);

program._name = 'mocha';

Expand Down Expand Up @@ -494,6 +496,13 @@ args.forEach(arg => {
throw err;
}

if (typeof newFiles !== 'undefined') {
if (typeof newFiles === 'string') {
newFiles = [newFiles];
}
newFiles = newFiles.filter(fileName => program.exclude.every(pattern => !minimatch(fileName, pattern)));
}

files = files.concat(newFiles);
});

Expand Down Expand Up @@ -529,7 +538,7 @@ if (program.watch) {
process.exit(130);
});

const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
const watchFiles = utils.files(cwd, program.watchExtensions);
let runAgain = false;

loadAndRun = () => {
Expand Down
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module.exports = config => {
logLevel: config.LOG_INFO,
client: {
mocha: {
reporter: 'html'
reporter: 'html',
timeout: 500
}
},
mochaReporter: {
Expand Down
23 changes: 18 additions & 5 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Runnable.prototype.slow = function (ms) {
if (typeof ms === 'string') {
ms = milliseconds(ms);
}
debug('timeout %d', ms);
debug('slow %d', ms);
this._slow = ms;
return this;
};
Expand Down Expand Up @@ -252,8 +252,7 @@ Runnable.prototype.resetTimeout = function () {
if (!self._enableTimeouts) {
return;
}
self.callback(new Error('Timeout of ' + ms +
'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.'));
self.callback(self._timeoutError(ms));
self.timedOut = true;
}, ms);
};
Expand Down Expand Up @@ -319,8 +318,7 @@ Runnable.prototype.run = function (fn) {
self.duration = new Date() - start;
finished = true;
if (!err && self.duration > ms && self._enableTimeouts) {
err = new Error('Timeout of ' + ms +
'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
err = self._timeoutError(ms);
}
fn(err);
}
Expand Down Expand Up @@ -417,3 +415,18 @@ Runnable.prototype.run = function (fn) {
});
}
};

/**
* Instantiates a "timeout" error
*
* @param {number} ms - Timeout (in milliseconds)
* @returns {Error} a "timeout" error
* @private
*/
Runnable.prototype._timeoutError = function (ms) {
var msg = 'Timeout of ' + ms + 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
if (this.file) {
msg += ' (' + this.file + ')';
}
return new Error(msg);
};
51 changes: 23 additions & 28 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ Suite.prototype.isPending = function () {
return this.pending || (this.parent && this.parent.isPending());
};

/**
* Generic hook-creator.
* @private
* @param {string} title - Title of hook
* @param {Function} fn - Hook callback
* @returns {Hook} A new hook
*/
Suite.prototype._createHook = function (title, fn) {
var hook = new Hook(title, fn);
hook.parent = this;
hook.timeout(this.timeout());
hook.retries(this.retries());
hook.enableTimeouts(this.enableTimeouts());
hook.slow(this.slow());
hook.ctx = this.ctx;
hook.file = this.file;
return hook;
};

/**
* Run `fn(test[, done])` before running tests.
*
Expand All @@ -207,13 +226,7 @@ Suite.prototype.beforeAll = function (title, fn) {
}
title = '"before all" hook' + (title ? ': ' + title : '');

var hook = new Hook(title, fn);
hook.parent = this;
hook.timeout(this.timeout());
hook.retries(this.retries());
hook.enableTimeouts(this.enableTimeouts());
hook.slow(this.slow());
hook.ctx = this.ctx;
var hook = this._createHook(title, fn);
this._beforeAll.push(hook);
this.emit('beforeAll', hook);
return this;
Expand All @@ -237,13 +250,7 @@ Suite.prototype.afterAll = function (title, fn) {
}
title = '"after all" hook' + (title ? ': ' + title : '');

var hook = new Hook(title, fn);
hook.parent = this;
hook.timeout(this.timeout());
hook.retries(this.retries());
hook.enableTimeouts(this.enableTimeouts());
hook.slow(this.slow());
hook.ctx = this.ctx;
var hook = this._createHook(title, fn);
this._afterAll.push(hook);
this.emit('afterAll', hook);
return this;
Expand All @@ -267,13 +274,7 @@ Suite.prototype.beforeEach = function (title, fn) {
}
title = '"before each" hook' + (title ? ': ' + title : '');

var hook = new Hook(title, fn);
hook.parent = this;
hook.timeout(this.timeout());
hook.retries(this.retries());
hook.enableTimeouts(this.enableTimeouts());
hook.slow(this.slow());
hook.ctx = this.ctx;
var hook = this._createHook(title, fn);
this._beforeEach.push(hook);
this.emit('beforeEach', hook);
return this;
Expand All @@ -297,13 +298,7 @@ Suite.prototype.afterEach = function (title, fn) {
}
title = '"after each" hook' + (title ? ': ' + title : '');

var hook = new Hook(title, fn);
hook.parent = this;
hook.timeout(this.timeout());
hook.retries(this.retries());
hook.enableTimeouts(this.enableTimeouts());
hook.slow(this.slow());
hook.ctx = this.ctx;
var hook = this._createHook(title, fn);
this._afterEach.push(hook);
this.emit('afterEach', hook);
return this;
Expand Down
Empty file added nom
Empty file.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mocha",
"version": "5.0.4",
"version": "5.0.5",
"description": "simple, flexible, fun test framework",
"keywords": [
"mocha",
Expand Down Expand Up @@ -432,6 +432,7 @@
"zhiyelee <zhiyelee@gmail.com>",
"Zsolt Takács <zsolt@takacs.cc>",
"现充 <qixiang.cqx@alibaba-inc.com>"

],
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -459,6 +460,7 @@
"glob": "7.1.2",
"growl": "1.10.3",
"he": "1.1.1",
"minimatch": "^3.0.4",
"mkdirp": "0.5.1",
"supports-color": "4.4.0"
},
Expand Down
7 changes: 7 additions & 0 deletions test/integration/fixtures/options/exclude/fail.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('exclude test fail', function () {
it('should not run this test', function () {
throw new Error('should not run');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('exclude test nested fail', function () {
it('should not run this test', function () {
throw new Error('should not run');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

describe('exclude test nested pass', function () {
it('should find this test', function () {});
});
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/exclude/pass.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

describe('exclude test pass', function () {
it('should find this test', function () {});
});
53 changes: 53 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,57 @@ describe('options', function () {
}, path.join(__dirname, 'fixtures', 'options', 'help'));
});
});

describe('--exclude', function () {
/*
* Runs mocha in {path} with the given args.
* Calls handleResult with the result.
*/
function runMochaTest (fixture, args, handleResult, done) {
run(fixture, args, function (err, res) {
if (err) {
done(err);
return;
}
handleResult(res);
done();
});
}

it('should exclude specific files', function (done) {
runMochaTest('options/exclude/*.fixture.js', [
'--exclude',
'test/integration/fixtures/options/exclude/fail.fixture.js'
], function (res) {
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
assert.equal(res.passes[0].title, 'should find this test');
assert.equal(res.code, 0);
}, done);
});

it('should exclude globbed files', function (done) {
runMochaTest('options/exclude/**/*.fixture.js', ['--exclude', '**/fail.fixture.js'], function (res) {
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
}, done);
});

it('should exclude multiple patterns', function (done) {
runMochaTest('options/exclude/**/*.fixture.js', [
'--exclude',
'test/integration/fixtures/options/exclude/fail.fixture.js',
'--exclude',
'test/integration/fixtures/options/exclude/nested/fail.fixture.js'
], function (res) {
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
}, done);
});
});
});
Loading

0 comments on commit 93be397

Please sign in to comment.