13

我需要帮助来查找代码覆盖率。

我刚刚使用最新的 create-react-app 创建了一个新应用程序。

我正在尝试使用npm run test -- --coverage. 这显示了空代码覆盖率。任何人都可以帮我找到我失踪的地方。

 PASS  src/__tests__/App.test.js
  ✓ renders without crashing (2ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.17s, estimated 1s
Ran all test suites.

Watch Usage: Press w to show more.
4

2 回答 2

26

https://github.com/facebook/create-react-app/issues/6888

只需将标志添加--watchAll=false到您的npm run test -- --coverage

于 2019-09-17T07:06:28.543 回答
8

尝试在脚本下将以下内容添加到您的 package.json

"test:coverage": "npm test -- --coverage --watchAll=false",

然后你可以运行命令来检查覆盖率'npm run test:coverage'

于 2020-07-14T12:38:06.133 回答