npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unic/estatico-visual-regressions

v0.0.2

Published

Helper for visual regression tests with [Puppeteer](https://github.com/GoogleChrome/puppeteer). Uses [pixelmatch](https://github.com/mapbox/pixelmatch).

Downloads

6

Readme

@unic/estatico-visual-regressions

Helper for visual regression tests with Puppeteer. Uses pixelmatch.

Installation

$ npm install --save-dev @unic/estatico-visual-regressions

Usage

With Puppeteer

$ npm install --save-dev puppeteer
const puppeteer = require('puppeteer');
const visualRegressions = require('@unic/estatico-visual-regressions');

puppeteer.launch().then(async (browser) => {
  const page = await browser.newPage();

  await page.goto('http://...');
  // await page.goto('file://...');

  const results = await visualRegressions(page, {
    // Options
  });

  console.log(results);

  await browser.close();
})

With @unic/estatico-puppeteer

Add the following config to estatico-puppeteer's options:

{
  plugins: {
    interact: async (page, taskConfig) => {
      // Run tests
      const results = await visualRegressions(page, {
        dest: './test/results/screenshots',
        destDiff: './test/results/diff',
        srcReferences: './test/fixtures/references',
        viewports: taskConfig.viewports,
        getTargets: async (pageInstance) => {
          const targets = await pageInstance.$$('.demo');

          return targets;
        },
      });

      // Report results
      visualRegressions.log(results, console);
    },
  },
};

API

visualRegressions(page, options) => [{...}, {...}]

page

Instance of Puppeteer's Page Class

options

dest

Type: String Default: './screenshots/results'

Directory to save screenshots. Created if missing.

destDiff

Type: String Default: './screenshots/diff'

Directory to save combined images of screenshot, diff and expected result. Created if missing.

srcReferences

Type: String Default: './screenshots/references'

Directory where reference screenshots are located. If thetre are no reference images, they are created on the first run.

getTargets

Type: Function Default: page => [page],

Returns array of elements (or promises resolving to an element) to take screenshots from. Defaults to whole page. See more complex examples in tests.

getFileName

Type: Function Default:

(url, viewport, targetIndex) => {
  let fileName = path.basename(url, path.extname(url));

  // Append viewport name
  fileName = `${fileName}-${viewport}`;

  // Optionally append target index (in case of multiple targets per page)
  // eslint-disable-next-line no-restricted-globals
  fileName = `${fileName}${!isNaN(parseFloat(targetIndex)) ? `-${targetIndex}` : ''}`;

  return fileName;
}

Returns screenshot file name.

getTargets

Type: Object Default: null

Optional object of viewportName:{width:Number} pairs. Used for screenshot naming if present (see getFileName above).

pixelmatch

Type: Object Default:

{
  threshold: 0.5,
}

Options passed to pixelmatch, see https://github.com/mapbox/pixelmatch

threshold

Type: Number Default: 50

Threshold to treat differences as errors. Checks result from https://github.com/mapbox/pixelmatch

License

Apache 2.0.