Taking slow mocha tests
Running unit tests takes a long time on my computer, but the post time from mocha is not too 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 to run the mocha tests, but the actual test run takes much longer (25 seconds). I can't imagine why it is so slow to find tests quickly:
find src -type d -name "__tests__" -exec find {} -type f \; 0.07s user 0.13s system 58% cpu 0.327 total
Any idea why this is so slow and how to make it faster?
+3
source to share
2 answers
I found a similar issue that was related to my antivirus software (Sophos) which has access file scanning enabled. Disabling this shortened total execution time from ~14.5s
to~1s
Scanning enabled:
mocha index.test.js 1.18s user 0.29s system 9% cpu 14.747 total
With scan disabled:
mocha index.test.js 1.11s user 0.27s system 103% cpu 1.336 total
+1
source to share