Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allure-mocha: Cannot run example from docs since allure-runtime gives an undefined property #509

Open
jamesmortensen opened this issue Oct 28, 2022 · 4 comments
Assignees
Labels
theme:mocha Mocha related issue type:bug Something isn't working

Comments

@jamesmortensen
Copy link

Describe the bug

When attempting to use the simple example from the readme, we discovered that the allure variable is undefined, so we cannot call any of the "extra information" methods, such as steps and attachments.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the following small repro example:
$ git clone https://github.com/jamesmortensen/allure-js-runtime-issue.git
  1. Run the tests with npm test
  2. Observe the error that allure is undefined.

Expected behavior

According to the documentation, if we want to add extra information to the report, we can import allure/runtime and then use methods, such as allure.epic, story, description, etc. We expect the tests to complete, with one passing and one failing and for the extra information to appear in the report.

Desktop (please complete the following information):

  • OS: macOS 12.4 ARM64
  • Browser N/A
  • Version N/A

We are running Node.js v16.17 and allure-mocha 2.0.0-beta.19

Additional context

See the Usage section of the docs to see the instructions.

Stacktrace:

TypeError: Cannot read properties of undefined (reading 'epic')
      at Context.<anonymous> (test/example.spec.js:21:16)
      at processImmediate (node:internal/timers:466:21)
      at process.callbackTrampoline (node:internal/async_hooks:130:17)
@epszaw
Copy link
Member

epszaw commented Oct 28, 2022

Thank you for the issue. It's strongly relates to #486 and depends on mochajs/mocha#4922

@epszaw epszaw self-assigned this Oct 28, 2022
@epszaw epszaw added type:bug Something isn't working theme:mocha Mocha related issue labels Oct 28, 2022
@jamesmortensen
Copy link
Author

Actually, my colleague dug into this pretty heavily today, and she got it working!

We discovered two causes. First, she discovered that the way the docs said to require the runtime was incorrect. Instead of:

const { allure } = require("allure-mocha/runtime");

She did this:

const runtime = require("allure-mocha/runtime");

Then we could do runtime.allure.epic('This is epic!');

We also discovered that it is because Mocha, or perhaps allure, wasn't able to handle both the default spec reporter and the allure-mocha reporter together. If we removed the spec reporter, then the runtime is defined. But with both, runtime.allure was undefined.

We used the mocha-multi-reporter module to configure both reporters together. If you need more details on this please let me know. I do think it is worth updating the docs with this information, as it may help others.

@epszaw
Copy link
Member

epszaw commented Oct 28, 2022

It depends on version of the packages.
The latest one doesn't work properly because at the same moment we can have multiple tests (in parallel mode) and any label assignment by the runtime can add label to a wrong test or suite.

@jamesmortensen
Copy link
Author

@epszaw if it helps, we are on the latest everything:

  • Mocha 10.1.0
  • allure-mocha: 2.0.0-beta.19
  • Node 16.17

We do run tests in parallel, but we use a variation of a script shared by an allure collaborator: #245 (comment). The script splits up all of the spec files and runs them as separate, independent mocha processes. So we don't run into any of these issues when running in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:mocha Mocha related issue type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants