我已经设置好 Grunt.js,并编写了我想使用 mocha-phantomjs 进行测试的测试。
我只需要帮助来编写一个可以运行的任务
$ mocha-phantomjs ./tests/index.html
环顾四周后,我发现有一个运行 shell 命令的繁重任务,但没有更简单的方法吗?
我是新手。我看到他认出了 grunt qunit
命令。它是内置的吗? Mocha 不能有类似的东西吗?我是否必须要求 child_process 并执行它?
更新:使用child_process并执行命令不等待最终结果
最佳答案
您可以将 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);
});
});
然后在终端中运行 grunt test
来执行测试。
关于javascript - 使用 Grunt.js 运行 mocha 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14302702/