mochawesome icon indicating copy to clipboard operation
mochawesome copied to clipboard

Context information is lost in final report when running in mocha parallel mode

Open aubertaa opened this issue 3 years ago • 10 comments

Describe the bug Using addContext has no effect in final report when running tests in parallel using mocha 'parallel' mode

Code Reproduce run test in parallel mode with code to add context in report file. For instance :

const addContext = require("mochawesome/addContext")
...
describe("My testsuite", function () {

            beforeEach(function () {
                addContext(this, "this is a contextual info");
            });

            it("my test", function (done) {
                expect(true).to.be.true;
            });

});

Expected behavior Context should be added in testcase when expanding test in HTML report, this works well when we run tests not in parallel mode (--parallel)

aubertaa avatar Dec 04 '20 16:12 aubertaa

Have the same issue!

olexandr13 avatar Dec 11 '20 13:12 olexandr13

Try running Mocha with --require mochawesome/register.

JakobsenA-ELS avatar Dec 16 '20 14:12 JakobsenA-ELS

I can confirm that using require("mochawesome/register"); inside .test.js file is solving the problem. It would be really nice if it worked without that tho...

GoldStrikeArch avatar Dec 18 '20 17:12 GoldStrikeArch

--require mochawesome/register

It helps. Thanks, man!

olexandr13 avatar Dec 24 '20 11:12 olexandr13

You're amazing, guys)

Serg-develop avatar Mar 19 '21 12:03 Serg-develop

You do not need to use require("mochawesome/register"); in the all tests. There is a simpler way to make it happen:

mocha -r mochawesome/register

kolbasik avatar Sep 10 '21 12:09 kolbasik

It's not working for me :(

Here's the run with --parallel flag - hooks are not logging the context

image

And here's the one without - hooks are logging the context this time

image

Is there something else I need to do particularly for typescript ?

joo920131 avatar Dec 03 '21 00:12 joo920131

Hi @joo920131,

I have restored your example in a demo project but I could not reproduce the issue of not attaching context in parallel mode.

mochawesome-issue-339.zip

Could you please provide the code to reproduce? Thanks.

kolbasik avatar Dec 10 '21 16:12 kolbasik

the above commandline requirement worked for me thanks! might be worth adding to the docs

sshaar08 avatar Aug 12 '22 14:08 sshaar08

PRs welcome

adamgruber avatar Aug 13 '22 03:08 adamgruber