我的茉莉花节点测试执行了两次。
我从 Grunt 任务和 Jasmine 命令运行这些测试。结果是一样的,我的测试运行了两次。我的包.json :
{
"name": "test",
"version": "0.0.0",
"dependencies": {
"express": "4.x",
"mongodb": "~2.0"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-jasmine-node":"~0.3.1 "
}
}
这是我的 Gruntfile.js摘录:
grunt.initConfig({
jasmine_node: {
options: {
forceExit: true,
match: '.',
matchall: true,
extensions: 'js',
specNameMatcher: 'spec'
},
all: ['test/']
}
});
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.registerTask('jasmine', 'jasmine_node');
我的测试文件之一:
describe("Configuration setup", function() {
it("should load local configurations", function(next) {
var config = require('../config')();
expect(config.mode).toBe('local');
next();
});
it("should load staging configurations", function(next) {
var config = require('../config')('staging');
expect(config.mode).toBe('staging');
next();
});
it("should load production configurations", function(next) {
var config = require('../config')('production');
expect(config.mode).toBe('production');
next();
});
});
我有 2 个用于 4 个断言的测试文件
这是我的提示:
grunt jasmine
Running "jasmine_node:all" (jasmine_node) task
........
Finished in 1.781 seconds
8 tests, 8 assertions, 0 failures, 0 skipped
你有什么想法吗?
全部归功于 1.618。他在这里回答了这个问题:咕噜咕噜的茉莉花节点测试运行了两次
这看起来像一些错误的行为。快速解决方法是在Gruntfile
中配置jasmine_node
,如下所示:
jasmine_node: {
options: {
forceExit: true,
host: 'http://localhost:' + port + '/',
match: '.',
matchall: false,
extensions: 'js',
specNameMatcher: '[sS]pec'
},
all: []
}
键是all
参数。grunt
插件正在寻找名称中带有规范的文件。出于某种原因,它会在spec/
目录中和其他任何地方查找。如果指定spec
目录,则会选取其文件两次。如果您不指定,它只会设置一次,但随后您不能将 spec 放入任何非测试文件名中。