[英]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). 您可以看到mocha运行测试需要4s,但实际测试运行需要更长的时间(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. 我发现了一个类似的问题,这个问题归功于我的防病毒软件(Sophos)启用了访问文件扫描。 Disabling that reduced total run-time from
~14.5s
to ~1s
禁用总运行时间从
~14.5s
到~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.
我在SSHFS文件系统上运行测试,导致速度减慢。 A simple copy to a local directory solved the problem.
简单复制到本地目录解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.