Cannot destructure property resultsDir of opts.reporterOptions
See original GitHub issueDescribe the bug Not able to run mocha with the reporter, even for very basic tests.
To Reproduce Steps to reproduce the behavior:
Create two files with the following contents:
test/test.spec.js:
const expect = require('chai').expect;
describe('Simple tests', () => {
it('should pass', () => {
expect(true).to.equal(true);
});
it('should fail', () => {
expect(true).to.equal(false);
});
});
package.json:
{
"name": "allure-js-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test/**.spec.js --reporter allure-mocha"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"allure-mocha": "^2.0.0-beta.15",
"chai": "^4.3.6",
"mocha": "^9.2.2"
}
}
To replicate, first run npm install
and then run npm test
. You’ll see the following error:
> allure-js-example@1.0.0 test /Users/dev/allure-js-example
> mocha test/**.spec.js --reporter allure-mocha
TypeError: Cannot destructure property 'resultsDir' of 'opts.reporterOptions' as it is undefined.
at new MochaAllureReporter (/Users/dev/allure-js-example/node_modules/allure-mocha/dist/MochaAllureReporter.js:31:17)
at Mocha.run (/Users/dev/allure-js-example/node_modules/mocha/lib/mocha.js:1027:18)
at singleRun (/Users/dev/allure-js-example/node_modules/mocha/lib/cli/run-helpers.js:126:16)
at async Object.exports.handler (/Users/dev/allure-js-example/node_modules/mocha/lib/cli/run.js:374:5)
npm ERR! Test failed. See above for more details.
Expected behavior
I have not included any allure functionality in the tests yet. I’m simply trying to run the tests, but with --reporter allure-mocha
it is as if some option is required somewhere that isn’t being set. I looked in mocha-allure2-example and found a reporterConfig.json file, and I can run those TypeScript tests, but it’s not clear to me how to get it working with a simple Node.js JavaScript project. Here is the file from the example:
cat reporterConfig.json
{
"reporterEnabled": "allure-mocha, list",
"allureMochaReporterOptions": {
"resultsDir": "./allure-results"
}
}
But even if I include it, I still get the same error. What am I missing?
Desktop (please complete the following information):
- OS: Mac M1
- Browser: N/A
- Version: Node.js v14.17.5 and v16.10.0
Additional context
I opened up a ticket https://github.com/allure-framework/allure-docs/issues/158 regarding a request for more documentation on allure-mocha. The documentation on https://docs.qameta.io/allure/#_mocha is still pointing to the deprecated mocha-allure-reporter package last updated in 2018.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
I can confirm now that the workaround works. The only difference is that I already had a
.mocharc.js
file, so I added the mocharc.json to the exports in the JS file, like so:.mocharc.js:
and then the code to run the test is like this:
I also had to make sure the reporterConfig.json was still in the root, as mentioned in previous comments:
Thank you again!
I believe it’s not yet published. But you can try the above suggestion.