I've opened a ticket, but it got closed immediately without any information if this is normal and acceptable;
I'll post the question here.
Thinking that this is normal could be one of the biggest mistakes of my career so far. I was tinkering with CodeSandbox and noticed how instantaneous the tests were compared to what I was used to. Set up a basic template project, and here are my results:
{
"name": "jest-performance-test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "mocha"
},
"dependencies": {
"chai": "^4.2.0",
"jest": "^23.0.0"
},
"devDependencies": {
"mocha": "^7.1.0"
}
}
jest.config.js
{
"testRegex": "__tests__/*",
"testEnvironment": "node",
}
Several dozen duplicated tests with
const {expect} = require('chai')
it ('should run the test', async () => {
expect (true).to.be.true
})
//...
in each
running jest --watch
, making a change and saving:
running yarn run test --watch
(mocha --watch
), making a change and saving:
--runInBand
makes it even worse.
I get it, I'm stuck with 5y/o Windows laptop on HDD and all that, but 40 times?
I have projects with pretty intricate jest setups, and tried to solve the issue of performance many times over the last year or so.
Is there anything I can do to not switch to mocha/chai? I don't feel like running a single jest test anymore.
Jest runs 40 times slower than mocha.
We love Jest because it's developer experience is superb, however, on our very large monorepo with ~7000+ test specs, Jest runs about 7 times slower than Jasmine.
This is mostly startup time because jest reports the test itself running in ~100ms. We would like to get this time down to allow for a better developer experience.
I use both in my projects, and yes, the performance difference is very real.
I use jest
only when it offers enhanced support for front-end modules - it is very good for React for example. Otherwise I always use mocha
.
jest
uses Babel to transpile all TypeScript code - including node_modules
when they need to be transpiled - to JavaScript.
mocha
uses ts-node
to directly run TypeScript.
This is the reason for the difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With