Use TestCafe with Grunt
You can easily integrate TestCafe with the Grunt.js task runner. This recipe shows how to configure a Grunt task to run TestCafe tests.
Note
You need to have Grunt v0.4 or newer to use it with TestCafe.
Step 1 - Install TestCafe Grunt Plugin
Assuming that you already have Grunt installed in your project, you also need to install the TestCafe Grunt plugin.
npm install grunt-testcafe --save-dev
Step 2 - Adding a TestCafe Task to Gruntfile
In Gruntfile.js
, add a property named testcafe
to the data object passed to the grunt.initConfig
method.
grunt.initConfig({
testcafe: {
test: {
options: {
files: ['tests/*.js'],
browsers: ['chrome']
}
}
}
});
This code declares a task that opens Google Chrome and runs tests from all test files in the tests
directory.
For more information about the available options, see Grunt Plugin Options.
You also need to add a line of code that loads the TestCafe plugin. Put this below the initConfig
method call.
grunt.loadNpmTasks('grunt-testcafe');
Step 3 - Running the Grunt Task
Now you can run the Grunt task from the console with a single command.
grunt testcafe
Acknowledgements
Thanks to Martin Cermak for making the TestCafe Grunt plugin.