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

When mocha runs in parallel mode, the failed test cases appear yellow instead of red #485

Open
jamesmortensen opened this issue Aug 20, 2022 · 3 comments
Labels
theme:mocha Mocha related issue

Comments

@jamesmortensen
Copy link

Describe the bug

When we run tests, any test which fails due to an AssertionError is reported in Allure in red, as a failing test. Any other thrown Error is reported as a broken test, in yellow.

While this functionality works as expected in sequential mode, failed tests are reported as broken tests (in yellow) when run in parallel.

To Reproduce
Steps to reproduce the behavior:

  1. Clone this repo: https://github.com/jamesmortensen/allure-js-reporter-issues#when-run-in-parallel-mode-with-hooks-hookerror-is-not-a-function and follow the instructions to run the tests and generate the report.

The example has us run tests in sequential mode as well as parallel mode. The README also has screenshots which show the issue.

Expected behavior

  • For AssertionErrors, results should appear in the report in RED. In parallel mode, they're reported in YELLOW.

Screenshots

Environment (please complete the following information):

| Test framework | mocha@10.0.0 | chai@4.3.6
| Allure adaptor | allure-mocha@2.0.0-beta.19 | mocha-multi-reporters@1.5.1
| Generate report using | allure-commandline@2.18.1 |

Additional context

Desktop (please complete the following information):

  • OS: macOS 12.x
  • Browser [Chrome, Yandex]
  • Version [latest]
@MASQA
Copy link

MASQA commented Dec 19, 2022

@jamesmortensen , could you share structure your framework and runner?
I`m interested you use data annotation or no, write some custom runner such as from here #245 (comment) or use this runner https://github.com/allure-framework/allure-js/blob/master/packages/allure-mocha/test/runner.ts ?
I ask because as I see you actively use framework with parallel mode, but when I execute test runs, all my test run in sequentially.
I dont understand where I am wrong
I use so config for runner

const mocha = new Mocha({
  timeout: 16000,
  reporter: "mocha-multi-reporters",
  reporterOptions: {
    reporterEnabled: "allure-mocha",
    parallel: true,
    jobs: 4,
    allureMochaReporterOptions: {
      resultsDir: path.resolve(__dirname, "./../allure-results"),
    },
  },
});

I have tried some combinations of runs with different values jobs, with and without data annotation and always parallel mode is not work

@vovsemenv vovsemenv added the theme:mocha Mocha related issue label Feb 9, 2023
@jamesmortensen
Copy link
Author

Hi @MASQA sorry for taking so long to get back to you. Because for the longest time Allure wouldn't work with mocha in parallel mode using mocha's parallel feature, we used the script referenced in #245 (comment):

npx mocha parallel-launcher.js

This spawns several mocha processes to run in parallel but without using mocha's parallelism features. We still use this methodology in some tests we run daily.

The issue I'm reporting here is that the allure report shows tests in yellow instead of red with mocha's default parallelism feature:

npx mocha -p test/**.test.js

We don't use any annotations. It's a JavaScript project.

I'll also say we're not running mocha programmatically. Because our tests are written in ESM, Mocha can't load reporters because it tries to "require" them, but it needs to "import" them. Instead, the wrapper script deals with this by using the execa module to spawn mocha processes from the shell:

testFiles.map(testFile =>
            limit(async () => {
                const subProcess = execa('mocha', [testFile]);

In short, we achieve parallelism using the script referenced #245 (comment). Hope this helps!

@jamesmortensen
Copy link
Author

jamesmortensen commented Jul 10, 2023

I opened a pull request in mocha to fix the inconsistent reporting of failures in Allure. If they don't accept the change, then the next step is to hack the error type from the error stack trace, in the allure-mocha codebase, and add that to the deserialized error object. See the linked pull request for details. mochajs/mocha#4995

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

No branches or pull requests

3 participants