and*_*rei 8 javascript mocha.js phantomjs gruntjs
我已经设置了Grunt.js并且我编写了我想要使用mocha-phantomjs测试的测试.
我只需要帮助就可以编写一个可以运行的任务
$ mocha-phantomjs ./tests/index.html
Run Code Online (Sandbox Code Playgroud)
经过一番环顾后,我发现运行shell命令有一项艰巨的任务但是有没有更简单的方法呢?
我是新来的咕噜声.我看到他认出了这个grunt qunit命令.它内置了吗?摩卡不可能有这样的东西吗?我是否必须要求child_process并执行它?
更新:使用child_process并执行命令不会等待最终结果
asg*_*oth 12
您可以注册test一个子进程(如Yeoman正在使用Testacular):
// Alias the `test` task to run `mocha-phantomjs` instead
grunt.registerTask('test', 'run mocha-phantomjs', function () {
var done = this.async();
require('child_process').exec('mocha-phantomjs ./tests/index.html', function (err, stdout) {
grunt.log.write(stdout);
done(err);
});
});
Run Code Online (Sandbox Code Playgroud)
然后在终端中运行grunt test以执行测试.