dvdzkwsk / react-redux-starter-kit

Get started with React, Redux, and React-Router.
MIT License
10.29k stars 2.2k forks source link

Super slow tests once project gets bigger #534

Closed SpencerCDixon closed 8 years ago

SpencerCDixon commented 8 years ago

Karma is running really slow now that my project has grown. I've passed in the debug flag and determined its due to karma-webpack. I was wondering if other people using this starter kit have experienced this problem and found any solutions?

I found this karma-webpack issue

Also this appears to be a fork of karma-webpack that can hot load the webpack. Wondering if anyone has used this instead of the normal karma-webpack

dvdzkwsk commented 8 years ago

:+1: for bringing this up, we have a larger app that can take ~1 minute just to get initial tests running. Don't have anything to add just yet, but would really love to hear peoples' thoughts.

SpencerCDixon commented 8 years ago

oh wow I suppose I shouldn't be complaining about 10-15 seconds! I just miss the user experience I had when first developing the app where I could run the npm test run:dev and it would auto run my tests in like nano seconds.

Another thing that happens somewhat frequently is this error:

screen shot 2016-02-08 at 10 16 01 pm

It's super odd because if I kill the test server and re-run it will just pass. Sometimes I have to do it 2-3 times to get it to work, other times it's actually a user error and I didn't import something properly.

Curious if this bug is just happening to me or if other people experience this as well

GerritWanderer commented 8 years ago

We're currently running into the same issue, which makes TDD a pain. I assume most of the time is spent when karma bundles all JS files. Could it be possible to use all available CPU cores?

dvdzkwsk commented 8 years ago

@SpencerCDixon I have not seen that error before, unfortunately.

@GerritWanderer that's my guess as well, and not sure as to the answer. Will do some digging today.

tarjei commented 8 years ago

@davezuko , @SpencerCDixon , regarding test speeds.

I've done some different hacks for this throughout the ages for a project running ~3000 tests. I do not have time for a PR atm, but I'll sum up the main things I've ended up doing:

  1. Use devtool: cheap-module-source-map for sourcemaps in webpack.
  2. Use karma-webpack-with-fast-source-maps instead of karma-webpack (in karma.conf you'll have to use: require('karma-webpack-with-fast-source-maps'), in plugins and comment out karma-webpack
  3. Do not use phanomjs-1.x as your browser as it leaks memory bigtime (we saw it using 20GB of RAM per run)

There are also some micro optimisations you can do:

  1. Tune test-bundler.js to just include the relevant tests for what you are developing just then.
  2. Make sure you teardown all resources, listeners etc you create in your tests.

Regards, Tarjei

GerritWanderer commented 8 years ago

thanks @tarjei, I'll give your hacks a try and report if the test speed have improved.

dvdzkwsk commented 8 years ago

@tarjei awesome tips, thank you. Just replacing the devtool and karma-webpack shaved off about 33% of the test time, will begin integrating these fixes into the starter kit mañana.

dvdzkwsk commented 8 years ago

I lied, some small perf improvements here: https://github.com/davezuko/react-redux-starter-kit/pull/553.

Will keep this issue open to figure out even more ways of improving test performance.

tarjei commented 8 years ago

I would not expext effects of these measures on a code base as small as this one ;-)

  1. feb. 2016 04.12 skrev "David Zukowski" notifications@github.com:

I lied, some small perf improvements here: #553 https://github.com/davezuko/react-redux-starter-kit/pull/553.

Will keep this issue open to figure out even more ways of improving test performance.

— Reply to this email directly or view it on GitHub https://github.com/davezuko/react-redux-starter-kit/issues/534#issuecomment-183571690 .

dvdzkwsk commented 8 years ago

@tarjei I did implement them in a larger code base, probably ~200 tests and >10k LoC and saw a 33% performance improvement there, just on initial build time.

tarjei commented 8 years ago

Good to hear :)

That is where I would expect the largest gains to come. IMHO, the actual running of JS tests is usually fast since you usually do not use a DB or other IO.

2016-02-13 19:57 GMT+01:00 David Zukowski notifications@github.com:

@tarjei https://github.com/tarjei I did implement them in a larger code base, probably ~200 tests and >10k LoC and saw a 33% performance improvement there, just on initial build time.

— Reply to this email directly or view it on GitHub https://github.com/davezuko/react-redux-starter-kit/issues/534#issuecomment-183723923 .


Tarjei Huse Mobil: 920 63 413

SpencerCDixon commented 8 years ago

Yeah @tarjei the actual tests in my project run SUPER fast, it's just the webpack compilation. Thank you for getting something working @davezuko I'm going to adapt your PR to the older version of the starter kit I'm using! Cheers

dvdzkwsk commented 8 years ago

Ok, well in that case I'll close this for now @SpencerCDixon. Will continue looking for performance improvements going forward.