Mocha: Isolation of Test scripts

Created on 1 Apr 2015  路  6Comments  路  Source: mochajs/mocha

I have two test scripts in my tests path server-side.js and client-side.js. Both utilize React and a set of related modules for an "isomorphic" dev experience. Great. Individually, both do their thing, and tests pass. Beautiful. When I allow both to run, that is I don't comment out the other one, the server-side fails. Why, oh, why? The problem seems to stem from using React's TestUtils library on the client-side , which may be making unknown changes to the node environment (I've already gone down the road of manually setting/unsetting global.window and global.document for similar reasons). That sucks, and it's non-obvious what it's doing. So, yes, I should complain to ReactJS that they need proper tear-downs for whatever environmental modifications they are making. In the mean time though, I'd like my testing framework to be able to run these in isolation.

Most helpful comment

... we decided it's not mocha's fault if a library modifies the environment ...

It might not be mocha's _fault_, but being able to run isolated tests is a critical feature of testing (especially unit testing), so it is sorely missed. Other testing frameworks like AVA have process isolation, so it is certainly a strange decision for mocha not to support some way to do this (even if as a non-default option).

All 6 comments

"test": "mocha server-side.js && mocha client-side.js"?

That's a good point. I love Mocha's auto pickup mechanism, and use it as boiler-plate, but nothing wrong with being explicit until a tear down fix is in place. I'll give it a shot, thanks!

I believe we decided it's not mocha's fault if a library modifies the environment, that we shouldn't restore globals, etc.

Let us know if it works! (it should)

Works great :+1:

Nice :)

... we decided it's not mocha's fault if a library modifies the environment ...

It might not be mocha's _fault_, but being able to run isolated tests is a critical feature of testing (especially unit testing), so it is sorely missed. Other testing frameworks like AVA have process isolation, so it is certainly a strange decision for mocha not to support some way to do this (even if as a non-default option).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CADBOT picture CADBOT  路  3Comments

niftylettuce picture niftylettuce  路  3Comments

helloravi picture helloravi  路  3Comments

wzup picture wzup  路  3Comments

3p3r picture 3p3r  路  3Comments