Lately I had to support our front end team by adding the visual regression test tool BackstopJS to their build environment. Since they used already Grunt as their build tool, the simple task was to run BackstopJS from Grunt. As it turned out, with the new 2.* version of BackstopJS this is far simpler than expected.
Previous versions of BackstopJS use Gulp under the hood. Consequently existing Grunt plugins for BacktopJS simply invoke the corresponding Gulp tasks.
With the new BackstopJS version we can install BackstopJS locally, i.e. it is very easy to build an integration for Grunt like this:
npm install --save-dev backstopjs
Gruntfile.js
var backstopjs = require('backstopjs');
grunt.registerTask('backstop', 'BackstopJS integration', function(cmd) {
// cmd is either 'reference', 'test', or 'openReport'
var done = this.async();
backstopjs(cmd).then(function() {
done(true);
}).catch(function() {
done(false);
});
});
With this we can use the Grunt tasks
backstop:reference
for creating the reference imagesbackstop:test
for running the testsbackstop:openReport
for displaying the test resultSimple, isn't it? No need for an external plugin!
I'm interested in your feedback. Send me a mail or ping me on twitter.