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 badges2 Answers
Reset to default 12You 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.