You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
4.x: junitReporter still doesn't record helper _beforeSuite()/_afterSuite() failures (follow-up to #5645) #5660
That fix listens on event.hook.failed, which is only emitted by fireHook() in lib/mocha/asyncWrapper.js, and fireHook() is only called from the injected() wrapper used for the test-file-defined BeforeSuite() / AfterSuite() / Before() / After() functions (registered in lib/mocha/ui.js).
A custom helper's_beforeSuite() / _afterSuite() lifecycle methods run through a different mocha hook — suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite)) (lib/mocha/ui.js:106), which calls runAsyncHelpersHook('_beforeSuite', ...) (lib/listener/helpers.js:32). Looking at suiteSetup() / suiteTeardown() in asyncWrapper.js, on failure they call doneFn(err) directly and never call fireHook() — so event.hook.failed is never emitted for helper lifecycle failures, and junitReporter still produces an empty/incomplete report for these.
Repro
// steps_file.ts / a custom helperimportHelperfrom"@codeceptjs/helper";classMyHelperextendsHelper{async_beforeSuite(){thrownewError("Simulated error in helper _beforeSuite");}}export=MyHelper;
// My_test.tsFeature("My");Scenario("test something",({ I })=>{I.amOnPage("https://example.com");});
Same empty-report symptom as #5645, just triggered from a helper's lifecycle hook instead of the test file's BeforeSuite().
Suggested fix
We worked around it by listening on Mocha's own runner.on('fail', ...) event instead of (or in addition to) event.hook.failed. runner.on('fail') fires for every suite-level hook failure regardless of origin (test-file hooks and helper lifecycle hooks alike), so a single title-based filter (/^"(before all|after all)" hook:/) covers both cases without duplicating the entries already covered by event.hook.failed. Happy to share the patch we're running if useful for a PR.
Activity
fix(hooks): emit hook.failed when a helper suite hook throws (codecep…