Skip to content

Commit

Permalink
Merge branch 'master' into feat/hot-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull authored May 4, 2020
2 parents fba0182 + 240cb3d commit f3f82c2
Show file tree
Hide file tree
Showing 26 changed files with 476 additions and 299 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'
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ Node.JS native ESM support still has status: **Stability: 1 - Experimental**
- [Custom reporters](#third-party-reporters) and [custom interfaces](#interfaces)
can only be CommonJS files
- [Required modules](#-require-module-r-module) can only be CommonJS files
- [Configuration file](#configuring-mocha-nodejs) can only be a CommonJS file (`mocharc.js` or `mocharc.cjs`)
- [Configuration file](#configuring-mocha-nodejs) can only be a CommonJS file (`.mocharc.js` or `.mocharc.cjs`)
- When using module-level mocks via libs like `proxyquire`, `rewiremock` or `rewire`, hold off on using ES modules for your test files
- Node.JS native ESM support does not work with [esm][npm-esm] module

Expand Down Expand Up @@ -1732,7 +1732,7 @@ tests as shown below:
Mocha supports configuration files, typical of modern command-line tools, in several formats:

- **JavaScript**: Create a `.mocharc.js` (or `mocharc.cjs` when using [`"type"="module"`](#nodejs-native-esm-support) in your `package.json`)
- **JavaScript**: Create a `.mocharc.js` (or `.mocharc.cjs` when using [`"type"="module"`](#nodejs-native-esm-support) in your `package.json`)
in your project's root directory, and export an object (`module.exports = {/* ... */}`) containing your configuration.
- **YAML**: Create a `.mocharc.yaml` (or `.mocharc.yml`) in your project's root directory.
- **JSON**: Create a `.mocharc.json` (or `.mocharc.jsonc`) in your project's root directory. Comments — while not valid JSON — are allowed in this file, and will be ignored by Mocha.
Expand Down
22 changes: 11 additions & 11 deletions example/config/.mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ 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
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 @@ -425,7 +425,9 @@ Mocha.prototype.unloadFiles = function() {
);
}

this.files.forEach(Mocha.unloadFile);
this.files.forEach(function(file) {
Mocha.unloadFile(file);
});
this._state = mochaStates.INIT;
return this;
};
Expand Down
6 changes: 6 additions & 0 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function Doc(runner, options) {

runner.on(EVENT_TEST_PASS, function(test) {
Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.title));
Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.file));
var code = utils.escape(utils.clean(test.body));
Base.consoleLog('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
});
Expand All @@ -72,6 +73,11 @@ function Doc(runner, options) {
indent(),
utils.escape(test.title)
);
Base.consoleLog(
'%s <dt class="error">%s</dt>',
indent(),
utils.escape(test.file)
);
var code = utils.escape(utils.clean(test.body));
Base.consoleLog(
'%s <dd class="error"><pre><code>%s</code></pre></dd>',
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/json-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
file: test.file,
duration: test.duration,
currentRetry: test.currentRetry()
};
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
file: test.file,
duration: test.duration,
currentRetry: test.currentRetry(),
err: cleanCycles(err)
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
"test",
"bdd",
"tdd",
"tap"
"tap",
"testing",
"chai",
"assertion",
"ava",
"jest",
"tape",
"jasmine",
"karma"
],
"funding": {
"type": "opencollective",
Expand Down
20 changes: 19 additions & 1 deletion test/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ exports.mixinMochaAssertions = function(expect) {
});
}
)
.addAssertion(
'<RawRunResult> [not] to have failed [test] count <number>',
function(expect, result, count) {
expect(result.failing, '[not] to be', count);
}
)
.addAssertion(
'<RawRunResult> [not] to have passed [test] count <number>',
function(expect, result, count) {
expect(result.passing, '[not] to be', count);
}
)
.addAssertion(
'<RawRunResult> [not] to have pending [test] count <number>',
function(expect, result, count) {
expect(result.pending, '[not] to be', count);
}
)
.addAssertion('<JSONRunResult> [not] to have test count <number>', function(
expect,
result,
Expand Down Expand Up @@ -315,7 +333,7 @@ exports.mixinMochaAssertions = function(expect) {
}
)
.addAssertion(
'<RawRunResult|JSONRunResult> to have [exit] code <number>',
'<RawResult|RawRunResult|JSONRunResult> to have [exit] code <number>',
function(expect, result, code) {
expect(result.code, 'to be', code);
}
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 f3f82c2

Please sign in to comment.