If I have fixtures and modify them then it seems that the fixtures are keeping new state for tests in next file. I expected mocha would reload required files, so fixtures for example are in initial state, since I'm requiring them again in the next test/file.
If I have fixtures and modify them then it seems that the fixtures are keeping new state for tests in next file. I expected mocha would reload required files, so fixtures for example are in initial state, since I'm requiring them again in the next test/file.
If you copy the fixture data in the `beforeEach`, all is well.
It sounds like there’s some misunderstanding of more fundamental issues here. In particular, Node.js’s require never executes a file more than once. Given that, why would you expect Mocha to do so? Do you expect it to spin up a separate Node.js process for each test file?
It sounds like there’s some misunderstanding of more fundamental issues here. In particular, Node.js’s require never executes a file more than once.
Given that, why would you expect Mocha to do so? Do you expect it to spin up a separate Node.js process for each test file?
>> Given that, why would you expect Mocha to do so? Do you expect it to spin up a separate Node.js process for each test file?
> Yes I expected to have a new process or something, which is not influenced by previous tests. I expect mocha to do so, because that is the only way to have an isolated test and it wouldn't matter which test runs first.
That's not the only way: the other way is to actually write your tests in an isolated fashion, as you are advised to by most canonical sources on unit testing. Indeed, such state-resetting is the entire purpose of things like `afterEach`.
Having used unit testing frameworks in both C# and JavaScript, I have never seen one that spins up a separate process per test file (or, as you seem to be suggesting, per test). The overhead involved would probably destroy the speed of your test runs!
That said, maybe in Ruby or Python communities such practices are common, and they've found a way around the overhead. I have no experience with them.
Yes I expected to have a new process or something, which is not influenced by previous tests. I expect mocha to do so, because that is the only way to have an isolated test and it wouldn't matter which test runs first.
The only solution I see is a batch or something like that, which calls tests I want to separate. Otherwise dig into mocha and see if these problem can be solved.