Git Product home page Git Product logo

mugshot's Introduction

logo

Framework independent visual testing library

Build status codecov npm type definitions License

View Docs


Introduction

Mugshot is a node library for doing visual regression testing. The way screenshots are taken, processed, compared and stored is entirely customizable. You can use it to write visual regression tests for websites, mobile apps, native apps etc. Moreover, Mugshot doesn't impose any preferences on how you write or execute the tests, it just gives you an assertion that you can call however and whenever you want.

Features

  • Framework independent so you can choose your favorite tools or plug it into your existing testing suite.
  • Produces diff images if a test fails.
  • Throws on missing baselines (can be toggled through options).
  • Everything is pluggable (screenshotter, differ, storage etc.).

Installation

npm install --save-dev mugshot

Or with yarn

yarn add -D mugshot

Depending on how you want to take screenshots, you'll need a Screenshotter implementation. Mugshot bundles a WebdriverScreenshotter that you can use with Webdriver compatible clients e.g. Selenium or Appium. Each client might need an adapter that translates its API to the interface that Mugshot expects. The following adapters are available:

Package Version
@mugshot/webdriverio npm
@mugshot/puppeteer npm
@mugshot/playwright npm

Motivation

Manually checking one component for unexpected visual changes is hard. Doing it across your entire UI is harder. Doing it in multiple browsers/devices is even harder. Making sure everyone on your team does it is the hardest.

Mugshot aims to automate that process. It offers a simple API that lets you compare an existing baseline screenshot with a fresh screenshot and make sure they're identical. If they're not you'll get a diff image highlighting the differences. You can then commit it as the new baseline if the changes are expected, or fix the code and rerun the tests.

Expected Actual Diff
expected actual diff

Docs

View Docs

License

MIT

mugshot's People

Contributors

adela-istrate-hs avatar andrei-picus-hs avatar dependabot[bot] avatar flavius-tirnacop-hs avatar flore77 avatar nighttrax avatar ovidiu-bute-hs avatar ovidiu-chereches-hs avatar renovate-bot avatar renovate[bot] avatar tricoder42 avatar valentin-radulescu-hs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mugshot's Issues

Throw a different error when baseline is missing and acceptFirstBaseline is false

Need

As a user
I want clear error messages
So that I can quickly identify what the problem is.

Deliverables

Given that there is no baseline
And `acceptFirstBaseline` is set to `false`
When I run mugshot
Then it will throw with an error telling me that the baseline is missing.

Solution

Don't call the done callback with no error when acceptFirstBaseline is false.

if (acceptFirstBaseline) {
  done(null, {isEqual: true, baseline: baselinePath});
} else {
  done(new Error('Baseline missing'));
}

TODO

  • write failing test
  • make it pass

Fix error reporting when a selector is provided

Need

As a user
When a visual test fails
I want to see the baseline name and the selector
So that I know what went wrong.

Problem

Now it shows a message like this:
AssertionError: expected baseline and screenshot of { Object (name, selector) } to be identical

Solution

Log the actual name and selector.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency chai to ~4.5.0
  • chore(deps): update dependency eslint to ~8.57.0
  • chore(deps): update dependency jest to ~29.7.0
  • chore(deps): update dependency playwright to ~1.46.0
  • chore(deps): update dependency puppeteer to ~19.11.0
  • chore(deps): update dependency webdriverio to ~7.36.0
  • chore(deps): update pnpm/action-setup action to v2.4.1
  • fix(deps): update dependency @algolia/client-search to ~4.24.0
  • fix(deps): update dependency @types/node to ~18.19.0
  • fix(deps): update dependency fs-extra to ~11.2.0
  • fix(deps): update dependency typedoc-plugin-markdown to ~3.17.0
  • fix(deps): update dependency webpack to ~5.93.0
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update codecov/codecov-action action to v4
  • chore(deps): update dependency @tdd-buffet/jest-config to v6
  • chore(deps): update dependency chai to v5
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency lerna to v8
  • chore(deps): update dependency puppeteer to v23
  • chore(deps): update dependency strong-mock to v9
  • chore(deps): update pnpm/action-setup action to v4
  • fix(deps): update dependency @algolia/client-search to v5
  • fix(deps): update dependency @tsconfig/docusaurus to v2
  • fix(deps): update dependency @types/node to v20
  • fix(deps): update dependency clsx to v2
  • fix(deps): update dependency docusaurus-plugin-typedoc to v1
  • fix(deps): update dependency pixelmatch to v6
  • fix(deps): update dependency prism-react-renderer to v2
  • fix(deps): update dependency typedoc-plugin-markdown to v4
  • fix(deps): update docusaurus monorepo to v3 (major) (@docusaurus/core, @docusaurus/module-type-aliases, @docusaurus/preset-classic)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • codecov/codecov-action v3
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • codecov/codecov-action v3
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • codecov/codecov-action v3
  • actions/checkout v3
  • pnpm/action-setup v2.2.4
  • actions/setup-node v3
  • codecov/codecov-action v3
