来自伊斯坦布尔的HTML格式的单元测试覆盖率报告显示了项目中的每个文件夹index.html
.
它实际上使目录结构变平.是否可以选择使用嵌套文件夹呈现html报告?
javascript unit-testing code-coverage istanbul test-coverage
我有一个构建我所有java/angularJS项目的Jenkins构建.它启动了java部分的testNG测试和javascript部分的karma测试.所以我可以在我的Jenkins构建中生成一个testNG报告(用于java)和一个junit报告(用于业力测试).这非常有效.
到目前为止,我使用cobertura来报告我的java测试的覆盖范围.但是现在我想为我的业力测试添加一份报道报告(伊斯坦布尔用cobertura类型生成).问题是,在Jenkins中,我被允许在一个构建中只生成一个覆盖率报告(我不能添加更多那个'发布cobertura覆盖率报告'构建后的动作).那么如何在单个Jenkins构建中获得这两个覆盖率报告呢?
我正在测试一个简单的应用程序(来自Mocha教程代码https://marcofranssen.nl/using-mocha-chai-sinon-to-test-node-js/),试图让伊斯坦布尔工作.我的问题是伊斯坦布尔工作正常,给我一个覆盖总结,但由于某种原因吐出错误,我不知道为什么.我的测试全部通过,所以他们希望不是问题.以下是我如何经营伊斯坦布尔:
$ istanbul cover test.js
=============================================================================
Writing coverage object [C:\Users\path\test\coverage\coverage.json]
Writing coverage reports at [C:\Users\path\test\coverage]
=============================================================================
=============================== Coverage summary ===============================
Statements : 54.55% ( 6/11 )
Branches : 100% ( 0/0 )
Functions : 0% ( 0/2 )
Lines : 54.55% ( 6/11 )
================================================================================
ReferenceError: describe is not defined
at Object.<anonymous> (C:\Users\path\test.js:9:386)
at Module._compile (module.js:435:26)
at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\path
\AppData\Roaming\npm\node_modules\istanbul\lib\hook.js:107:24)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at runFn (C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\lib\com
mand\common\run-with-cover.js:122:16)
at C:\Users\path\AppData\Roaming\npm\node_modules\istanbul\lib\command\co …
Run Code Online (Sandbox Code Playgroud) 我正在使用istanbul和nyc命令为NodeJs运行代码覆盖率报告.
我正在使用mocha进行单元测试
我按照预期得到了每个文件的报告,但我希望看到的是一个包含单个目录摘要的报告.让我更详细地解释一下,我正在阅读我想要看到的内容
我的所有源文件都在一个文件夹中,我想查看该文件夹的摘要,而不是该文件夹中每个文件的完整列表
这是我的文件夹结构的样子
// This is the folder where all the sources are at
src
// This is the folder where coverage is output
coverage
NodeJs
index.html
file1.js
file2.js
file3.js
// This is the folder where all tests are at
tests
test_file1.js
test_file2.js
test_file3.js
Run Code Online (Sandbox Code Playgroud)
我的.babelrc
文件看起来像这样
{
"presets": ["es2015", "stage-2"],
"plugins": [
[
"istanbul",
{"exclude": ["**/tests/*.js"]}
]
]
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下命令来运行我的测试覆盖率
node ./node_modules/.bin/nyc --reporter=html \
--report-dir=./src/coverage/NodeJs \
./node_modules/mocha/bin/_mocha \
--require babel-core/register \
--ui bdd src/tests/test*.js
Run Code Online (Sandbox Code Playgroud)
我的所有测试运行正常,它们通过,报告src/coverage/NodeJs/index.html
按预期输出到文件.在浏览器中,该报告看起来像这样: …
是否有人为伊斯坦布尔的nightwatch.js提供代码覆盖率.任何有用的配置链接将不胜感激.
我正在尝试获取测试的覆盖率报告,但所有文件的覆盖率输出始终在一行上,显示带有文件路径的require.例如...
然而,测试运行良好.这是一个反应项目,因此我必须在文件和预处理器中包含一些额外的路径以使测试运行.
我不确定我的业力配置是否有问题?这就是我的配置目前的样子......
/* global module */
module.exports = function (config) {
'use strict';
config.set({
autoWatch: true,
singleRun: true,
frameworks: ['browserify', 'jasmine'],
files: [
'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js',
'node_modules/react/react.js',
'src/**/*.jsx',
'src/**/!(*spec).js'
],
browsers: ['PhantomJS'],
preprocessors: {
'node_modules/react/react.js': ['browserify', 'sourcemap'],
'src/**/*.jsx': ['browserify', 'sourcemap', 'coverage'],
'src/**/!(*spec).js': ['browserify', 'sourcemap', 'coverage'],
},
browserify: {
debug: true,
transform: [ 'babelify' ]
},
reporters: ['progress', 'coverage'],
coverageReporter: {
instrumenters: {isparta: require('isparta')},
instrumenter: {
'src/**/*.js': 'isparta',
'src/**/*.jsx': 'isparta'
},
reporters: [
{
type: 'text-summary',
subdir: normalizationBrowserName
},
{
type: 'lcov', …
Run Code Online (Sandbox Code Playgroud) Mocha
并且chai
可以在浏览器中无缝使用。你用脚本标签导入它们,导入你的测试脚本,然后在浏览器中你就会得到一个很好的结果摘要。
这也使得测试操作 dom 的库变得微不足道,因此必须在浏览器中进行测试。
如何集成instabul
到这样的工作流程中?随着QUnit
它是那么容易,因为进口blanket.js
,但它不支持了。
我在一家@std/esm
未获批准的公司工作。我的摩卡测试是这样工作的......
// suite.js
async function wire(){
await import("./Sanity.spec.mjs"); // eslint-disable-line
run();
}
wire();
//Sanity.spec.mjs
import chai from "chai"
describe("My Test", ()=>{
it("Should do what I want", ()=>chai.assert.equal(1,1, "One is in fact 1")); // eslint-disable-line no-self-compare
});
Run Code Online (Sandbox Code Playgroud)
但是当我运行时,nyc mocha --delay --exit ./test/suite.js
我看到 mocha 测试运行但代码覆盖率结果为空。
My Test
? Should do what I want
When using base App
info: Healthcheck server is listening on 420
? App should not be null
? The port should be correct
3 passing …
Run Code Online (Sandbox Code Playgroud) 我想使用 Gitlab CI 来跟踪/嵌入合并请求中的覆盖率分析。该gitlab-ci.yml artifacts:reports:junit
配置的选择似乎是非常适合这项工作。但是,这要求覆盖
输出为 junit.xml 格式。
我没有找到合适的设置来输出这种格式的覆盖率。我也找不到将 lcov/json/clover 转换为 junit.xml 的工具。
对于 React/Redux 项目,我使用 Cypress 来测试 UI。我需要从这些测试中获取代码覆盖率,以便在声纳中获得详细信息(但那是另一个故事了)。
所以我开始阅读 Cypress 的文档:https://docs.cypress.io/guides/tooling/code-coverage.html
我按照说明找到了不同的插件,但没有任何作用。运行赛普拉斯测试后,我没有覆盖结果,当我尝试使用转译中的检测代码运行服务器并尝试获取window.__coverage__
它的undefined
.
这是我的配置。
我的 devDep 和 NYC conf 在package.json中:
"devDependencies": {
"@cypress/code-coverage": "^1.8.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^5.2.0",
"babel-plugin-react-intl": "^2.4.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-react-app": "^3.1.2",
"cross-env": "^5.2.0",
"cypress": "3.1.0",
"istanbul-lib-coverage": "^2.0.5",
"jest-junit-reporter": "^1.1.0",
"junit": "^1.4.9",
"nyc": "^14.1.1",
"react-test-renderer": "^16.3.0"
[...]
},
"scripts": {
"start": "react-scripts start",
[...]
"test:unit:local": "react-scripts test --env=jsdom .*_test.js",
"test:unit": "npm run test:unit:local -- --ci --coverage --testResultsProcessor ./node_modules/jest-junit-reporter",
"test:integ:local": "cypress run --reporter junit",
"test:integ": …
Run Code Online (Sandbox Code Playgroud) istanbul ×10
javascript ×5
mocha.js ×3
nyc ×2
reactjs ×2
testing ×2
babeljs ×1
browserify ×1
chai ×1
cobertura ×1
cypress ×1
ecmascript-6 ×1
gitlab-ci ×1
jenkins ×1
jestjs ×1
junit ×1
karma-runner ×1
node.js ×1
tdd ×1
unit-testing ×1
xml ×1