Skip to content

Commit

Permalink
assorted test fixes & refactors (#4240)
Browse files Browse the repository at this point in the history
- increase default timeout for wiggle room
- specify `watch-ignore` in case we run our own tests in watch mode
- reformat `.mocharc.yml`
- `integration/fixtures/uncaught/listeners.fixture.js`: reduce number of listeners created to avoid max listener warning
- `integration/fixtures/diffs.spec.js`: do not pass `-C`; the helper already does this
- `integration/options/watch.spec.js`: do not use context object; be more specific about spawn options. tweak timings
- `node-unit/mocha.spec.js`: make more unit-test-like insofar as that's possible when testing w/ `require()`
- `node-unit/cli/config.spec.js`: rewiremock fixes; assertion tweaks; add test for `.cjs` extension
- `node-unit/cli/options.spec.js`: rewiremock fixes; increase timeout
- `unit/hook-timeout.spec.js`: do not override default (configured) timeout
- `unit/runner.spec.js`: leverage [unexpected-eventemitter](https://npm.im/unexpected-eventemitter)
- `unit/throw.spec.js`: proper teardown: remove uncaught exception listeners
- `unit/timeout.spec.js`: increase timeout to _greater than_ default (configured) value
- `example/config/.mocharc.yml`: quote yaml strings

BONUS

- fixes a weird call to `Mocha.unloadFile()` from `Mocha#unloadFiles()`

Ref: #4198
  • Loading branch information
boneskull authored and craigtaub committed May 21, 2020
1 parent 032f586 commit 8b9ce08
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 171 deletions.
19 changes: 13 additions & 6 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
require: test/setup
ui: bdd
require: 'test/setup'
ui: 'bdd'
global:
- okGlobalA,okGlobalB
- okGlobalC
- callback*
timeout: 300
- 'okGlobalA,okGlobalB'
- 'okGlobalC'
- 'callback*'
timeout: 1000
watch-ignore:
- '.*'
- 'docs/_dist/**'
- 'docs/_site/**'
- 'node_modules'
- 'coverage'
- 'cache'
22 changes: 11 additions & 11 deletions example/config/.mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ delay: false
diff: true
exit: false # could be expressed as "no-exit: true"
extension:
- js
- 'js'
# fgrep and grep are mutually exclusive
# fgrep: something
file:
- /path/to/some/file
- /path/to/some/other/file
- '/path/to/some/file'
- '/path/to/some/other/file'
forbid-only: false
forbid-pending: false
full-trace: false
global:
- jQuery
- $
- 'jQuery'
- '$'
# fgrep and grep are mutually exclusive
# grep: something
growl: false
ignore:
- /path/to/some/ignored/file
- '/path/to/some/ignored/file'
inline-diffs: false
# needs to be used with grep or fgrep
# invert: false
opts: false
recursive: false
reporter: spec
reporter: 'spec'
reporter-option:
- foo=bar
- baz=quux
- 'foo=bar'
- 'baz=quux'
require: '@babel/register'
retries: 1
slow: 75
sort: false
spec: test/**/*.spec.js # the positional arguments!
spec: 'test/**/*.spec.js' # the positional arguments!
timeout: false # same as "no-timeout: true" or "timeout: 0"
trace-warnings: true # node flags ok
ui: bdd
ui: 'bdd'
v8-stack-trace-limit: 100 # V8 flags are prepended with "v8-"
watch: false
watch-files:
Expand Down
4 changes: 3 additions & 1 deletion lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ Mocha.unloadFile = function(file) {
* @chainable
*/
Mocha.prototype.unloadFiles = function() {
this.files.forEach(Mocha.unloadFile);
this.files.forEach(function(file) {
Mocha.unloadFile(file);
});
return this;
};

Expand Down
2 changes: 1 addition & 1 deletion test/integration/diffs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('diffs', function() {
var diffs, expected;

before(function(done) {
run('diffs/diffs.fixture.js', ['-C'], function(err, res) {
run('diffs/diffs.fixture.js', [], function(err, res) {
if (err) {
done(err);
return;
Expand Down
3 changes: 2 additions & 1 deletion test/integration/fixtures/uncaught/listeners.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const assert = require('assert');
const mocha = require("../../../../lib/mocha");

for (let i = 0; i < 15; i++) {
// keep this low to avoid warning
for (let i = 0; i < 5; i++) {
const r = new mocha.Runner(new mocha.Suite("" + i, undefined));
r.run();
}
Expand Down
Loading

0 comments on commit 8b9ce08

Please sign in to comment.