javascript - Mocha 单元测试运行缓慢

标签 javascript performance shell mocha.js

在我的电脑上运行单元测试会花费很多时间,但是 mocha 的报告时间还不错。如果我运行这个命令:

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

我得到这个结果:

  1396 passing (4s)
  10 pending

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

您可以看到 mocha 运行测试需要 4 秒,但实际测试运行需要更长的时间(25 秒)。我无法想象为什么这么慢,找到测试很快:

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

知道为什么它这么慢以及如何让它更快吗?

最佳答案

我发现了一个类似的问题,这是由于我的防病毒软件 (Sophos) 启用了按访问文件扫描。禁用将总运行时间从 ~14.5s 减少到 ~1s

启用扫描:

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

禁用扫描:

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

关于javascript - Mocha 单元测试运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31746840/

相关文章:

asp.net - 代码覆盖率工具

shell - 为什么curl 发送有关速度和时间的报告作为错误输出

linux - Makefile 和 Shell 脚本 (Bash)

javascript - RactiveJS + Redux 调度操作和水合物

javascript - Meteor 应用程序运行时出现 pm2 fatal error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

php - 每秒大量插入导致大量 CPU 负载

c# - 提高 Excel 文件创建的性能

javascript - 重新排序 javascript 数组

javascript - 在 Javascript 的工作线程中阻塞异步调用

java - 如何将 Jar 文件传递​​给 OOZIE shell 节点中的 shell 脚本