question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot destructure property resultsDir of opts.reporterOptions

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesmortensencommented, May 31, 2022

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:

/*
Other setup I was doing is here...
*/
module.exports = {
  "spec": "./test/**/*.spec.js",
  "reporter": "mocha-multi-reporters",
  "reporter-option": "configFile=reporterConfig.json"
}

and then the code to run the test is like this:

$ npx mocha --config .mocharc.js tests/*.spec.mjs

I also had to make sure the reporterConfig.json was still in the root, as mentioned in previous comments:

cat reporterConfig.json 
{
  "reporterEnabled": "allure-mocha, list",
  "allureMochaReporterOptions": {
    "resultsDir": "./allure-results"
  }
}

Thank you again!

0reactions
sskorolcommented, May 13, 2022

I believe it’s not yet published. But you can try the above suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue test utils TypeError: Cannot destructure property `config ...
I was getting the following error and that did it for me: Cannot destructure property 'config' of 'undefined' as it is undefined.
Read more >
Next.js error: Cannot destructure property? : r/learnjavascript
I am following a tutorial and I cannot figure out why Next keeps throwing this error: TypeError: Cannot destructure property 'loginUser' of ...
Read more >
mochawesome - npm
A gorgeous reporter for Mocha.js. Latest version: 7.1.3, last published: 9 months ago. Start using mochawesome in your project by running ...
Read more >
Profile for GitHub - Linknovate
Or are there missing methods or properties that you need to implement your idea? ... resultsDir) const finalResultsFile = options.resultsFile ? options.
Read more >
TypeError: Cannot destructure property 'events' of 'e' as it is null
Hello, I'm new to Flow and I'm trying to write a very simple test. But when I try to use const Alice =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found