happo-plugin-gatsby

    1.0.0 • Public • Published

    happo-plugin-gatsby

    A happo.io plugin making it easy to add screenshot testing for Gatsby projects.

    Usage

    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

    Options

    pageFilter

    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;
      },
    });

    publicFolder

    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'),
    });

    Install

    npm i happo-plugin-gatsby

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    79.4 kB

    Total Files

    10

    Last publish

    Collaborators

    • trotzig