glenjamin / mocha-multi Goto Github PK
View Code? Open in Web Editor NEWA bit of a hack to get multiple reporters working with mocha
License: MIT License
A bit of a hack to get multiple reporters working with mocha
License: MIT License
Running mocha tests with latest mocha-multi reporter plugin leads to breaking change and failed run.
The following error is logged in the console and the run fails.
runner.stats = stats;
^ TypeError: Cannot set property stats of #<EventEmitter> which has only a getter
The error is not thrown in "mocha-multi": "1.1.0"
.
In the previous version of mocha (gulp-mocha 3.0.1) all was well with the universe and definitions for the mocha-multi reporter could be specified through the "reporterOptions" property sent into mocha. That now seems to be deprecated or something is seriously broken with the latest version of mocha (gulp-mocha 4.0.1). Here is the gulp script which includes my mocha call:
gulp.task('testServer:ci', ['build:server'], function (cb) {
log('Running Server unit tests...');
gulp.src(config.servercoveredfiles)
.pipe($.istanbul({includeUntested: true}))
.pipe($.istanbul.hookRequire())
.on('finish', function () {
var reporterOptions = {
xunit: config.ci + 'server-ut.xml',
spec: '-'
};
var stream = gulp.src(config.tests, {read: false})
// do the success/fail reporting on the unit tests
.pipe($.mocha({
ui: 'bdd',
reporter: 'mocha-multi',
reporterOptions: reporterOptions
}));
stream.on('error', function (err) {
// if the unit tests fail, report the error to the command
// line and don't do the CI reporting.
$.util.log($.util.colors.red(err));
log('Server Unit Tests Failed, exiting...');
cb();
});
// do the CI reporting for Code coverage
stream.pipe($.istanbul.writeReports({
dir: config.ccserver,
reporters: ['text-summary', 'html', 'cobertura']
}))
.on('end', function () {
log('Server Unit Tests Completed, exiting...');
cb();
});
});
});
Up until the most recent release of mocha, this worked fine. Now the following error is spewed, declaring that "reporter definitions should be set in the multi
shell variable". Here is the full error:
[17:14:20] Error in plugin 'gulp-mocha'
Message:
spawn undefined ENOENT
Details:
errno: ENOENT
code: ENOENT
syscall: spawn undefined
killed: false
stdout:
stderr: ERROR: reporter definitions should be set in the `multi` shell variable
eg. `multi='dot=- xunit=file.xml' mocha`
failed: true
signal: null
cmd: mocha C:\git\my-program\ServerSide\test\fileHandler.test.js C:\git\my-program\ServerSide\test\translateData.test.js --colors --ui=bdd --reporter=mocha-multi
timedOut: false
Seems like something fundamental has changed, or this reporter is now DOA.
Any help?
Need example:
mocha-multi depends on an old version of mkdirp and I see this log line in my yarn install:
➤ YN0061: │ mkdirp@npm:0.5.1 is deprecated: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
yarn why mkdirp
├─ mocha-multi@npm:1.1.5
│ └─ mkdirp@npm:0.5.5 (via npm:^0.5.1)
In the Mocha code there is the following bit of logic: https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L234
it allows customers to write local reporters and provide them to mocha. This feature is even used in this package in the verify script.
However it is not working in mocha-multi
mocha -R mocha-multi --reporter-options spec=-,./my-custom.js=out.txt
Apologies ahead of time if this is a mocha
issue, rather than an issue with mocha-multi
, but it appears the recent update to 1.1.4
is now breaking with a range of mocha
versions.
Dependencies:
"dependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"chai": "^4.2.0",
"jsdom": "^9.0",
"mocha": "5.2.0",
"mocha-jsdom": "~1.1.0",
"mocha-multi": "^1.0.1",
"sinon": "^7.3.1"
}
Error:
bal@Blakes-MacBook-Pro-2 phase-0-intro-to-js-2-looping-code-along % npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/mocha
npm ERR! mocha@"5.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer mocha@"2.2.0-7.0.0 || ^9.0.0" from [email protected]
npm ERR! node_modules/mocha-multi
npm ERR! mocha-multi@"^1.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/bal/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/bal/.npm/_logs/2021-09-30T15_00_58_403Z-debug.log
If you have a custom reporter like mochawesome which takes more than one option mocha-multi won't work since the options are separated by comma just like --reporter-options.
Example:
--reporter-options reportDir=customReportDir,reportName=customReportName
that's what mochawesome expects.
But passing that to mocha-multi would be something like:
--reporter-options spec=-,mochawesome=reportDir=customReportDir,reportName=customReportName
notice how reportName would become another reporter in this case.
mocha recently had a release, version 7.0.0.
The current mocha-multi library can't seem to take in the changes from this latest version.
In a branch of my fork for the mocha-multi repo, updated the mocha version to 7.0.0 to verify - HarshaNalluru@3b6d5a5
The tests seem to fail.
With npm run test
..
> [email protected] test <path>/mocha-multi
> run-s lint verify:*
> [email protected] lint <path>/mocha-multi
> eslint . --max-warnings 0
> [email protected] verify:node <path>/mocha-multi
> node ./verify.js
ERROR: reporter definitions should be set in the `multi` shell variable
eg. `multi='dot=- xunit=file.xml' mocha`
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] verify:node: `node ./verify.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] verify:node script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
@glenjamin any chance of a release?
Sorry I am a beginner to mocha. I am trying to generate two reporters for my tests using :
mocha --timeout 60000 -R mocha-multi --reporter-options dot=-,xunit=file.xml,doc=docs.html
I am getting following error in tests: stats.tests.
/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha/lib/reporters/xunit.js:94 tests: stats.tests, ^ TypeError: Cannot read property 'tests' of undefined at EventEmitter.<anonymous> (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha/lib/reporters/xunit.js:94:24) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:106:13) at EventEmitter.emit (events.js:208:7) at withReplacedStdout (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha-multi/mocha-multi.js:197:14) at withReplacedStdout (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha-multi/mocha-multi.js:159:12) at Runner.runner.on.eventArgs (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha-multi/mocha-multi.js:196:7) at emitNone (events.js:111:20) at Runner.emit (events.js:208:7) at Runner.uncaught (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha/lib/runner.js:868:8) at process.uncaught (/Users/example/.nvm/versions/node/v8.12.0/lib/node_modules/mocha/lib/runner.js:887:10) at emitOne (events.js:116:13) at process.emit (events.js:211:7) at process._fatalException (bootstrap_node.js:391:26) npm ERR! Test failed. See above for more details.
Is there any other packages that I should install to use mocha-multi?
Thank you
Will be more consistency with mocha.
Current version strictly requires mocha 1.15.1. Can it be updated to support newer versions?
Hello,
according to the releases page, the latest version is 1.1.0
. However, in NPM, the latest version is 1.0.1
.
Could you publish the latest version to NPM? Thanks
Latest Mocha version as of today - 8.3.2
Please bump up the compatibility - we have dependency checker breaking if using latest mocha, however using 7.x is suboptimal
I'm using latest node, mocha to run UI tests and mochaawesome for reporting. I would like to get output of mocha test command in console output and text file both. I have tried your mocha-multi too but it doesn't generate text file report.
For e.g.
mocha --recursive tests -f 'Smoke' --retries 1 -R mocha-multi --reporter-options list=-,text=file.txt
Test works fine but user can't see console output promptly if output is redirected and if i don't redirect then report text file is not created. mochawesome report doesn't create text file, default behavior is html file. I need both kind of output, any alternative using mochawesome report or any other solution to have this facility?
npm install mocha mochaawesome
mocha create-event.js -f Smoke > report.txt
mocha create-event.js -f Smoke
hey mate is possible to change this "mocha": ">=2.2.0 <5.0.0"
to support mocha 5
many thanks
I'm trying to use mocha-junit-reporter programmatically but it doesn't seem to work. My code below:
var reporterOptions = {
"mocha-junit-reporter": {
reporterOptions: {
mochaFile: "./test-reports/unit-test-report.xml"
}
},
spec: "-",
};
mocha({
reporter: "mocha-multi",
reporterOptions: reporterOptions
})
I upgraded to the latest package versions in my project and started to get this error when using mocha-multi.
I suspect it may be because of how mocha-multi fakes the stdout/tty.
/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:141
throw err;
^
TypeError: Object #<Object> has no method 'getWindowSize'
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/base.js:114:13)
Here is my fix. It is not particularly nice, but perhaps it helps someone. I add mocha --require ./fix-mocha.js --reporter mocha-multi ...
fix-mocha.js
var tty = require('tty');
if (!tty.getWindowSize){
tty.getWindowSize = function(){ return [80,75]; } ;
console.log("patched missing function in tty");
}
If case you're curious, tty has these properties:
[ 'isatty', 'setRawMode', 'ReadStream', 'WriteStream' ]
and the isatty returns
{ 'tty.isatty(1)': true, 'tty.isatty(2)': true }
It seems related to mochajs/mocha#36 - but that is such an old issue I wonder why it resurfaced.
Stack trace:
/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:141
throw err;
^
TypeError: Object #<Object> has no method 'getWindowSize'
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/base.js:114:13)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/reporters/index.js:2:16)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/lib/mocha.js:26:21)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/node_modules/mocha/index.js:4:5)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/lib/reporters/cobertura.js:6:15)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha-cobertura-reporter/index.js:2:18)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions..js (/home/tom/projects/some-project/node_modules/blanket/src/index.js:172:17)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at safeRequire (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:138:12)
at resolveReporter (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:127:16)
at /home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:114:22
at withReplacedStdout (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:216:5)
at /home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:113:5
at Array.map (native)
at initReportersAndStreams (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:104:16)
at new MochaMulti (/home/tom/projects/some-project/node_modules/mocha-multi/mocha-multi.js:39:17)
at Mocha.run (/home/tom/projects/some-project/node_modules/mocha/lib/mocha.js:345:18)
at Object.<anonymous> (/home/tom/projects/some-project/node_modules/mocha/bin/_mocha:351:7)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
mocha 2.1.0 added the capability for a Reporter to implement a done(fn)
method (commit), which if present would be invoked on completion and mocha would not exit until the fn
callback is invoked.
For an example, see the XUnit reporter:
/**
* Override done to close the stream (if it's a file).
*
* @param failures
* @param {Function} fn
*/
XUnit.prototype.done = function (failures, fn) {
if (this.fileStream) {
this.fileStream.end(function () {
fn(failures);
});
} else {
fn(failures);
}
};
It would be nice if mocha-multi would implement done
and then check if any of the provided reporters implement it and then tie the completion of fn
to when all the reporters complete their callback.
I can add this if you agree that this should be supported and would like me to give it a try, thanks!
Hi, I am trying to use two below two reporters and declare them into protractor.conf.js using 'mocha-multi'. I tried searching docs on how do that but in vain. I see most examples were around configurations from command line when running with mocha
I basically need to combine both these reports as I need both
Reporter 1:
mochaOpts: {
ui: 'bdd',
reporter: 'mochawesome-screenshots',
reporterOptions: {
reportDir: testResultsDir,
reportName: 'TestExecutionReport',
reportTitle: 'Sample Reports',
takePassedScreenshot: true,
clearOldScreenshots: true
}
}
Reporter 2:
mochaOpts: {
ui: 'bdd',
reporter: mochaReporter,
timeout: 20000,
reporterOptions: {
console: true,
storyDir: testCasesDir,
outputDir: testResultsDir
}
},
It looks like #13 added support for creating a directory for the reporter output, but it does not handle nested directories (mkdir
needs a -p
option).
Here's the stack trace I get when trying to create build/reports/xml/mocha-results.xml
when only build
exists.
fs.js:842
return binding.mkdir(pathModule._makeLong(path),
^
Error: ENOENT: no such file or directory, mkdir 'build/reports/xml'
at Error (native)
at Object.fs.mkdirSync (fs.js:842:18)
at resolveStream (/Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha-multi/mocha-multi.js:145:8)
at /Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha-multi/mocha-multi.js:78:18
at Array.map (native)
at initReportersAndStreams (/Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha-multi/mocha-multi.js:73:16)
at new MochaMulti (/Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha-multi/mocha-multi.js:29:17)
at Mocha.run (/Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha/lib/mocha.js:474:18)
at Object.<anonymous> (/Users/ianvs/code/nutshell/nutshell-client/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3
I see you released 0.9.0, but I think you forgot to publish it to npm!
Also, minorly, your npm badge in the readme reports the right version from npm, but it links to the skin-deep
package instead of mocha-multi
.
All the information to reproduce this issue is available here.
Noticed v1.0.1 is tagged here, but not released to npm.
Given a simple setup:
multi="progress=-" mocha --reporter mocha-multi
Always return zero exit code, even tests has been failed. Library versions:
"mocha": "2.3.2",
"mocha-multi": "0.7.1",
I guess it happens because mochajs/mocha#1059 already merged and some hacks doesn't necessary anymore. I could remove them by myself, but I am not sure, which parts of hacks actually still needed.
All the information to reproduce this issue is available here.
Running my tests with
mochaOptions: ['--reporter-options', 'spec=-,mocha-bamboo-reporter=./test/mocha-bamboo-reporter.json,doc=./test/docs.html,mocha-junit-reporter=./test/mocha-junit-reporter.xml'],
I get the spec
output, the docs.html
file gets generated with the correct report, but the files mocha-junit-reporter.xml
and mocha-bamboo-reporter.json
are empty.
Tried to run with only mochaOptions: ['--reporter-options', 'spec=-,mocha-bamboo-reporter=./test/mocha-bamboo-reporter.json'],
with the same results.
Is there a way to have all 4 outputs?
I get the following error when trying to install mocha-multi 1.16 with mocha 10.0.0
Could not resolve dependency: npm WARN peer mocha@">=2.2.0 <7 || ^9" from [email protected] npm WARN node_modules/mocha-multi
Just want to know if you are aware of this issue, I haven't found out how to resolve this, here are my devdependencies
"devDependencies": { "chai": "^4.3.6", "eslint": "^8.21.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-es5": "^1.2.0", "eslint-config-es5": "^0.5.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-react": "^7.30.1", "mocha": "^10.0.0", "pkg": "^5.8.0" }
Thanks a lot,
Is there any reason to not bump this to 1.0.0? Whenever a nodeJS package is below 1.0.0 it doesn't provide much semantic information other than anything goes and anything can break on upgrade.
More importantly, when a new release is made and I use this as in "mocha-multi": "^0.9.1"
in several modules (I maintain around about a dozen with this module) the carrot will not update my package automatically since this is a pre-release. I have to go in by hand and upgrade all as well as read release notes to see if I am going to be broken or not.
A 1.0.0
release and semantic versioning after that would help out a lot.
It would be nice if mocha-multi's releases could tell what's new.
After installing, a lot of dependency issues.
npm WARN deprecated [email protected]: TSD is deprecated in favor of Typings (https://github.com/typings/typings) - see DefinitelyTyped/tsd#269 for more information
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN deprecated [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Use uuid module instead
Now that mochajs/mocha#1059 is released the process.exit hack could be tidier
I'm trying to drive reporter options programmatically through grunt.
This works fine:
var mochaMultiReporterOptions = {
xunit: {
stdout: 'build-artifacts/reporters/results.xml'
},
json: {
stdout: 'build-artifacts/reporters/json-reporter.json'
}
};
But when I try to direct something to console I get a protractor error. The code:
var mochaMultiReporterOptions = {
xunit: {
stdout: 'build-artifacts/reporters/results.xml'
},
json: {
stdout: 'build-artifacts/reporters/json-reporter.json'
},
spec: '-'
};
The error:
"Error: more than one config file specified"
Versions:
"grunt-protractor-runner": "~2.0",
"grunt-protractor-webdriver": "~0.2",
"mocha": "~2.4",
"mocha-multi": "^0.9.0",
"protractor": "~2.5",
Mocha options:
{
ui: 'bdd',
reporter: 'mocha-multi',
timeout: '540000',
reporterOptions: mochaMultiReporterOptions
};
Any ideas?
Other things I have tried:
stdout: '-'
as an option for spec
Currently here is an issue with mocha 6 (6.0.2): on tests completion process never stops. Even the only reporter (for example, spec
) causes process forever freezing.
I run tests with grunt. My node version is 10.15.1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.