mobxjs / mobx-state-tree

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

Convert to bun:test for our tests, remove codecov #2149

Closed coolsoftwaretyler closed 3 months ago

coolsoftwaretyler commented 4 months ago

What does this PR do and why?

This PR will convert our Jest test to bun test. This offers us a few advantages:

  1. Huge improvement in speed (locally, I see ~2-3x improvement)
  2. Native support for TypeScript, so no need for ts-jest
  3. Without the need for ts-jest and jest itself, we reduce our devDependencies as well
  4. Since we have moved over to Bun for dependency management and script running, this makes our development tooling more consistent overall.
  5. This also removes codecov, partially because we didn't take the time to implement it with Bun, but also because that package is deprecated, and I don't think our token has been working for some time. We discussed this in the maintainer chat and agreed.
  6. Fixes a missing MstError from a rebase

Steps to validate locally

  1. Make sure you have latest Bun installed
  2. Pull down this branch
  3. Run bun install
  4. Then run bun test:all - tests should pass.
  5. If you time it with time bun test:all, you can measure its runtime. Here's what I got on my 2020 Macbook Pro with Intel i7/32 GB RAM:
bun test:all  14.55s user 6.84s system 100% cpu 21.302 total

Compare this to the yarn test:all run in master, which reports:

Ran all test suites.
✨  Done in 75.39s.

Ran it with time yarn test:all and got slightly better results but with a lot more CPU usage:

yarn test:all  178.77s user 24.75s system 432% cpu 47.026 total
coolsoftwaretyler commented 3 months ago

I was able to get this working with a little bit of bash scripting. I don't love it, but since the Bun test runner doesn't behave precisely like jest -i, someone recommended this command instead, which we can chain together to get full tests running with minimal skips and changes.

The major downside right now is that coverage is no longer correctly generated. I will see if I can fix that up.

Bun also shipped support for expect.assertions, so I was able to keep that expectation in there

coolsoftwaretyler commented 3 months ago

I added the specific toThrow error messages back to those expectations, and then realized we weren't appropriately failing with the one-liner script to run all tests, so I put together separate bash scripts that will fail the process if we got any failures (and output the full results if so).

I also removed cross-env for now since we were only using it in those test commands, and we've swapped to bash scripts which presume a specific type of environment variable setting.