mochawesome
mochawesome copied to clipboard
Unknown "reporter": mochawesome
Describe the bug While running test using mochawesome, it throws error saying {reporter mochawesome not found}.
Expected behavior
I have install mochawesome in the workspace using npm install mochawesome --save-dev
and its also visible in my package.json, for this scenario it does not work. However, when i install mochawesome globally it worked fine.
Environment (please complete the following information):
- MacOS
- mochawesome version - 3.1.2
- mocha (or other test library) version - 6.1.4
- Node version - 8.9.4
Possibly a permissions issue? Can you consistently reproduce this? I installed those versions in a clean workspace and it works. What is the script you use to run your tests?
I used the following command to run test mocha --reporter mochawesome
. Attaching bellow my package.json
{ "name": "hello-world", "version": "1.0.0", "description": "Node hello world", "main": "app.js", "scripts": { "test": "mocha", "start": "node app.js" }, "keywords": [ "soumak" ], "author": "schongder", "license": "ISC", "dependencies": { "express": "^4.16.4" }, "devDependencies": { "chai": "^4.2.0", "mocha": "^6.1.4", "mochawesome": "^3.1.2", "mochawesome-report-generator": "^3.1.5", "request": "^2.88.0" } }
You can try to supply the path explicitly --reporter=./node_modules/mochawesome
. I had the same issue, because my package manager uses symlinks to construct the node_modules
directory so require()
can not find mochawesome
without a proper path.
Might also apply to #274
I had the same issues you have to run it programmatically. It's easy.
const Mocha = require('mocha'),
fs = require('fs'),
path = require('path');
// Instantiate a Mocha instance.
const mocha = new Mocha({
reporter: 'mochawesome',
reporterOptions: {
reportDir: 'report',
reportFilename: 'index',
quiet: true
},
timeout: 5000
});
// Folder where your test is
const testDir = '__test__';
// Add each .js file to the mocha instance
fs.readdirSync(testDir).filter(function(file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function(file) {
mocha.addFile(
path.join(testDir, file)
);
});
// Run the tests.
mocha.run(function(failures) {
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
});
You can try to supply the path explicitly
--reporter=./node_modules/mochawesome
. I had the same issue, because my package manager uses symlinks to construct thenode_modules
directory sorequire()
can not findmochawesome
without a proper path.Might also apply to #274
use npx command instead.
npx mocha --reporter mochawesome
Possibly a permissions issue? Can you consistently reproduce this? I installed those versions in a clean workspace and it works. What is the script you use to run your tests?
I read npx command docs, and try npx command: npx mocha --reporter mochawesome
.
npx mocha can avoid this problem.
FYI - I had the same issue - however the problem wasn't that the reporter module couldn't be found, but that it's dependencies couldn't be loaded.
This is happening when a mochawesome.json file is already present in the directory where you are running the tests. Deleting that json will solve the issue.
@KSVarun Can you provide some more detail or an example setup? I am not able to reproduce the issue as you describe.