Skip to content

Commit cebddf2

Browse files
Lindsay-Needs-Sleepboneskull
authored andcommitted
Improve reporter documentation for mocha in browser. (#4026)
You can pass the constructor function of your custom reporter in options and mocha will use it. # Conflicts: # docs/index.md
1 parent 3f7b987 commit cebddf2

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

Diff for: docs/index.md

+27-15
Original file line numberDiff line numberDiff line change
@@ -868,17 +868,16 @@ Configuration
868868
--package Path to package.json for config [string]
869869
870870
File Handling
871-
--ignore, --exclude Ignore file(s) or glob pattern(s)
871+
--file Specify file(s) to be loaded prior to root suite
872+
execution [array] [default: (none)]
873+
--ignore, --exclude Ignore file(s) or glob pattern(s)
872874
[array] [default: (none)]
873875
--extension, --watch-extensions File extension(s) to load and/or watch
874-
[array] [default: js]
875-
--file Specify file(s) to be loaded prior to root
876-
suite execution [array] [default: (none)]
877-
--recursive Look for tests in subdirectories [boolean]
878-
--require, -r Require module [array] [default: (none)]
879-
--sort, -S Sort test files [boolean]
880-
--watch, -w Watch files in the current working directory
881-
for changes [boolean]
876+
--recursive Look for tests in subdirectories [boolean]
877+
--require, -r Require module [array] [default: (none)]
878+
--sort, -S Sort test files [boolean]
879+
--watch, -w Watch files in the current working directory for changes
880+
[boolean]
882881
883882
Test Filters
884883
--fgrep, -f Only run tests containing this string [string]
@@ -1095,7 +1094,7 @@ Files having this extension will be considered test files. Defaults to `js`.
10951094

10961095
Affects `--watch` behavior.
10971096

1098-
Specifying `--extension` will _remove_ `.js` as a test file extension; use `--extension js` to re-add it. For example, to load `.mjs` and `.js` test files, you must supply `--extension mjs --extension js`.
1097+
The option can be given multiple times. The option accepts a comma-delimited list: `--extension a,b` is equivalent to `--extension a --extension b`
10991098

11001099
### `--file <file|directory|glob>`
11011100

@@ -1107,6 +1106,8 @@ Files specified this way are not affected by `--sort` or `--recursive`.
11071106

11081107
Files specified in this way should contain one or more suites, tests or hooks. If this is not the case, consider `--require` instead.
11091108

1109+
### `--ignore <file|directory|glob>, --exclude <file|directory|glob>,`
1110+
11101111
### `--recursive`
11111112

11121113
When looking for test files, recurse into subdirectories.
@@ -1132,6 +1133,8 @@ Sort test files (by absolute path) using [Array.prototype.sort][mdn-array-sort].
11321133

11331134
### `--watch, -w`
11341135

1136+
Rerun tests on file changes.
1137+
11351138
Executes tests on changes to JavaScript in the current working directory (and once initially).
11361139

11371140
By default, only files with extension `.js` are watched. Use `--extension` to change this behavior.
@@ -1545,23 +1548,32 @@ mocha.setup({
15451548
ui: 'tdd'
15461549
});
15471550

1548-
// Use "tdd" interface, ignore leaks, and force all tests to be asynchronous
1551+
// Use "tdd" interface, check global leaks, and force all tests to be asynchronous
15491552
mocha.setup({
15501553
ui: 'tdd',
1551-
ignoreLeaks: true,
1554+
checkLeaks: true,
15521555
asyncOnly: true
15531556
});
15541557
```
15551558

15561559
### Browser-specific Option(s)
15571560

1558-
The following option(s) _only_ function in a browser context:
1561+
Browser Mocha supports many, but not all [cli options](#command-line-usage).
1562+
To use a [cli option](#command-line-usage) that contains a "-", please convert the option to camel-case, (eg. `check-leaks` to `checkLeaks`).
1563+
1564+
#### Options that differ slightly from [cli options](#command-line-usage):
1565+
1566+
`reporter` _{string|constructor}_
1567+
You can pass a reporter's name or a custom reporter's constructor. You can find **recommended** reporters for the browser [here](#reporting). It is possible to use [built-in reporters](#reporters) as well. Their employment in browsers is neither recommended nor supported, open the console to see the test results.
1568+
1569+
#### Options that _only_ function in browser context:
15591570

1560-
`noHighlighting`: If set to `true`, do not attempt to use syntax highlighting on output test code.
1571+
`noHighlighting` _{boolean}_
1572+
If set to `true`, do not attempt to use syntax highlighting on output test code.
15611573

15621574
### Reporting
15631575

1564-
The "HTML" reporter is what you see when running Mocha in the browser. It looks like this:
1576+
The "html" reporter is the default reporter when running Mocha in the browser. It looks like this:
15651577

15661578
![HTML test reporter](images/reporter-html.png?withoutEnlargement&resize=920,9999){:class="screenshot" lazyload="on"}
15671579

Diff for: lib/mocha.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ exports.Test = require('./test');
8383
* @param {boolean} [options.ignoreLeaks] - Ignore global leaks?
8484
* @param {boolean} [options.invert] - Invert test filter matches?
8585
* @param {boolean} [options.noHighlighting] - Disable syntax highlighting?
86-
* @param {string} [options.reporter] - Reporter name.
86+
* @param {string|constructor} [options.reporter] - Reporter name or constructor.
8787
* @param {Object} [options.reporterOption] - Reporter settings object.
8888
* @param {number} [options.retries] - Number of times to retry failed tests.
8989
* @param {number} [options.slow] - Slow threshold value.

0 commit comments

Comments
 (0)