我为 GitLab 存储库进行了 CI 设置,并且该作业包含以下到 STDOUT 的输出。
=============================== Coverage summary ===============================
Statements : 94.25% ( 291/333 )
Branches : 62.29% ( 53/75 )
Functions : 73.32% ( 170/196 )
Lines : 94.68% ( 533/569 )
================================================================================
Run Code Online (Sandbox Code Playgroud)
在.gitlab-ci.yml该工作的文件中,我有coverage: /^Statements\s*:\s*([^%]+)/. 同样,在我设置的存储库的 CI/CD 设置中^Statements\s*:\s*([^%]+)。
然而,代码覆盖率似乎出现Unknown在代码覆盖率徽章上。
我想要获得单元测试和集成测试的组合覆盖。
我有单独的单元测试和集成测试文件夹。在我的管道 ci 中,我有一个单独的阶段用于单元测试和集成测试,因为集成测试需要依赖项。
包.json
{
"unit-test": "nyc mocha --timeout 5000000 -r ts-node/register --project tsconfig.json test/unit/*.test.ts --exit",
"integration-test": "nyc mocha --timeout 5000000 -r ts-node/register --project tsconfig.json test/integration/*.test.ts --exit",
}
Run Code Online (Sandbox Code Playgroud)
现在我分别收到了他们两个的报道报告,但我可以看到它并不能真实反映所有报道。
有什么办法我可以合并覆盖范围摘要吗?这可能意味着我需要将管道中的两个阶段结合起来?
我用 React、Cypress、Cucumber 和 Cypress Image Snapshot 做了一个项目来测试前端测试。一切正常,现在我想为执行的黄瓜测试获得一些代码覆盖率。
我尝试按照此处的建议进行设置(https://github.com/cypress-io/code-coverage),但没有运气。
我已经尝试过这个解决方案(https://github.com/cypress-io/cypress/issues/346#issuecomment-365220178),但结果相同。
测试以成功结束,但代码覆盖率显示Unknown% 0/0了语句、分支、函数和行。
我当前的设置:
support/index.js
import '@cypress/code-coverage/support'
import './commands'
Run Code Online (Sandbox Code Playgroud)
plugins/index.js
const cucumber = require('cypress-cucumber-preprocessor').default;
const {
addMatchImageSnapshotPlugin,
} = require('cypress-image-snapshot/plugin');
module.exports = (on, config) => {
addMatchImageSnapshotPlugin(on, config);
on('task', require('@cypress/code-coverage/task'))
on('file:preprocessor', cucumber());
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取我的角度项目的代码覆盖率。我不太熟悉这些工具。我决定使用"istanbul-instrumenter-loader": "^3.0.1". 我尝试从这个问题中寻求帮助:
以及在同一线程上给出的许多其他解决方案。我的问题是我想排除我为单元测试编写的规范文件。这是我得到的屏幕截图: 截图。请纠正我的错误,并随时询问缺失的信息。
我一直在尝试让 Cypress 代码覆盖率与我的 Angular 生产项目一起使用,但没有成功。
为了尝试帮助诊断它,我创建了一个最小的实施项目,以确保我没有在生产版本中引入任何奇怪的东西,我不认为我是这样,因为同样的问题仍在发生。它开始让我发疯了!
我使用了一些参考资料,据我所知,我已经准备好了所需的东西:
据我所知,Angular 和 Cypress 端都已连接,并且正在 .nyc_output 文件夹中获取输出和覆盖率报告。然而,该报告并未表明打字稿行覆盖率或包括这些统计数据。
我看过这个,但似乎没有帮助。
代码检测(webpack扩展+ angular.json):
module.exports = {
module: {
rules: [
{
test: /\.(js|ts)$/,
loader: "istanbul-instrumenter-loader",
options: { esModules: true },
enforce: "post",
include: require("path").join(__dirname, "..", "src"),
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/,
/(ngfactory|ngstyle)\.js/,
],
},
],
},
};
Run Code Online (Sandbox Code Playgroud)
"serve": {
"builder": "ngx-build-plus:dev-server",
"options": {
"browserTarget": "architecture-testing:build",
"extraWebpackConfig": "./cypress/coverage.webpack.js",
"sourceMap": true
},
"configurations": {
"production": {
"browserTarget": "architecture-testing:build:production"
}
}
}
Run Code Online (Sandbox Code Playgroud)
Cypress 似乎正在记录并保存报道:
const registerCodeCoverageTasks …Run Code Online (Sandbox Code Playgroud) 伊斯坦布尔测试覆盖率报告看起来像
从上图可以看出,第 4 行被覆盖了 25 次(或者已经运行了 25 次),是否可以准确地知道我的哪些测试命中了这条线?
其实我对1x的线条更感兴趣(图片来自伊斯坦布尔网站)
希望在玩笑覆盖范围中忽略这部分代码
/* istanbul ignore next */
async middleware(
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
_res: Response<any, Record<string, any>>,
next: NextFunction
) {
const { email, password } = req.body
await validate({ email, password })
next()
}
Run Code Online (Sandbox Code Playgroud)
我尝试过,/* istanbul ignore next */但似乎不起作用
module.js这个错误谈论的地方是什么?刚刚在这里找到它
load函数认为该命令是一个'.js'文件.如何为'.cmd'文件添加扩展处理程序????
使用yo和创建项目后generator-gulpplugin-coffee,我立即遇到了一个问题npm test
基本package.json "test"参数中列出的完整命令是
coffeelint gulpfile.coffee index.coffee test -f ./coffeelint.json && istanbul test _mocha --report lcovonly -- ./test/*.coffee --require coffee-script/register --reporter spec
Run Code Online (Sandbox Code Playgroud)
当我提取该命令并运行它时,coffeelint工作正常,但是在文件中的符号处istanbul test _mocha...出现Unexpected token ILLEGAL错误时失败:'@'_mocha.cmd
$ npm test
> gulp-ember-template-compiler-2@0.0.0 test C:\Users\me\code\something
> coffeelint gulpfile.coffee index.coffee test -f ./coffeelint.json && istanbul test _mocha --report lcovonly -- ./test/*.coffee --require coffee-script/register --reporter spec …Run Code Online (Sandbox Code Playgroud) 我的目标是能够在 es6 中编写 src 和测试文件,都在同一个目录中(我希望我的测试文件与我的源文件并排),并获得原始文件的覆盖率报告。
此时我能想到的最好方法是使用以下命令将我的测试文件包含在覆盖率报告中:
./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
cover \
node_modules/.bin/_mocha -- 'src/**/*.spec.*.js'
Run Code Online (Sandbox Code Playgroud)
我确实尝试使用cover -x 'src/**/*.spec.*.js',它也从转译中排除文件,mocha然后无法运行测试。对于我的生活,我无法弄清楚如何做这样的事情:
./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
cover -x 'src/**/*.spec.*.js' \
node_modules/.bin/_mocha -- --require babel-core/register 'src/**/*.spec.*.js'
Run Code Online (Sandbox Code Playgroud)
这将正常运行我的所有测试,但会给我带来负面影响:
未收集覆盖信息,不写入覆盖信息退出
所以我离我想要的并不远,我想我只是错过了最后一块,如果有人能在这里提供帮助,我将不胜感激。
问候,D。
我需要将相对路径作为 SF: karma 覆盖生成的 lcov.info 文件中的参数值。这是为了使 SonarQube 能够收集信息以显示覆盖范围。目前,SF参数具有完整的绝对路径,例如c:\abc\xyz....\src\bar\foo.js
我需要 SF: src\bar\foo.js
有办法实现这一点吗?
istanbul ×10
mocha.js ×3
nyc ×3
angular ×2
cypress ×2
javascript ×2
node.js ×2
angular-test ×1
babeljs ×1
chai ×1
cucumber ×1
ecmascript-6 ×1
gitlab ×1
jestjs ×1
karma-runner ×1
npm ×1
reactjs ×1
regex ×1
sonarqube ×1
unit-testing ×1