javascript - 使用 Grunt.js 运行 mocha 测试

标签 javascript phantomjs mocha.js gruntjs

我已经设置好 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/

相关文章:

javascript - jQuery 过滤器帮助

javascript - Jquery点击事件导致循环只执行一次

javascript - 使用 PhantomJs 登录后如何进入下一页?

javascript - 如何使用 webdriverIO 访问站点 JavaScript 函数

javascript - Rails/Javascript : JQueryVector Map Not Loading on Page Load

javascript - Casperjs/Phantomjs - 在加载 google plus 主页时挂起

node.js - Node 的 exec 调用是否会阻止 Meteor 应用程序?

模拟 super 代理发布请求,诺克不匹配

unit-testing - 如何使用 Mocha 测试 AngularJS 代码?

javascript - JS验证,为什么这段代码不起作用?