- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试学习这个自动化单元测试的骗局。我想使用 Grunt 自动运行我的 Mocha 测试,并将测试结果输出到一个文件中。据我所知,我需要使用 grunt-mocha-cov为了这。我有点让它工作了:当测试通过时,Grunt 写出结果文件 OK。但是当其中一个失败时,我得到这个:
Running "mochacov:all" (mochacov) task
Warning: Use --force to continue.
Aborted due to warnings.
并且没有创建文件。谁能告诉我哪里出错了?
我的项目是这样组织的:
我的测试文件夹包含一个文件 test.js,如下所示:
var chai = require("chai"),
assert = chai.assert,
expect = chai.expect;
var foobar = {
sayHello: function() {
return 'Hello World!';
}
}
describe('Foobar', function() {
describe('#sayHello()', function() {
it('should work with assert', function() {
assert.equal(foobar.sayHello(), 'Hello World!');
});
it('should work with expect', function() {
expect(foobar.sayHello()).to.equal('Hello Worlxd!');
});
});
});
package.json 有这个:
{
"name": "GruntTest",
"version": "0.0.1",
"private": true,
"devDependencies": {
"grunt": "~0.4.1",
"grunt-mocha-cli": "~1.3.0",
"grunt-contrib-qunit": "~0.3.0",
"grunt-contrib-jshint": "~0.6.4",
"grunt-mocha": "~0.4.1",
"should": "~2.0.1",
"chai": "~1.8.1",
"grunt-mocha-cov": "0.0.7"
},
"description": "Grunt Test",
"main": "grunt.js",
"dependencies": {
"grunt": "~0.4.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD"
}
这是我的 Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochacov: {
options: {
reporter: 'XUnit',
require: ['should'],
output: 'test-results.xml',
bail: false
},
all: ['test/*.js']
}
});
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.registerTask('default', ['mochacov']);
};
编辑
根据 xavier 的建议,我使用 mochacov 和 xunit-file reporter 完成了它。这是我新改进的 Gruntfile,以防对其他人有用:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mochacov: {
options: {
reporter: 'xunit-file',
require: ['should'],
bail: false
},
all: ['test/*.js']
}
});
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.registerTask('default', ['mochacov']);
};
终端发出警告“因警告而中止”,但 mochacov 创建了一个包含测试结果的文件 xunit.xml。
最佳答案
试试那个:https://github.com/yaymukund/grunt-simple-mocha
与以下记者之一:http://visionmedia.github.io/mocha/#reporters
或类似这样的内容:https://github.com/peerigon/xunit-file
但事实是,您应该从服务器端放弃 grunt,并使用 Makefile!
这是我用的经典的:
MOCHA="node_modules/.bin/mocha"
_MOCHA="node_modules/.bin/_mocha"
JSHINT="node_modules/.bin/jshint"
ISTANBUL="node_modules/.bin/istanbul"
TESTS=$(shell find test/ -name "*.test.js")
clean:
rm -rf reports
test:
$(MOCHA) -R spec $(TESTS)
jshint:
$(JSHINT) src test
coverage:
@# check if reports folder exists, if not create it
@test -d reports || mkdir reports
$(ISTANBUL) cover --dir ./reports $(_MOCHA) -- -R spec $(TESTS)
.PHONY: clean test jshint coverage
就是这样,只需安装 mocha、jshint 和 istanbul 作为开发依赖项就可以了
有些人会告诉你全局安装这些工具,但这取决于你
关于javascript - Grunt 运行 mocha - 测试失败时中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19362954/
我安装了 grunt 和 grunt cli,但仍然出现命令未找到错误 { "name": "angulartdd", "version": "1.0.0", "description":
我有一个使用“grunt-contrib-watch”和“grunt-exec”的 Grunt.js 文件,这是因为我想以一种独特的方式使用 handlebars 预编译器的一些自定义功能。 代码:
我正忙于尝试完成我正在运行的部署脚本。它可能有一半的时间有效,而且令人沮丧,因为我使用的大部分代码都不是我写的。我真的希望有一个我可以执行的较低级别的解决方法。 基本上发生的事情是我正在尝试执行 5
我想像在文档中定义的那样将参数传递给grunt-shell: module.exports = function(grunt) { // Configure Grunt grunt.initConfi
背景 我正在使用 Yeoman webapp 来搭建我的前端。 在 gruntfile 中,他们使用 grunt-rev 和 grunt-usemin Grunt-rev 将“修改”我的 Assets
我已经设置了grunt-eslint在我的 gruntfile.js 中,但是当我运行“grunt eslint”时,什么也没有发生。该任务看似即将开始,但 15 分钟后却停滞不前。 我的所有其他任务
我最近开始使用 grunt 做 JS 项目。 我有一个名为“grunt-contrib-jasmine”的插件用于 Jasmine 测试。我工作得很好,但我无法在浏览器中通过 specrunner 运
谁能告诉我这里做错了什么(我是 grunt 的新手)一个大学给我提供了一个基本的 gruntfile 设置 我已经安装了 node、js 和 grunt,但我不知道如何安装各种包(uglify、con
我正在尝试使用 grunt-contrib-watch和 grunt-rsync将任何文件更改上传到我的开发服务器。这是我的设置: var path = require('path'); module
尝试使用grunt-kill创建一个任务来终止我的 server-scorm 任务,并最终终止所有相关任务。这些说明非常短,因为它假设我知道有关 PID 文件的所有信息(我不知道,不是开发人员的错误)
我要么脑子一片空白,要么本该更复杂。 我正在尝试从 Grunt 任务运行 grunt-init,如下所示: grunt.registerTask('init', 'Scaffold various a
我有一个从玩家发射的射弹预制件,当它与“边界”碰撞时,它应该摧毁自己,当它击中“咕噜声”时,它应该摧毁自己和咕噜声。但是,当它碰到边界时,它会破坏自身和边界的对撞机。我创建了一个自定义标签脚本,允许我
module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),
我已经加入了一个非营利性开源项目,想帮点忙,但我对 Grunt 不熟悉。我做了一些研究,但无法弄清楚为什么配置不起作用。 这是我正在尝试使用的插件。它允许应用多个后处理器,但我现在只需要 Autopr
下面的代码读取app/modules/中的每个子目录js的内容(例如app/modules/module1/js/, app/modules/module2/js/, aso.) 此脚本在不使用最后一
我正在尝试使用 grunt-exec 运行一个 javascript 测试运行程序,并传入一个已部署的链接变量。 我尝试通过使用 exec:setLink 设置环境变量 grunt.option('l
当我使用 grunt-contrib-watch 更改我的 js 文件时,我试图让 Grunt 重新加载它们。这是我的 Gruntfile: module.exports = function(gru
所以我的意思是: grunt.registerTask('default', ['default']); // CLI: grunt grunt.registerTask('serve', ['ser
我想创建一个通用的顶级 Gruntfile.js,配置为监视较少的文件更改。当less文件发生变化时,我想将其编译为css,然后在浏览器中实时加载css文件。我的功能正常,但我必须为每个项目复制 Gr
我正在使用 grunt-xmlpoke 更新 xml 文件。 xml 文件的路径作为参数提供。问题是文件部分中的第一个 WebConfigPath (键)被视为字符串。它更新了我的 xml 文件的本地
我是一名优秀的程序员,十分优秀!