question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Jest performance is at best 2x slower than Jasmine, in our case 7x slower

See original GitHub issue

šŸ› Bug Report

Weā€™ve been using Jest alongside Jasmine for the same test suite for about a year now. 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 problem has been getting worse and worse as the test suite grows and as a result, we always run our test suite via Jasmine and only use Jest for development --watch mode.

We would ā™„ to use Jest as our only test runner, but its poor performance is preventing us from doing so. Having to run both Jest and Jasmine runners requires painful CI setup and constant upkeep of the Jasmine environment setup (which is much more complex than Jestā€™s).

Iā€™d like to better understand why the performance difference is so significant and if thereā€™s anything that can be done to optimize it.

To Reproduce

Iā€™ve created a very detailed project to reproduce and profile both Jest and Jasmine on the same test suite in this project: https://github.com/EvHaus/jest-vs-jasmine

The environment is the same. The configurations are very similar. Both use JSDom. Both use the same Babel setup. Additional instructions are contained therein.

Expected behavior

Running tests through Jest should ideally be as fast as running them through Jasmine.

Link to repl or repo (highly encouraged)

https://github.com/EvHaus/jest-vs-jasmine

Run npx envinfo --preset jest

Tested on a few different platform. See https://github.com/EvHaus/jest-vs-jasmine README for more info.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:167
  • Comments:42 (10 by maintainers)

github_iconTop GitHub Comments

21reactions
Shingazcommented, Mar 26, 2020

Same issue here on 25.2.2, file resolution takes too long. Is there any plan to speed it up?

11reactions
armano2commented, Jan 12, 2019

i was trying to do migration from mocha to jestā€¦ andā€¦ mocha is finishing all tests before jest starts first oneā€¦ i think there is somewhere issue with resolving/reading files -> my project contains ~70k files, and iā€™m running ~19k tests.

after some digging its looks like jest is trying to import all files from all folders before he starts tests, iā€™m providing explicit match for test file: testMatch: ['<rootDir>/dist/alignment.spec.js'].

i was able to run tests by adding to jest.config

modulePathIgnorePatterns: ['<rootDir>/fixtures/.*'],

but itā€™s still 11mā€¦ as opposed to mocha ~1m and without test framework (try/catch assert) ~40-50s

turning off transformation helped to

transform: {}

so far my configuration looks like this:

module.exports = {
  testEnvironment: 'node',
  testMatch: ['<rootDir>/dist/alignment.spec.js'],
  moduleFileExtensions: ['js'],
  transform: {},
  modulePathIgnorePatterns: ['<rootDir>/projects/.*', '<rootDir>/node_modules/.*']
};

its still slow, ~4min


now iā€™m looking for way to turn of prettier, i donā€™t care about formatting errorsā€¦

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Test-Runners Benchmark - Medium
Jasmine is the leader with 215 ms. And the other 3 runners (Jest, Tap and AVA) are several times slower. I guess the...
Read more >
JavaScript Unit Testing Performance - Jest
Because we are running slow tests first, Jest can sometimes seem to take a long time to start up ā€“ we only print...
Read more >
How to make your sluggish Jest tests go faster - ITNEXT
A step-by-step guide how to improve performance of your slow Jest unit test and make them blazingly fast and delightful again.
Read more >
[AskJS] Jest is so slow. Why Jest? : r/javascript - Reddit
I switch to Jasmine and it is much cleaner. Though don't see much performance difference because my project is quite small.
Read more >
Make your Jest Tests upto 10x Faster | Dev Genius - Dev Genius
use jest-slow-test-reporter to identify the slowest tests, and then start working on improving their performance of that. Make sure most of your tests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found