allure-js icon indicating copy to clipboard operation
allure-js copied to clipboard

Uncaught TypeError: hook.error is not a function MochaAllureReporter

Open darkallure opened this issue 3 years ago • 7 comments

Describe the bug Getting an error when parallel mode is on while using Mocha

To Reproduce Steps to reproduce the behavior:

  1. Set parallel mode to true in mocha.rc config or use "--parallel" flag
  2. Run the tests
  3. Tests fail due to the following error: Uncaught TypeError: hook.error is not a function

Expected behavior The tests should run successfully in parallel mode with Mocha allure reporter Screenshots image image

Additional context the following version packages are used: "allure-mocha": "^2.0.0-beta.19", "mocha": "^9.2.1"

darkallure avatar Aug 19 '22 06:08 darkallure

@darkallure if you patch MochaAllureReporter on line 70 with this block of code, do you still get the error? This resolved the issue for me, and I've opened a pull request to get the changes reviewed and merged:

node_modules/allure-mocha/dist/MochaAllureReporter.js line 70:

 onHookEnd(hook) {
        console.log('inside onHookEnd...');
        if(typeof hook.error === 'function')
            this.coreReporter.endHook(hook.error());
        else
            this.coreReporter.endHook();
    }

jamesmortensen avatar Aug 20 '22 09:08 jamesmortensen

@jamesmortensen thank you so much! It did fixed the issue but the other issue started to occur, do you know how to fix this? image image

darkallure avatar Aug 20 '22 12:08 darkallure

@darkallure Not sure if that's related to this change or if it's another issue altogether which needs to be reported. It does seem like the v2.0.0 platform is still missing many of the 1.0 features, so my guess is new issue. If you check the source code, do you see any implementation for label?

jamesmortensen avatar Aug 22 '22 06:08 jamesmortensen

@jamesmortensen Yes, I do see it: image The issue is not only with label but all the other properties as well: allure.suite, allure.description etc.

darkallure avatar Aug 22 '22 07:08 darkallure

Can you try using the JavaScript Debug Terminal in VSCode to step through code in order to see what's missing? My guess is something is going on in the "model" that's being required.

jamesmortensen avatar Aug 22 '22 15:08 jamesmortensen

@jamesmortensen it cannot even pass this line: image Do you have any other suggestions on what can be done to fix it or some kind of a workaround?

darkallure avatar Aug 24 '22 19:08 darkallure

I'm not yet sure what runtime is supposed to be or where it comes from. It's supposed to be passed into the Allure constructor. I'm thinking it must be related to Mocha or Jest or Jasmine or whatever the runner is that's being used, but I'm not sure. Hopefully one of the maintainers of the project can jump in and give some insight.

jamesmortensen avatar Aug 25 '22 08:08 jamesmortensen

Fixed in 2.0.0.beta-20 via #510. Remains fixed in 3.0.0-beta.3, which uses a different approach to the parallel mode.

delatrie avatar Jun 26 '24 11:06 delatrie