New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest tests are slow #180

Closed
AlesJiranek opened this Issue May 4, 2015 · 7 comments

Comments

Projects
None yet
4 participants
@AlesJiranek
Contributor

AlesJiranek commented May 4, 2015

I'm trying to write some basic tests using jest and I figured out that Jest is super slow.
I have three simple tests and running them takes 5 seconds.
When I clone este and run gulp jest, it takes ~1.4 sec, which is so much for running only one test for getrandomstring.js

I tried to google how to improve tests speed but I haven't found anything interesting. Lot of users recommends to use mocha instead of jest. They showed some benchmarks and mocha was running over 100 test in ~3 secs.

What do you think about mocha? Wouldn't it be better?

@AlesJiranek

This comment has been minimized.

Contributor

AlesJiranek commented May 4, 2015

I just tried to setup mocha and run tests for my project and they passed in 222ms. I think it's big difference to 5sec

@ronag

This comment has been minimized.

ronag commented May 4, 2015

Possibly related, facebook/jest#116

@steida

This comment has been minimized.

Contributor

steida commented May 4, 2015

I have to say I didn't liked jest, because I expected issues with auto mocking. I was using Mocha for years in my previous Este stack also with JSDOM, and it was super fast.
I have to rethink unit tests strategy for new Este, probably going back to Mocha. I will also add test strategies into wiki.

Problem is all there requires in code aka mixing app wiring with app logic. In previous Este everything was testable because everywhere were a lot of small classes with DI container. But classes driven development sucks, as I recently realised with new functional Este approach. Every class is piece of mutable state without change history = debug hell.

So now we have clean functional approach, but hard coded requires make code untestable. It's not a big issue, since testing is overrated and tests are a compensation mechanism for poor programming and incomplete and leaky abstractions. So we don't need testing everything, like classical class OOP needs. Still, sometimes TDD with unit tests is priceless. And for that use cases new Este will use Mocha with proper dependency injection without IOC container. Pure DI is enough http://blog.ploeh.dk/2014/06/10/pure-di/

@AlesJiranek AlesJiranek changed the title from Jest test are slow to Jest tests are slow May 4, 2015

@steida steida added this to the Jazzy House milestone Jun 9, 2015

@steida

This comment has been minimized.

Contributor

steida commented Jun 16, 2015

Jest will be removed.

@steida steida closed this Jun 16, 2015

@grabbou

This comment has been minimized.

Contributor

grabbou commented Jul 31, 2015

I can confirm that fixing babel parser to skip node_modules as well as setting correct testPathDir so it does not loop through node_modules makes start-up time to be less than 1 second. Also, optimising imports makes my tests run in less than 0.1 so very acceptable.

@steida

This comment has been minimized.

Contributor

steida commented Jul 31, 2015

Still, jsdom is deal breaker for Node 0.12 and what is worse, auto mocking is brittle and magic.

@grabbou

This comment has been minimized.

Contributor

grabbou commented Jul 31, 2015

I am testing react native, so auto mocking is actually my friend (React-Native provides lots of modules you can require during its runtime that are not available in test environments, so at least with Jest I can easily mock them, see https://github.com/este/native/blob/master/src/app/menu.style.js#L1). There are more than ~50 modules available like that but there are plans to move everything under react-native in 2 or 3 next releases.

PS. I believe as per tests, what matters are the solid and reasonable use cases, not the framework being used :) But just leaving it here for anybody interested in using Jest. In case of any questions, feel free to shoot me a message via Gitter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment