A happo.io plugin making it easy to add screenshot testing for Gatsby projects.
Add the following to your .happo.js
configuration file:
// .happo.js
const happoPluginGatsby = require('happo-plugin-gatsby');
module.exports = {
// ...
plugins: [
happoPluginGatsby({
// options go here
}),
],
type: 'plain',
}
The Gatsby plugin for Happo takes screenshots on pre-built Gatsby pages.
Therefore, before you run happo run
you need to run a Gatsby build. Use the
INSTALL_CMD
environment
variable
to tell Happo to build before screenshooting. This could look something like
this (using Travis CI as an example):
# .travis.yml
script:
- INSTALL_CMD="yarn build" yarn happo-ci
By default, all Gatsby pages are included in the test suite. By providing a filter function, you can exclude certain pages. Here's an example excluding all "blog" pages:
happoPluginGatsby({
pageFilter: (pathToFile) => {
if (/\/blog/.test(pathToFile)) {
// exclude blog pages
return false;
}
return true;
},
});
Use this option to override where Happo looks for pre-built Gatsby pages. The
default is path.resolve(process.cwd(), 'public')
. Make sure to use an
absolute file path here.
const path = require('path');
happoPluginGatsby({
publicFolder: path.resolve(__dirname, 'custom-build'),
});