我有下面的grunt文件,它运行mocha测试OK (我在运行grunt.js后获得测试结果),现在我想添加一个代码,并使用https://github.com/taichi/grunt-istanbul模块。但是当我运行grunt.js时什么都不会发生,知道吗?
我想要的仅仅是在摩卡测试运行之后,它将运行代码覆盖和一些报告,?任何新的代码覆盖率都将是很棒的。
这是我的项目结构
myApp
-server.js
-app.js
-test
-test1.spec
-test2.spec
-test-reports
-grunt.js
-utils
-file1.js
-file2.js
-controller
-file1.js
-file2.js这是我尝试过的代码
module.exports = function (grunt) {
var path = require('path');
process.env.RESOURCE_PATH_PREFIX = "../";
var d = new Date();
var datestring = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " +
d.getHours() + ":" + d.getMinutes();
var npmCommand = path.dirname(process.execPath).concat('/npm');
var reportDir = "./test-reports/" + datestring;
grunt.initConfig({
jasmine_nodejs: {
// task specific (default) options
options: {
specNameSuffix: ["-spec.js"],
helperNameSuffix: "helper.js",
useHelpers: false,
stopOnFailure: false,
reporters: {
console: {
colors: true,
},
junit: {
savePath: "./test-reports",
filePrefix: "testresult",
}
}
},
test: {
specs: [
"test/*",
]
},
makeReport: {
src: './test-reports/coverage.json',//should I create this file?or its created automatically ?
options: {
type: ['lcov', 'html'],
dir: reportDir,
print: 'detail'
}
},
coverage: {
APP_DIR_FOR_CODE_COVERAGE: "./utils/*.js",//HERE IS THE PATH OF THE UTILS Folder which all the js login which I want to test there
clean: ['build'],
instrument: {
files: tasks,//WHAT IS TASKS????
options: {
lazy: true,
basePath: 'build/instrument/'//I DONT KNOW WHAT IT IS???
}
},
reloadTasks: {
rootPath: 'build/instrument/tasks'//SHOULD I USE IT????
},
storeCoverage: {
options: {
dir: reportDir
}
}
}
});
grunt.loadNpmTasks('grunt-jasmine-nodejs');
grunt.loadNpmTasks('grunt-istanbul');
grunt.registerTask('default', ['jasmine_nodejs']);
grunt.registerTask('cover', ['instrument', 'test',
'storeCoverage', 'makeReport']);
};如果有摩卡代码覆盖,可以帮助它也将是伟大的,我希望在我运行测试后,我将能够看到报告与所有的代码覆盖。
我希望覆盖范围将是为文件夹实用程序和控制器(所有文件在那里),我应该如何配置?
更新
这是我给贾斯敏用的,我想我应该换成摩卡。
jasmine_nodejs: {
// task specific (default) options
options: {
specNameSuffix: ["-spec.js"], // also accepts an array
helperNameSuffix: "helper.js",
useHelpers: false,
stopOnFailure: false,
reporters: {
console: {
colors: true,
cleanStack: 1, // (0|false)|(1|true)|2|3
verbosity: 4, // (0|false)|1|2|3|(4|true)
listStyle: "indent", // "flat"|"indent"
activity: false
},
junit: {
savePath: "./test-reports",
filePrefix: "testresult",
consolidate: true,
useDotNotation: true
}
}
},
test: {
// target specific options
options: {
useHelpers: false
},
// spec files
specs: [
"test/*",
]
}
},我应该如何改变它呢?,我的测试的语法是相似的(茉莉/摩卡),我想要的只是简单地运行我的测试和运行代码覆盖率之后。
发布于 2016-07-14 20:37:20
我会给你一个间接的答案。我以前也有过代码覆盖率,但是使用了不同的插件(还有摩卡)。我不确定您是否愿意将jasmine替换为mocha,但我要说的是,在遇到这个插件之前,我遇到了各种各样的代码覆盖插件。我想你会同意这个配置既简洁又明显。
您想要的插件是咕噜-摩卡-黑头党,下面是Gruntfile的示例配置
module.exports = function(grunt) {
grunt.initConfig({
clean: ['coverage'],
mocha_istanbul: {
coverage: {
src: 'test',
options: {
timeout: 20000,
'report-formats': 'html',
print: 'summary',
check: {
lines: 90,
statements: 90,
functions: 100,
branches: 80
}
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.registerTask('default', ['clean', 'mocha_istanbul']);
}https://stackoverflow.com/questions/38337900
复制相似问题