Grunt代码覆盖不起作用

我有下面这个运行mochatesting的grunt文件OK(运行grunt.js后我得到testing结果)现在我想添加一个代码,并使用https://github.com/taichi/grunt-istanbul模块。 但是当我运行grunt.js什么也没有发生,有什么想法?

我想要的只是之后,摩卡testing正在运行它将运行代码覆盖与一些报告 ? 任何新的代码覆盖将是伟大的

这是我的项目结构

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']); }; 

如果有摩卡的代码覆盖率可以帮助它,那么我希望在运行testing之后,我将能够看到所有代码覆盖率的报告。

我想覆盖文件夹utils和控制器 (所有的文件那里)如何configuration?

UPDATE

这是我用于茉莉花,我想我应该改用摩卡

 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/*", ] } }, 

我应该如何改变它? 我的testing语法是相似的(茉莉花/摩卡),我想要的只是运行我的testing,并在运行代码覆盖

我会给你一个间接的答案。 我已经获得了代码覆盖面,但是使用了不同的插件(还有摩卡)。 我不确定你是否愿意为mocha jasmine ,但是我会说,在遇到这个问题之前,我在各种代码覆盖的插件上苦苦挣扎。 我想你会同意这个configuration既简洁又明显。

你想要的插件是grunt-mocha-istbanbul ,下面是你的GruntfileconfigurationGruntfile

 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']); }