[英]How to execute jasmine tests for node modules from grunt
我想在Grunt版本中為node.js模塊運行一些Jasmine 2.x測試。 我的設置如下所示:
SRC / foo.js
exports.bar = 23;
投機/ foo.spec.js
var foo = require("../src/foo.js");
define("foo", function() {
it("exports bar as 23", function() {
expect(foo.bar).toBe(23);
});
});
與grunt-contrib-jasmine節點模塊系統不可用,我得到
>> ReferenceError: Can't find variable: require at
>> spec/foo.spec.js:1
有grunt-jasmine-node ,但是它取決於未維護的jasmine-node ,包括Jasmine 1.3.1,因此這不是一個選擇。
Jasmine 開箱即 jasmine.json
支持node.js ,通過在spec
目錄中包含文件jasmine.json
,我可以使用jasmine
cli運行測試。 是否有任何干凈的方法也可以通過grunt運行相同的測試?
您可以使用grunt-exec , 它只執行值,就像在命令行上鍵入一樣:
module.exports = function (grunt) {
grunt.initConfig({
exec: {
jasmine: "jasmine"
},
env: {
test: {
NODE_ENV: "test"
}
}
});
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks("grunt-env");
grunt.registerTask("test", [
"env:test",
"exec:jasmine"
]);
};
這將使您可以使茉莉花保持最新狀態,並與其他艱苦的任務一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.