Webstorm has great test running support, which I can use to start my test suite by telling it "run the file testStart.js". I can then define testStart.js
to do the setup for my test environment (eg. creating a Sinon sandbox) and to bring in all the tests themselves.
That works great, when I run the whole suite. But Webstorm has a feature that let's you re-run just a single failing test, and when I try to use that feature I run in to a problem: my test setup code doesn't get run because the individual test file doesn't invoke the setup code.
So, I'm looking for a solution. The only options I see so far are:
instead of having a separate
testStart.js
file I could move the setup code in to atestSetup.js
file and make every test require it. DOWNSIDE: I have to remember to import the setup file in every single test file (vs. never having to import it in my current scheme)use Mocha's
--require
option to run atestSetup.js
. DOWNSIDE: Code require-ed in this way doesn't have access to the Mocha code, so I'm not sure how I can callbeforeEach
/afterEach
use some other Mocha or Webstorm option that I don't know about to run the test setup code. DOWNSIDE: Not sure if such an option even exists
If anyone else has run in to this problem I'd love to hear if any of the above solutions can be made to work (or if there's another solution I hadn't considered).