【发布时间】:2015-08-26 18:29:06
【问题描述】:
我想创建一个 grunt 任务,以便在代码更改时自动运行 jasmine 测试。对于 AMD 支持,我安装了grunt-template-jasmine-requirejs。我将这些行添加到我的 gruntfile 中:
connect: {
test : {
port : 8000
}
},
jasmine: {
jasmine_tests: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
host: 'http://127.0.0.1:8000/',
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: 'public/js/app/config/config.js'
}
}
}
},
现在我尝试通过键入 grunt jasmine 来开始我的测试。但我得到的只是:
运行“jasmine:jasmine_tests”(茉莉花)任务
通过 PhantomJS 测试 jasmine 规格
警告:PhantomJS 未能加载您的页面。使用 --force 继续。
由于警告而中止。
那里可能有什么问题?
我的目录结构:
- website3
- .grunt
+ grunt-contrib-jasmine
+ node_modules
- public
- js
- app
+ collections
- config
> config.js
+ ...
- views
+ ...
> AddVehicleView.js
> ...
+ libs
> index.html
+ server
- spec
+ helpers
- support
> jasmine.json
> AddVehicleViewSpec.js
> .bowerrc
> ...
> _SpecRunner.html
> Gruntfile.js
> package.json
【问题讨论】:
-
127.0.0.1:8000是否可以通过 http 访问?您如何提供文件?connect?使用--debug执行测试以获取更多信息。 -
要查看文件以进行更改,请查看
grunt-contrib-watch -
我在我的问题中添加了连接线。为了在给定端口提供要测试的文件,我还需要做什么?
-
是否需要通过ip接收测试数据?
-
如果你想在浏览器中执行你的测试,你必须通过 HTTP 服务它们。如果它们仅用于 node.js/io.js,则不需要。在您的连接配置中,您只指定一个端口,没有要服务的文件。看看文档:github.com/gruntjs/grunt-contrib-connect 毕竟你必须创建一个执行 connect AND jasmine 的任务:
grunt.registerTask('test', ['connect', 'jasmine'])并由grunt test执行它
标签: javascript node.js gruntjs requirejs jasmine