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

Adding a check in onHookEnd to only call error function if it exists and is a function (fixes #482)

Open jamesmortensen opened this issue 2 years ago • 0 comments

Context

Checklist

Fixes #482

The issue here is that, when running mocha in parallel mode with beforeEach or afterEach hooks, the onEndHook is called in MochaAllureReporter and the error() method is undefined.

Not sure about any unit tests for this. The project unit tests weren't passing before I made changes, so it's difficult to work with broken tests. Instead, I have a reproduceable example here: https://github.com/jamesmortensen/allure-js-reporter-issues#when-run-in-parallel-mode-with-hooks-hookerror-is-not-a-function

In the reproduceable example, run npx mocha -p test-with-hooks.js without the changes, to see the error occur, and run it with the changes to see the reporter function without errors and somewhat correctly. (By somewhat correctly, there is this related issue https://github.com/allure-framework/allure-js/issues/485 where failed test cases in parallel mode are incorrectly reported as yellow/broken instead of red/failed.)

jamesmortensen avatar Aug 20 '22 09:08 jamesmortensen