简体   繁体   English

在 npm create-react-app 之后立即运行测试非常慢

[英]Running test immediately after npm create-react-app is extremely slow

Immediately after npx create-react-app my-app , I move into the my-app folder and do CI=true npm test .npx create-react-app my-app之后,我立即进入my-app文件夹并执行CI=true npm test

The resulting output is:生成的 output 是:

> react-scripts test

PASS src/App.test.js
  ✓ renders learn react link (39ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        4.465s
Ran all test suites.

In package.json after adding the flag --env=jsdom to react-scripts test , I got:package.json添加标志--env=jsdomreact-scripts test后,我得到:

PASS src/App.test.js
  ✓ renders learn react link (42ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.026s, estimated 3s
Ran all test suites.

My expectation is that everything would run in less than 1 second.我的期望是一切都将在不到 1 秒的时间内运行。 Can I get it to run faster than shown above if I'm rendering react components in the tests?如果我在测试中渲染反应组件,我可以让它比上面显示的运行得更快吗?

Running with yarn doesn't make a difference.yarn跑步并没有什么不同。

Run it in gitpod... it's a containerized electron app for vscode that runs in the browser and is blisteringly fast compared to running npm commands on a local machine and is noticably faster than github code spaces as well.在 gitpod 中运行它...它是用于 vscode 的容器化 electron 应用程序,可在浏览器中运行,与在本地计算机上运行 npm 命令相比速度非常快,并且明显快于 ZBF215181B514052244AZD 代码以及空格。

If that's not to your liking than you could probably run npm audit fix -f and Or如果这不符合您的喜好,您可能可以运行 npm 审计修复 -f 和或


npm cache clear --force
npm cache rm --force
npm cache verify 

You cous also append the test.skip to save time on test's you're not currently working on...您还可以使用 append test.skip 来节省您当前未进行的测试的时间...

In my experience slowdowns are usually the result of some dependency weirdness or your computer overheating after a long day of indifference to the cpu's temperature.以我的经验,速度变慢通常是由于某些依赖异常或您的计算机在对 cpu 温度一整天漠不关心后过热造成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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