I'm using grunt to package my jQuery plugin. As part of the QUnit tests, I need to run a node command before the tests start to get a consistent result (something like process.env.TZ = 'Europe/London' as my plugin deals with timezones, so results will be different in different timezones).
So my question is: How can you run a node specific command as part of the qunit tests?
Thanks.
Create your own grunt task and call the qunit task from inside it:
var exec = require('child_process').exec;
grunt.registerTask('qunit-plus', 'Custom qunit task', function() {
exec('/usr/bin/mycmd', function(err, stdout, stderr) {
grunt.task.run('qunit');
});
});
Then call it with:
$ grunt qunit-plus
NOTE: untested.
Well, after a bit more research, I came across grunt-env @ https://github.com/onehealth/grunt-env
That allows different environment tasks to be defined in the gruntfile, e.g.
env: {
setTZ : {
TZ : 'Europe/London'
}
}
which will define the task env:setTZ to set the timezone. And yes, whilst setting the timezone can be problematic, advice appears to be that so long as you only do it the once, you're OK: https://groups.google.com/d/msg/nodejs/rt8EFR6gdi8/i2Fdp2vDPFQJ
you can set TZ just once, further changes won't get picked up.
Luckily, that's plenty sufficient for my use case, and it works just fine for me.