npm
package.json
  • @nighttrax/eslint-config-ts ~12.0.0-alpha.3
  • @tdd-buffet/jest-config ~5.0.1
  • @tdd-buffet/tsconfig ~1.0.5
  • @tdd-buffet/selenium ~0.4.21
  • @types/jest ~29.5.0
  • @types/node ~18.15.0
  • eslint ~8.38.0
  • jest ~29.5.0
  • lerna ~6.6.0
  • strong-mock ~8.0.0
  • typescript ~4.9.0
packages/contracts/package.json
  • @types/chai ~4.3.0
  • chai ~4.3.0
  • fs-extra ~11.1.0
  • jimp ~0.22.7
  • @types/fs-extra ~11.0.0
  • typescript ~4.9.0
packages/jimp/package.json
  • @jimp/core ~0.16.1
  • @jimp/custom ~0.16.1
  • @jimp/plugin-color ~0.16.1
  • @jimp/plugin-crop ~0.22.0
  • @jimp/png ~0.22.0
  • typescript ~4.9.0
packages/mugshot/package.json
  • @types/fs-extra ~11.0.0
  • @types/is-ci ~3.0.0
  • @types/node ~18.15.0
  • fs-extra ~11.1.0
  • is-ci ~3.0.0
  • pixelmatch ~5.3.0
  • @types/chai ~4.3.0
  • @types/pixelmatch ~5.2.0
  • chai ~4.3.0
  • playwright ~1.32.0
  • strong-mock ~8.0.0
  • typescript ~4.9.0
packages/playwright/package.json
  • playwright ~1.32.0
  • typescript ~4.9.0
  • playwright ^1.3.0
packages/puppeteer/package.json
  • puppeteer ~19.8.0
  • typescript ~4.9.0
  • puppeteer ^19.0.0
packages/webdriverio/package.json
  • typescript ~4.9.0
  • webdriverio ~7.30.0
  • webdriverio ^7.0.0
packages/website/package.json
  • @algolia/client-search ~4.17.0
  • @docusaurus/core ~2.0.0-beta.14
  • @docusaurus/module-type-aliases ~2.0.0-beta.14
  • @docusaurus/preset-classic ~2.0.0-beta.14
  • @mdx-js/react ~1.6.21
  • @tsconfig/docusaurus ~1.0.2
  • @types/react ~17.0.39
  • @types/react-dom ~17.0.19
  • @types/react-router-dom ~5.3.0
  • clsx ~1.2.0
  • docusaurus-plugin-typedoc ~0.18.0
  • prism-react-renderer ~1.3.0
  • react ~17.0.2
  • react-dom ~17.0.2
  • typedoc ~0.23.28
  • typedoc-plugin-markdown ~3.14.0
  • typescript ~4.9.0
  • url-loader ~4.1.1
  • webpack ~5.78.0

  • Check this box to trigger a request for Renovate to run again on this repository

Change threshold of mugshot comparison

I'm currently using mugshot for visual regression testing with webdriverio.
However, I could not find a working way to change the threshold of the comparison.

I know that the PixelDifferOptions include the threshold, however, there is no documentation about how to use it. I cannot inject it into the mugshot constructor, I cannot change the mugshots threshold via PNGDiffer since it doesn't have the required attribute.

So I am asking for a constructor, that takes the PixelDiffer insteaf of a constructor that doesn't seem to use the PixelDiffers threshold.
If it does already do so, then a documentation about how to use it or where to use it would be beneficial in order to use mugshot properly.

Here is the little test I'm running with webdriverio and chai.

it('visual regression tests', async () => {
await browser.setWindowSize(1280, 1024);
await browser.url('/?action=setTitle');
await browser.pause(1000);
const differ = new PixelDiffer({threshold: 1});
const mugshot = new Mugshot(
new BrowserScreenshotter(
new WebdriverIOAdapter(browser)
),
new FsStorage('./screenshots/title-tests'),
{ createMissingBaselines: true},
);
const result = await mugshot.check('title-test');
assert.isTrue(result.matches, 'title matches');
})

Error handling

Need

As a user
I want good error reporting
So that I can get quick feedback on where my program is doing stuff wrong.

Deliverables

  • An integration test suite that checks that all errors are returned through the .test() callback.
  • Unit tests for the WebdriverIO adapter that check that all errors are returned through the callbacks.

Solution

Stub all of the dependencies to throw errors and check that they're returned through the callbacks.

Improve integration tests

Need

As a developer
I want to use temporary files
When testing a package

Solution

Use tmp.
Test the package with a recursive rootDirectory.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Add Cypress adapter

It would be really cool to be able to use this tool together with Cypress as this is IMO currently the best tool out there to write tests in the browser.

There are other open source solutions for it already (for example https://github.com/jaredpalmer/cypress-image-snapshot) and many commercial ones. This one seems to be the better choice overall though.
For a list of currently available visual diff tools for Cypress see this: https://docs.cypress.io/plugins/directory#visual-testing

Would you consider adding a Cypress adapter to this library?

Fix error when the results folder doesn't exist

Need

As a user
I want Mugshot to work correctly straight out of the box
So that I can quickly run my tests.

Problem

Given that there is no `visual-tests` folder
When I run mugshot
Then it will throw with an error for each fixture telling me that there is no such file or directory.

Eg:
Error: ENOENT: no such file or directory, mkdir 'tests/visual/visual-test/tooltip'

Deliverables

Fix the problem.

Solution

Use mkdirp instead of fs.mkdir.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.