最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Grunt.js to run mocha tests - Stack Overflow

programmeradmin8浏览0评论

I have Grunt.js all set up and I wrote my tests which I want to test using 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 mands but isn't there a simpler way ?

I'm new to grunt. I saw that he recognises the grunt qunit mand. Is it built in ? Can't there be something like that for mocha ? Do I have to require child_process and execute it ?

Update: using child_process and executing the mand doesn't wait for the end result

I have Grunt.js all set up and I wrote my tests which I want to test using 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 mands but isn't there a simpler way ?

I'm new to grunt. I saw that he recognises the grunt qunit mand. Is it built in ? Can't there be something like that for mocha ? Do I have to require child_process and execute it ?

Update: using child_process and executing the mand doesn't wait for the end result

Share Improve this question edited Jan 13, 2013 at 10:51 andrei asked Jan 13, 2013 at 10:45 andreiandrei 8,58214 gold badges52 silver badges67 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

You can register test to a child process (like Yeoman is doing with 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.

I know this is old, but there is a grunt-mocha task that runs mocha tests in phantomjs.

发布评论

评论列表(0)

  1. 暂无评论