Adding a check in onHookEnd to only call error function if it exists and is a function (fixes #482) #484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #485 where failed test cases in parallel mode are incorrectly reported as yellow/broken instead of red/failed.)