0

我让 Jenkins 构建了我们的 nx Angular 单一存储库。现在,每个应用程序/模块都会在覆盖目录下生成自己的报告。是否有一种经过批准的方法或一种好方法可以将所有这些报告合并到一个 html 报告中?

4

4 回答 4

2

我自己也有同样的问题。在 3 个不同的项目中遇到这种需求后,我决定写一篇关于它的博客文章: https ://yonatankra.com/how-to-create-a-workspace-coverage-report-in-nrwl-nx-单回购/

本质上,我编写了一个脚本来获取lcov文件并将它们组合起来:

const glob = require('glob');
const fs = require('fs');
const path = require('path');

const getLcovFiles = function (src) {
  return new Promise((resolve, reject) => {
    glob(`${src}/**/lcov.info`, (error, result) => {
      if (error) return reject(error);
      resolve(result);
    });
  })
};

(async function(){
  const files = await getLcovFiles('coverage');
  const mergedReport = files.reduce((mergedReport, currFile) => mergedReport += fs.readFileSync(currFile), '');
  await fs.writeFile(path.resolve('./coverage/lcov.info'), mergedReport, (err) => {
    if (err) throw err;
    console.log('The file has been saved!');
  });
})();

test然后我在 npm脚本之后使用它。

如果需要 JSON 格式,可以在合并后使用https://github.com/davglass/lcov-parse或其他转换器。

于 2021-02-15T04:40:23.963 回答
1

istanbul-combine will be deprecated in favor of istanbul report. I did a migration lately.

This was the old configuration that I was using with istanbul-combine:

istanbul-combine -d coverage -p none -r lcov -r cobertura coverage/hierarchical-grid/coverage-final.json coverage/tree-grid/coverage-final.json coverage/non-grid/coverage-final.json coverage/grid/coverage-final.json

Changed to:

istanbul report --dir coverage --include coverage/**/coverage-final.json lcov

I was searching for a way to combine a couple .json reports with GitHub Actions CI.

The good side of this configuration above is that all .json files are part of similar directories:

  • coverage/grid/coverage-final.json
  • coverage/non-grid/coverage-final.json etc.

This is where the lcov report would be generated:

enter image description here

Related Pull Request.

于 2021-01-26T13:40:32.530 回答
0

我发现的一种可能性是创建一个简单的脚本来处理这项工作。完全在您的控制之下,因此您可以保持更新。我找不到最适合我需要的东西。

https://github.com/neekware/fullerstack/blob/main/tools/utils/coverageMerge.ts

我仍在寻找一种方法来发送可发布库的单个覆盖文件,分别发送到工作服。找到解决方案后,我将更新脚本。目前,遗憾的是,所有公共库都必须使用整体组合覆盖链接。

于 2021-08-17T17:29:41.697 回答
0

istanbul-combine is the best solution I've found for this. It uses an old version of istanbul internally, but it worked for me.

于 2020-07-06T19:27:45.587 回答