A bit of a hack to get multiple reporters working with mocha
Installations
npm install mocha-multi
Releases
Unable to fetch releases
Developer
glenjamin
Developer Guide
Module System
CommonJS
Min. Node Version
>=6.0.0
Typescript Support
No
Node Version
18.8.0
NPM Version
8.18.0
Statistics
76 Stars
200 Commits
22 Forks
7 Watching
13 Branches
15 Contributors
Updated on 07 Nov 2023
Languages
JavaScript (71.62%)
Shell (28.38%)
Total Downloads
Cumulative downloads
Total Downloads
25,330,170
Last day
-6.9%
18,120
Compared to previous day
Last week
4.9%
92,663
Compared to previous week
Last month
4.8%
376,748
Compared to previous month
Last year
9.8%
4,484,731
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
5
Peer Dependencies
1
mocha-multi
A bit of a hack to get multiple reporters working with mocha
Usage
npm install mocha-multi --save-dev
mocha --reporter mocha-multi
Choosing Reporters
For both methods below, the special value of -
(hyphen) for destination uses normal stdout/stderr.
With the multi
Environment Variable
Set the environment variable multi
to whitespace-separated type=destination pairs.
1multi='dot=- xunit=file.xml doc=docs.html' mocha -R mocha-multi
With --reporter-options
Pass --reporter-options
with comma-separated type=destination pairs.
1mocha -R mocha-multi --reporter-options dot=-,xunit=file.xml,doc=docs.html
From a file
Using either of the above methods, include a type=destination pair where the type is mocha-multi and the destination is a filename, e.g. mocha-multi=mocha-multi-reporters.json
More reporters will be loaded from the named file, which must be valid JSON in the same data format described below for passing reporterOptions to Mocha programmatically.
Using mocha-multi programmatically
You may specify the desired reporters (and their options) by passing reporterOptions
to the Mocha contructor.
For example: the following config is the equivalent of setting multi='spec=- Progress=/tmp/mocha-multi.Progress.out'
, with the addition of passing the verbose: true
option to the Progress reporter.
1var reporterOptions = { 2 Progress: { 3 stdout: "/tmp/mocha-multi.Progress.out", 4 options: { 5 verbose: true 6 } 7 }, 8 spec: "-" 9}; 10 11var mocha = new Mocha({ 12 ui: "bdd" 13 reporter: "mocha-multi", 14 reporterOptions: reporterOptions 15}); 16mocha.addFile("test/dummy-spec.js"); 17mocha.run(function onRun(failures){ 18 console.log(failures); 19});
The options will be passed as the second argument to the reporter constructor.
How it works
A big hack that keeps changing the value of process.stdout and process.stderr whenever a reporter is doing its thing.
Seriously?
Yeah, Sorry!
All the hacks
This is very hacky, specifically:
- The
process
andconsole
objects get their internal state messed with process.exit
is hacked to wait for streams to finish writing- Only works if reporters queue writes synchronously in event handlers
Could this be a bit less hacky?
-
Now that https://github.com/mochajs/mocha/pull/1059 is released the process.exit hack could maybe be tidier
-
Having each reporter run in a child process would make it eaiser to capture their streams, but might lead to other issues
TODO
- Add tests for coverage reports
- Add tests which produce multiple reports at once
- Add test for help text
- Add test that uses --no-exit
HISTORY
1.0.0 (unreleased)
The breaking changes are mostly around internals, and shouldn't affect most people.
- BREAKING: MochaMulti.prototype.done removed, new MochaMulti(...).done now optional
- BREAKING: new MochaMulti(...).options removed
- BREAKING: Must run at least mocha@>=2.2.0
- BREAKING: Must run at least node@>=6.0.0
- Correctly set exit code when writing to files
- Declare support for mocha@^4.0.0
- Support running mocha without a run callback
- Upgrade to ES2015+ via eslint-preset-airbnb-base (MochaMulti is an ES class)
- Avoid patching stderr, now that mocha does not write to it
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/18 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 19 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
Score
2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More