The initial setup and usage of Jest has been merged in request #13789. This request is about moving the other test suites and to drop the usage of Karma/Jasmine within Tuleap.
Why are we moving away from Karma/Jasmine ?
- The more tests we have, the more Jenkins "steps" we have to add.
- Each karma "step" means spinning up a new headless chrome, which consumes resources.
- For each webpack configuration, we need a new, separate, karma file, which means even more Jenkins steps. This is because karma-webpack can only deal with one webpack configuration.
- Jasmine tests have to be run all at the same time. The only way to control which tests are run is through hacky "fit / fdescribe" or "xit / xdescribe". When you have more than 500 tests is becomes slow to run all tests everytime.
- coverage produced a HTML report, but we opened a browser to navigate it.
- We had to import manually our tests (see request #13653) in part because we badly mocked an external dependency of many apps: TLP.
- Karma's goal was to run tests in a real browser, but it's hard to say if we ever had the same goal when using it. Given we never ran our tests on IE11 which is the lowest common denominator as far as our browser support is concerned, we never really took advantage of "running tests in a real browser".
Not all of those are due to Karma or Jasmine, some are due to our own usage of them. We can do better.
Why are we moving to Jest ?
Jest offers all the same features as Jasmine but with additional goodness.
- We hope to be able to unify all JS test suites into a single "npm run test", meaning only one Jenkins step
- Even if we can't, we're no longer spinning a real browser but jsdom, which runs only in node. It should be faster.
- Jest tests can be ran one at a time, which means having the same dev experience as PHPUnit tests. (Run continuously the test suite associated to your file / component)
- Jest handles coverage better, which means seeing test coverage in our IDE
- Jest can do snapshot testing (Jasmine can't)
- And error messages are just better. No more "Expected true to be false".