Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 ?

I'm new to grunt. I saw that he recognises the grunt qunit command. 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 command doesn't wait for the end result

like image 368
andrei Avatar asked Jan 13 '13 10:01

andrei


1 Answers

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.

like image 170
asgoth Avatar answered Sep 29 '22 19:09

asgoth