简体   繁体   中英

Slow mocha unit tests run

Running unit tests takes a lot of time in my computer, but the reporting time from mocha is not that bad. If I run this command:

time mocha $(find src -type d -name "__tests__" -exec find {} -type f \;)

I get this result:

  1396 passing (4s)
  10 pending

mocha   20.31s user 1.15s system 85% cpu 25.115 total

You can see that it takes 4s for mocha to run tests but actual test run takes much longer (25s). I cannot imagine why is it so slow, finding tests is quick:

find src -type d -name "__tests__" -exec find {} -type f \;  0.07s user 0.13s system 58% cpu 0.327 total

Any idea why is it so slow and how to make it faster?

I found a similar problem that was down to my antivirus software (Sophos) having on-access file scanning enabled. Disabling that reduced total run-time from ~14.5s to ~1s

With scanning enabled:

mocha index.test.js  1.18s user 0.29s system 9% cpu 14.747 total

With scanning disabled:

mocha index.test.js  1.11s user 0.27s system 103% cpu 1.336 total

For me it was another issue. I was running the tests on an SSHFS filesystem which caused the slowdown. A simple copy to a local directory solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM