简体   繁体   English

使用Grunt.js运行mocha测试

[英]Using Grunt.js to run mocha tests

I have Grunt.js all set up and I wrote my tests which I want to test using mocha-phantomjs. 我已经设置了Grunt.js并且我编写了我想要使用mocha-phantomjs测试的测试。

I just need help to write a task that will run 我只需要帮助就可以编写一个可以运行的任务

$ mocha-phantomjs ./tests/index.html 

After some looking around I saw that there is a grunt task for running shell commands but isn't there a simpler way ? 经过一番环顾后,我发现运行shell命令有一项艰巨的任务但是有没有更简单的方法呢?

I'm new to grunt. 我是新来的咕噜声。 I saw that he recognises the grunt qunit command. 我看到他认出了grunt qunit命令。 Is it built in ? 它内置了吗? Can't there be something like that for mocha ? 摩卡不可能有这样的东西吗? Do I have to require child_process and execute it ? 我是否必须要求child_process并执行它?

Update: using child_process and executing the command doesn't wait for the end result 更新:使用child_process并执行命令不会等待最终结果

You can register test to a child process (like Yeoman is doing with Testacular): 您可以将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);
    });
  });

In the terminal you then just run grunt test to execute the tests. 在终端中,您只需运行grunt test来执行测试。

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

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

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