Jest get total line coverage (for gitlab badge)

Jest get total line coverage (for gitlab badge)

我看到您可以使用 GitLab 来 generate a badge icon on the fly for code coverage. Therefore, in one of the CI jobs, there must be a regex pattern found

我有一个使用 jest 进行测试的 React 项目。我看到您可以使用 --coverage 参数,这会输出以下内容:

 PASS  __tests__/App-test.js
  ✓ renders correctly (631ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |       50 |      100 |      100 |                   |
 App.js   |      100 |       50 |      100 |      100 |                36 |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.46s
Ran all test suites.

不幸的是,这并没有提供我可以用来满足 GitLab 的正则表达式模式的总数。

我的谷歌搜索没有给出关于如何输出总覆盖率的结论。

任何帮助将不胜感激,非常感谢。

我从其他测试库中了解到的“总覆盖率”一般来说是“总 覆盖率”。因此 jest 已经在第一行 (All files) 的 % Lines.

列下提供了此信息

正则表达式可用于检测:

All files[^|]*\|[^|]*\s+([\d\.]+)