如何修复 'error from lcovParse: ' 'Failed to parse string'?在 circleICI v2.0 上使用带摩卡咖啡的工作服

how to fix 'error from lcovParse: ' 'Failed to parse string'? on circleICI v2.0 using coveralls with mocha

circleCI 在尝试 运行 这个命令时失败:

#!/bin/bash --login
cat ./coverage/coverage.json | ./node_modules/.bin/adana --format lcov | ./node_modules/coveralls/bin/coveralls.js

[error] "2019-02-20T20:22:50.695Z"  'error from lcovParse: ' 'Failed to parse string'
[error] "2019-02-20T20:22:50.697Z"  'input: ' '\n'
[error] "2019-02-20T20:22:50.697Z"  'error from convertLcovToCoveralls'

/home/ubuntu/Band-of-Coders/uber-auth/node_modules/coveralls/bin/coveralls.js:18
        throw err;
        ^
Failed to parse string
Exited with code 1

我就是这样 运行 我的测试:

./node_modules/.bin/_mocha -r test/helper/chai.js -r adana-dump --compilers js:babel-core/register -R spec --recursive --slow 100 test/spec/**/*.spec.js

在我的 .circleci/config.yml 中,我有:

 - run: npm test
 - run: npm install coveralls
 - run: cat ./coverage/coverage.json | ./node_modules/.bin/adana --format lcov | ./node_modules/coveralls/bin/coveralls.js

关于为什么会发生这种情况有什么想法吗? 我非常感谢任何帮助

您可能需要先使用 nycbabel-plugin-istanbul 或纯 istanbul 来生成覆盖率数据,然后再 运行 您的覆盖率报告脚本。否则,将没有可用于生成报告的数据。

我之前用过 nycbabel-plugin-istanbul,得到了预期的结果。

"test": "NODE_ENV=test nyc ./node_modules/.bin/_mocha <your-test-matching-wildcard-here>",
"coveralls": "NODE_ENV=test nyc report --reporter=text-lcov | coveralls"

您还需要在 .nycrc:

中进行一些配置
{
  "reporter"   : ["text", "text-summary", "lcov", "html"],
  "include"    : ["<your-include-wildcard>"],
  "exclude"    : ["<your-exclude-wildcard>"],
  "require"    : ["@babel/register"],
  "sourceMap"  : false,
  "instrument" : false,
  "all"        : true
}

运行先测试脚本再测试工作服。