mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.99k stars 641 forks source link

Get `bun test` working locally #2204

Closed thegedge closed 3 months ago

thegedge commented 3 months ago

What does this PR do and why?

Before this PR, bun test would have a ton of failures if you ran it locally. We didn't see this in CI because our runners would test each file separately from one another.

After doing some digging, I found a couple of issues:

  1. AFAICT, bun test maintains globals across modules (unlike jest), so you have to be careful to reset it.
  2. Sometimes tests would hang because failures wouldn't call the done callback.
  3. Some other issue that I could not explain with this test: https://github.com/mobxjs/mobx-state-tree/blob/fc60d76b3725e053b89532e6f26804bf9e893d75/__tests__/core/model.test.ts#L212-L230

And the various solutions:

  1. Introducing a setup script that ensures we reset state before/after each test.
  2. Switch to await / async vs callbacks.
  3. Check for overlapping view/properties when instantiating the views vs discovering this issue when getting the atoms, which we were doing here: https://github.com/mobxjs/mobx-state-tree/blob/fc60d76b3725e053b89532e6f26804bf9e893d75/src/types/complex-types/model.ts#L651-L658

Steps to validate locally

All of the following should succeed:

coolsoftwaretyler commented 3 months ago

Ooh very exciting! Thanks for figuring this out! Will take a look soon.