🐛 Bug: mocha should reload --require'd root hook modules on watch reruns #5352
Labels
status: in triage
a maintainer should (re-)triage (review) this issue
type: bug
a defect, confirmed by a maintainer
Uh oh!
There was an error while loading. Please reload this page.
Bug Report Checklist
faq
label, but none matched my issue.Expected
I'm building a chai plugin to do snapshot testing; it needs to get the Mocha
currentTest
somehow; it seems like a root hooks module is the only way.This works for the first test run, but in watch mode reruns a new instance of the hooks module is getting loaded by tests requiring it, whereas Mocha calls the hooks on the first instance of the hooks module. I expected Mocha to also reload the hooks module so that it is the same module instance as the tests see in every rerun.
In general it seems like there's no clean way to make a chai plugin access the current test where I don't have to manually pass it in from each test suite?
What I expected when running the code below is for the initial run and subsequent reruns to each output a matching hook module and defined test file like so:
Actual
Minimal, Reproducible Example
package.json
test/hook.js
test/setup.js
test/test.js
Versions
Mocha 11.2.2
Node 20.10.0
Additional Info
Right now the unsatisfying workaround is to set
globalThis._currentTest = this.currentTest
in my root hook.The text was updated successfully, but these errors were encountered: