Jest slow startup time and slow tests

2,682 views
Skip to first unread message

gil...@madeofbytes.com

unread,
Aug 5, 2014, 6:47:24 PM8/5/14
to jes...@googlegroups.com
Hi all,

I started a new application for a client and we are going for ReactJS, flux architecture and Jest.

1 week in, we really love the setup. The only issue I have is the slow running tests.

Here is the output of running npm test (which just calls `jest`)

± time npm test

> CaLo-...@4.0.0 test dev/CaLo-Player
> jest

Found 8 matching tests...
PASS src/components/exercises/__tests__/GapFillingItem-fixture.js (0.224s)
PASS src/actions/__tests__/CaloActions-test.js (0.626s)
PASS src/constants/__tests__/CaloConstants-test.js (0.602s)
PASS src/dispatcher/__tests__/CaloDispatcher-test.js (0.66s)
PASS src/stores/__tests__/ContextualResource-test.js (0.809s)
PASS src/stores/__tests__/CaloStore-test.js (0.952s)
PASS src/components/exercises/__tests__/GapFillingItem-test.js (1.428s)
PASS src/components/__tests__/ContextualResourceButton-test.js (1.863s)
8 tests passed (8 total)
Run time: 4.722s

real 0m6.561s
user 0m2.848s
sys 0m1.014s


Only a couple of the test do some DOM interactions and there are no more than about 30 tests so far. Having used karma (and previously testacular), I'm used to test suites with 100s to 1000s of tests executing in seconds, 10s of tests in milliseconds. There are also just 2 test suites so far that contain JSX code.

Is this normal? Could it be a configuration issue? Is there something I can do to speed this up?


Thanks,

Gilles

miken...@gmail.com

unread,
Dec 30, 2014, 1:17:11 PM12/30/14
to jes...@googlegroups.com
For anyone else finding this thread. I've seen similar numbers and improved it by making some modifications to my JSX preprocessor file. The original file is at the bottom of https://facebook.github.io/jest/docs/tutorial-react.html#content.

Mine now look like this:

var ReactTools = require('react-tools');
module.exports = {
process: function(src, file) {
// We really only care about JSX and React test files
if (/\.jsx$/.test(file) || /react-test.js$/.test(file)) return ReactTools.transform(src);
return src;
}
};

Note the "*react-test.js" naming convention for our React test files. The above ensures that only *.jsx and our specific React test files are being transformed.

Another improvement I made to my tests was moving the require() statements within my tests from the beforeEach() function right at the top of the describe() function.

Cheers,

Mike
Reply all
Reply to author
Forward
0 new messages