mochawesome icon indicating copy to clipboard operation
mochawesome copied to clipboard

Unknown "reporter": mochawesome

Open Soumak1311 opened this issue 5 years ago • 9 comments

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

Soumak1311 avatar May 12 '19 05:05 Soumak1311

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?

adamgruber avatar May 12 '19 12:05 adamgruber

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" } }

Soumak1311 avatar May 12 '19 16:05 Soumak1311

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

oliversalzburg avatar Jun 05 '19 17:06 oliversalzburg

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
});

ArcaneDiver avatar Aug 01 '19 11:08 ArcaneDiver

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

use npx command instead.

npx mocha --reporter mochawesome

iqianxing avatar Dec 28 '19 12:12 iqianxing

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.

iqianxing avatar Dec 28 '19 12:12 iqianxing

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.

mbwhite avatar Mar 11 '21 10:03 mbwhite

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 avatar Feb 23 '22 07:02 KSVarun

@KSVarun Can you provide some more detail or an example setup? I am not able to reproduce the issue as you describe.

adamgruber avatar Feb 23 '22 14:02 adamgruber