I have a file named test/helper.js
that I use to run Mocha tests on my Node.js apps. My tests structure looks like:
test/
test/helper.js # global before/after
test/api/sometest.spec.js
test/models/somemodel.spec.js
... more here
The file helper.js
has to be loaded because it contains global hooks for my test suite. When I run Mocha to execute the whole test suite like this:
mocha --recursive test/
the helper.js
file is loaded before my tests and my before
hook gets executed as expected.
However, when I run just one specific test, helper.js
is not loaded before the test. This is how I run it:
mocha test/api/sometest.spec.js
No global before
called, not even a console.log('I WAS HERE');
.
So how can I get Mocha to always load my helper.js
file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…