adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

Unknown "reporter": mochawesome #281

Open Soumak1311 opened 5 years ago

Soumak1311 commented 5 years ago

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):

adamgruber commented 5 years ago

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?

Soumak1311 commented 5 years ago

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

oliversalzburg commented 5 years ago

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

ArcaneDiver commented 5 years ago

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
});
iqianxing commented 4 years ago

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 commented 4 years ago

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.

mbwhite commented 3 years ago

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.

KSVarun commented 2 years ago

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.

adamgruber commented 2 years ago

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