首页 > 解决方案 > 如何修复“来自 lcovParse 的错误:”“无法解析字符串”?在 circleICI v2.0 上使用带有 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

关于为什么会发生这种情况的任何想法?我真的很感激任何帮助

标签: node.jsmocha.jscircleci-2.0coveralls

解决方案


在运行覆盖率报告脚本之前,您可能需要先使用nycwithbabel-plugin-istanbul或 plainistanbul来生成覆盖率数据。否则,将没有可用于生成报告的数据。

我以前用过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
}

先运行测试脚本,然后运行工作服。


推荐阅读