我正在使用mocha来运行纯粹在coffeescript中的测试.我还希望能够使用istanbul生成代码覆盖率报告.
注意,我--compilers coffee:coffee-script/register在mocha.opts文件中使用带有选项的mocha .
我遇到的问题是,不包括需要其他coffeescript源文件的测试.相反,我需要js文件,它被覆盖得很好.
我错过了什么吗?
我的npm test命令是:istanbul test --report html -x 'vendor/**' _mocha.我npm test --coverage用来强制执行伊斯坦布尔的覆盖效用.
这是一个mocha测试的样本(./test/test.coffee):
# Project
# require ../src/main.coffee
main = require('../src/main')
# Chai
chai = require('chai')
assert = chai.assert
should = chai.should()
expect = chai.expect
describe 'something', (done) ->
describe "when given something", ->
it "should do this", ->
# tests using chai API here
something = new main()
Run Code Online (Sandbox Code Playgroud) 我似乎无法让Coveralls显示我的node.js项目的报道。这是我的设置:
我创建了以下.travis.yml文件:
language: node_js
node_js:
- 0.11
- 0.10
after_success:
npm run coveralls
Run Code Online (Sandbox Code Playgroud)
在我的package.json文件中有以下脚本:
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
Run Code Online (Sandbox Code Playgroud)
Coveralls可以识别所有受影响的文件(index.js和我的lib文件夹),但不会显示任何文件的任何覆盖范围。
这是工作服上的构建外观:https : //coveralls.io/builds/1851378
如果我在本地运行它,这是伊斯坦布尔的输出(只是为了证明实际上有一些测试范围,而且生成的lcov.info文件看起来也不错):
=============================== Coverage summary ===============================
Statements : 87.85% ( 253/288 )
Branches : 75.34% ( 55/73 )
Functions : 86.25% ( 69/80 )
Lines : 87.85% ( 253/288 )
================================================================================
Run Code Online (Sandbox Code Playgroud)
关于我可能会丢失的哪些建议以正确显示工作服的覆盖范围?
顺便说一句,我还尝试使用存储库令牌和node-coveralls将覆盖结果上传到本地的工作服。结果是一样的...
说我有以下代码:
define([
'a'
], function(a) {
return {
initialize: function() {
},
stuff: function() {
}
};
});
Run Code Online (Sandbox Code Playgroud)
据伊斯坦布尔报道,只测试了1/3的功能.这有点真实,因为我只进行了一次测试main.initialize.
我怎样才能让伊斯坦布尔忽略用于定义回调的函数?
编辑:附加Gruntfile.js配置
jasmine: {
coverage: {
src: 'src/assets/js/app/**/*.js',
options: {
specs: 'src/assets/js/spec/**/*Spec.js',
host: 'http://127.0.0.1:8000/',
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
//files: 'src/assets/js/app/**/*.js',
coverage: 'bin/coverage/coverage.json',
report: [
{type: 'html', options: {dir: 'src/coverage/html'}},
{type: 'text-summary'}
],
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'src/assets/js',
paths: {
/* 'jquery': 'lib/jquery',
'underscore': 'lib/lodash',
'text': 'lib/text',
'i18n': 'lib/i18n',*/
}
}
}
},
keepRunner: true …Run Code Online (Sandbox Code Playgroud) 我无法让伊斯坦布尔与茉莉花合作:
这是我的目录结构
ttm-jira
- package.json
- spec
- jira-spec.js
Run Code Online (Sandbox Code Playgroud)
我的package.json看起来像这样:
{
"name": "ttm-jira",
"version": "1.0.0",
"description": "nodeJS module to provide access to the JIRA REST API",
"author": {
"name": "...",
"url" : "...."
},
"main": "jira.js",
"private": true,
"repository": {
"type": "git",
"url" : "https://........git"
},
"bugs": {
"url" : "https://jira2........."
},
"scripts": {
"test" : "npm run code-coverage && npm run unit-test",
"unit-test" : "jasmine-node . --autotest --captureExceptions --watch",
"code-coverage": "istanbul cover --include-all-sources"
},
"devDependencies": {
"istanbul" : "^0.4.0", …Run Code Online (Sandbox Code Playgroud) 关于使用伊斯坦布尔进行集成测试的报道很少。当我通过摩卡测试时,我得到了No coverage information was collected, exit without writing coverage information。
我要做的第一件事是检测所有源代码:
? istanbul instrument . -o .instrument
Run Code Online (Sandbox Code Playgroud)
就我而言,这是一种Docker化的REST微服务,我编写了Mocha测试以对其进行运行以验证其一旦部署。我期望伊斯坦布尔能为我提供该Node服务的源代码覆盖范围。
第二步,我执行此命令以在我的检测代码上运行节点:
? istanbul cover --report none .instrument/server.js
Run Code Online (Sandbox Code Playgroud)
之后,我使用我的主src目录中的以下内容运行我的测试,如下所示(带有结果):
? istanbul cover --report none --dir coverage/unit node_modules/.bin/_mocha -- -R spec ./.instrument/test/** --recursive
swagger-tests
#createPet
? should add a new pet (15226ms)
#getPets
? should exist and return an Array (2378ms)
? should have at least 1 pet in list (2500ms)
? should return error if search not name or id
? …Run Code Online (Sandbox Code Playgroud) 我正在使用伊斯坦布尔进行量角器测试的代码覆盖.
在检测源代码的过程中,我收到"无法解析,意外令牌"错误,并在完成错误后发现"导入"令牌正在创建问题.
一直在研究Angular2和Typescript.
我正在使用命令:istanbul instrument ./dir/to/instrument/ -o ./out/dir/
伊斯坦布尔默认使用esprima解析器在检测之前解析代码.这是一个解析错误,但我无法找到解决它的任何解决方案.
伊斯坦布尔:v0.4.5
Esprima解析器:v3.1.3
我的小组正在使用以下前端堆栈构建应用程序:
我们开始vue-cli为我们的项目创建一个Webpack模板.在大多数情况下,一切都很顺利.我们可以使用Ava 使用vue-node对单独的.vue组件文件进行单元测试.但是,通过nyc生成的测试覆盖率报告存在问题.下面是我们的package.json文件的片段,其中定义了相关的nyc和ava部分:
"nyc": {
"exclude": [
"build",
"config",
"static",
"tests"
],
"extension": [
".js",
".vue"
]
},
"ava": {
"require": [
"./tests/unit/helpers/setup.js",
"ignore-styles"
]
},
Run Code Online (Sandbox Code Playgroud)
问题是Uncovered Lines下列出的行#s 不存在.该.vue文件只有402线长,所以我想不通的地方在纽约报告这些线#分别来自何方.
任何帮助将不胜感激,并提前感谢您.
当通过angular-cli(ng test -cc)运行具有代码覆盖率的测试时,因果报应抛出以下错误。罪魁祸首似乎是伊斯坦布尔代码覆盖率模块,因为在没有-cc的情况下运行测试不会导致任何错误。
错误(我用***替换了本地路径):
at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16),Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"' (1:0)
at Parser.pp$5.raise (***\node_modules\babylon\lib\index.js:4454:13)
at Parser.pp$1.parseStatement (***\node_modules\babylon\lib\index.js:1881:16)
at Parser.parseStatement (***\node_modules\babylon\lib\index.js:5910:22)
at Parser.pp$1.parseBlockBody (***\node_modules\babylon\lib\index.js:2268:21)
at Parser.pp$1.parseTopLevel (***\node_modules\babylon\lib\index.js:1778:8)
at Parser.parse (***\node_modules\babylon\lib\index.js:1673:17)
at Object.parse (***\node_modules\babylon\lib\index.js:7305:37)
at Instrumenter.instrumentSync (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
at Instrumenter.instrument (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16)
at Compiler.compiler.plugin (***\node_modules\@angular\cli\plugins\karma-webpack-throw-error.js:10:23)
at Compiler.applyPlugins (***\node_modules\tapable\lib\Tapable.js:61:14)
at Watching._done (***\node_modules\webpack\lib\Compiler.js:92:17)
at onCompiled (***\node_modules\webpack\lib\Compiler.js:51:17)
at ***\node_modules\webpack\lib\Compiler.js:494:13
at next (***\node_modules\tapable\lib\Tapable.js:202:11)
at Compiler.<anonymous> (***\node_modules\webpack\lib\CachePlugin.js:62:5)
at Compiler.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:206:13)
at ***\node_modules\webpack\lib\Compiler.js:491:10
at Compilation.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:195:46) …Run Code Online (Sandbox Code Playgroud) 我想从测试类中模拟这些全局变量的值
//index.js
/* Globals variables */
var documentLoaderGlobal = {
region: process.env.ElasticSearchRegion,
endpoint: process.env.ElasticSearchEndpoint,
index: process.env.ElasticSearchIndex,
mapping: process.env.ElasticSearchMapping,
dynamoDBTable:process.env.DynamoDBTable
};
Run Code Online (Sandbox Code Playgroud)
我的测试课是
var rewire = require("rewire");
var myModule = rewire("./index.js");
var region="us-east-1";
myModule.__set__("documentLoaderGlobal.region", region);
Run Code Online (Sandbox Code Playgroud)
当我运行测试用例时,值没有被嘲笑。
知道我在做什么错吗?还是我错过了什么?
我有一个使用QUnit的最小浏览器JavaScript项目,该项目是我使用QUnit文档提供的示例编写的。这是源代码:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="qunit-2.6.2.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="qunit-2.6.2.js"></script>
<script src="example.js"></script>
<script src="tests.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
example.js
/**
* Returns a sum of two numbers
*
* @param {number} - first number
* @param {number} - second number
*
* @returns {number}
*/
function mysum(arg1, arg2) {
var ret;
ret = arg1 + arg2;
return ret;
}
mysum(1, 2);
Run Code Online (Sandbox Code Playgroud)
tests.js
QUnit.test( "hello test", function( assert ) …Run Code Online (Sandbox Code Playgroud) istanbul ×10
node.js ×5
javascript ×4
mocha.js ×3
unit-testing ×2
angular ×1
angular-cli ×1
ava ×1
coffeescript ×1
coveralls ×1
esprima ×1
import ×1
protractor ×1
qunit ×1
requirejs ×1
travis-ci ×1
vue.js ×1
webpack ×1