繁体   English   中英

使用Grunt.js运行mocha测试

[英]Using Grunt.js to run mocha tests

我已经设置了Grunt.js并且我编写了我想要使用mocha-phantomjs测试的测试。

我只需要帮助就可以编写一个可以运行的任务

$ mocha-phantomjs ./tests/index.html 

经过一番环顾后,我发现运行shell命令有一项艰巨的任务但是有没有更简单的方法呢?

我是新来的咕噜声。 我看到他认出了grunt qunit命令。 它内置了吗? 摩卡不可能有这样的东西吗? 我是否必须要求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来执行测试。

我知道这是旧的,但有一个grunt-mocha任务在phantomjs中运行mocha测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM