0

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 a testSetup.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 a testSetup.js. DOWNSIDE: Code require-ed in this way doesn't have access to the Mocha code, so I'm not sure how I can call beforeEach/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).

machineghost
  • 33,529
  • 30
  • 159
  • 234

1 Answers1

0

I wound up just importing testSetup.js in to every test file. It was a pain and violated the DRY principle, but it worked.

If anyone else has a better solution though I'll happily accept it.

machineghost
  • 33,529
  • 30
  • 159
  • 234
  • Regarding better solutions, your question is 90% duplicate of questions already asked about this very problem. The only difference is that the questions asked previously did not have Webstorm as a factor. See [this](http://stackoverflow.com/q/28191243/1906307) and [this](http://stackoverflow.com/q/24153261/1906307), for instance. – Louis Dec 06 '16 at 11:56
  • Thanks for the links, although unfortunately they don't seem to offer any better solutions :( – machineghost Dec 06 '16 at 17:31