以下代码片段只有50%的分支覆盖率(请参阅下面的覆盖率报告)我不知道如何改进这一点,因为没有if
语句.
我想伊斯坦布尔必须做一些我不完全理解的测量,任何指针都会受到赞赏.
angular
.module("konakFront", [
"ngRoute"
])
.config(function ($routeProvider) {
"use strict";
$routeProvider
.when("/", {
templateUrl: "views/main.html",
controller: "MainCtrl"
})
.otherwise({
redirectTo: "/"
});
});
Run Code Online (Sandbox Code Playgroud)
我在让工作服上班时遇到问题.我在这里创建了一个简单的项目.
它似乎正在正确地输出报告,但我肯定错过了某个地方,因为工作服不会看到我的设置.没有分支显示,它只是给出了如何设置它的说明.我试图复制qunit正在做什么,因为他们显然有它的工作.
这是我到目前为止所做的.
创建了使用node/grunt/qunit以及工作服帐户并在项目上切换的项目.我已经用这个替换了部分中的qunit
引用.devDependencies
package.json
"grunt-coveralls": "0.3.0",
"grunt-qunit-istanbul": "^0.4.0"
Run Code Online (Sandbox Code Playgroud)
我已将此添加到我的package.json
.
"scripts": {
"ci": "grunt && grunt coveralls"
}
Run Code Online (Sandbox Code Playgroud)
我已经添加了这个配置对于qunit
我的Gruntfile.js
.
options: {
timeout: 30000,
"--web-security": "no",
coverage: {
src: [ "src/<%= pkg.name %>.js" ],
instrumentedFiles: "temp/",
coberturaReport: "report/",
htmlReport: "build/report/coverage",
lcovReport: "build/report/lcov",
linesThresholdPct: 70
}
},
Run Code Online (Sandbox Code Playgroud)
然后我把它添加到我的.travis.yml
.
language: node_js
node_js:
- "0.10"
before_install:
npm install -g grunt-cli
install:
npm install
before_script:
grunt
after_script:
npm run-script coveralls
Run Code Online (Sandbox Code Playgroud) 我在本地使用npm和grunt的代码覆盖,但我想在浏览器中演示这一点.
如果我打开一个codepen,我怎样才能在浏览器中生成代码覆盖?
请举例说明.
在这里,我正在测试一个控制器,Jasmine测试代码,但我想知道它是否100%覆盖并在浏览器中显示. http://codepen.io/clouddueling/pen/Jwaru?editors=001
我可以将我的代码提交给服务器吗?是否在heroku上即时测试并获得结果?Instanbul能以某种方式在客户端运行并输出一个html报告或json字符串吗?
我刚开始使用一个示例文件(example.js),该文件包含以下语句:
x = 42;
if(false)
x = -1;
Run Code Online (Sandbox Code Playgroud)
我没有任何单元测试文件.但是当我跑
istanbul cover example.js
Run Code Online (Sandbox Code Playgroud)
我看到一些以下的覆盖率数据
=============================== Coverage summary ===============================
Statements : 66.67% ( 2/3 )
Branches : 50% ( 1/2 )
Functions : 100% ( 0/0 )
Lines : 66.67% ( 2/3 )
==============================================================================
Run Code Online (Sandbox Code Playgroud)
这是否意味着我有3个陈述中的2个陈述?如果是这样,当我没有针对该代码的任何单元测试文件时,如何报告此代码被覆盖?
根据我对代码覆盖率的定义理解,它是由单元测试覆盖的代码.我不明白为什么istabul说当我没有写任何单元测试时我有2个陈述.
我有麻烦添加测试代码覆盖率,我使用Karma和添加到Karma的文件已经与browserify捆绑在一起,所以在karma.conf.coffee
它看来是这样的:
files: [
{ pattern:'bin/public/client/app.js', served:yes: included:yes }
{ pattern:'src/lib/vendor/angular-mocks/angular-mocks.js', served:yes: included:yes }
{ pattern:'bin/tests.js', served:yes: included:no }
]
Run Code Online (Sandbox Code Playgroud)
这适用于运行测试,但不适用于覆盖范围
我正在使用karma-coverage
npm包,这个:
preprocessors: 'bin/public/client/app.js':['coverage']
reporters: ['progress','coverage']
Run Code Online (Sandbox Code Playgroud)
实际上确实创建了覆盖率统计文件,但这些文件是完全错误的,因为它会使从node_modules带来的浏览器部分变得更糟(因为我没有测试来覆盖那些)
理想情况下,我必须收集browserify生成的源映射,并针对这些映射运行覆盖,但browserify将源映射嵌入到.js文件中.使用karma-sourcemap-loader
让我看到测试的原始coffeescript文件,在调试时(由于某种原因它只适用于ChromeCanary,但它可以工作)
我尝试过这样做preprocessors: 'src/client/**/*.coffee':['coverage']
,但是没有任何统计数字表示"无数据显示"
你有什么想法?
UPD:
我想通过运行browserify-istanbul
转换后coffeeify
,这给了我这样的好图:
现在,我需要以某种方式从中删除app.js,因为它真的没关系,真的很困惑
UPD:
哦,而不是javascript我必须提供咖啡文件:
preprocessors : {
'bin/tests.js': ['sourcemap']
'src/client/**/*.coffee': ['coverage']
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试检测我的代码以获得一些覆盖和运行,但是有些东西在我的手指上滑落.
我推出istanbul
:
node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -u exports -R spec
Run Code Online (Sandbox Code Playgroud)
我mocha.opts
看起来像这样:
app/assets/javascripts/components/**/*-mocha.jsx
--compilers jsx:mocha/compiler.js
Run Code Online (Sandbox Code Playgroud)
一切似乎运行良好(测试运行,至少),但我得到的唯一报道是用于编译JSX到JavaScript的文件(用于 compiler.js
compiler.js 100%
jsx-stub-transform.js 65%
Run Code Online (Sandbox Code Playgroud)
非常有用......
有任何想法吗?
我想执行命令
istanbul cover node_modules/mocha/bin/_mocha dist/test
Run Code Online (Sandbox Code Playgroud)
使用Istanbul编程API.但是文档并没有多说,除了一切都是可能的,并链接到庞大的API文档.我在互联网上找不到任何简短的例子.我不想生成子进程或使用NPM中的其他模块.我知道如何在没有覆盖的情况下以编程方式运行Mocha,所以这不是问题.
我刚刚开始将伊斯坦布尔测试覆盖模块用于摩卡咖啡。当我查看报告时,某些代码以黄色突出显示。我在文档中找不到这意味着什么?
我正在尝试将覆盖率报告生成添加到打字稿库项目中。
布局包括以下目录:
project
?? src
? ?? lib ## project code (typescript), *.tsx
? ?? test ## test specs (typescript), *.spec.tsx
? ?? @types ## types I made for a few dependencies that didn't have them
?? build
?? lib ## compiled project code (ES5 + type info, with inline sourcemaps), *.js and *.d.ts
?? test ## compiled test specs (ES5 + type info, with inline sourcemaps), *.spec.js and *.spec.d.ts
Run Code Online (Sandbox Code Playgroud)
我有一个测试脚本,package.json
它似乎可以正常工作:
"test": "mocha --reporter mocha-multi --reporter-options mocha-multi=mocha-multi.json --recursive …
Run Code Online (Sandbox Code Playgroud) 即使测试用例通过,我也无法弄清楚为什么测试覆盖率是0。我在package.json中有一个脚本:
"nyctest": "node --max_old_space_size=4096 node_modules/nyc/bin/nyc.js --reporter=text mocha"
Run Code Online (Sandbox Code Playgroud)
当我跑步 npm run nyctest
我的测试通过了,但是覆盖率为0%。
以下是测试,文件正在测试:
test.js
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
var application = require('../../../src/main/resources/static/js/components/app.js');
describe('sample return testing', function(){
it('should return true', function(){
application.sample.returnValue().should.equal(true);
})
});
Run Code Online (Sandbox Code Playgroud)
app.js
const sample = {
returnValue: function () {
return true;
}
};
module.exports = {sample};
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助。
istanbul ×10
javascript ×3
mocha.js ×3
angularjs ×2
node.js ×2
browserify ×1
coffeescript ×1
coveralls ×1
jasmine ×1
karma-runner ×1
nyc ×1
qunit ×1
react-jsx ×1
reactjs ×1
typescript ×1
unit-testing ×1