node.js - 如何修复“来自 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
关于为什么会发生这种情况的任何想法?我真的很感激任何帮助
解决方案
在运行覆盖率报告脚本之前,您可能需要先使用nyc
withbabel-plugin-istanbul
或 plainistanbul
来生成覆盖率数据。否则,将没有可用于生成报告的数据。
我以前用过nyc
并babel-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
}
先运行测试脚本,然后运行工作服。
推荐阅读
- unix - 在 csv 文件中启用 Oracle 表数据的快速导出
- python - 检测到辣椒的面部识别后如何修复它?
- javascript - 如何使用条件 CSS 更改此图的颜色?
- sql-server - 在 SQL 中查找行的最大值
- vue.js - 使用 adal-angular 包 adal.js 身份验证上下文获取 Microsoft Graph 令牌
- django - 在 django 中为特定用例使用 select_related?
- javascript - 如何根据参数选择调用方法
- c# - 为什么我的 SQL 查询不能按我的意愿工作?
- c# - 如何使 Identity Core 生成的访问令牌无效?
- javascript - 如何获取输入值并将其用于异步函数以在 api 中进行搜索?