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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@compare-ui/playwright-test-fixture

v0.1.0

Published

Playwright component-test fixture for design comparison.

Readme

@compare-ui/playwright-test-fixture

Playwright helpers for component-level design comparison.

This package provides:

  • a full fixture for registering Playwright component-test comparisons
  • a smaller helper for taking a screenshot from the current Playwright page or target

Installation

pnpm add @compare-ui/playwright-test-fixture
pnpm add @playwright/test @playwright/experimental-ct-react react react-dom

If you author shared comparison config directly with @compare-ui/core, also install it explicitly:

pnpm add @compare-ui/core

If your app already has Playwright and React installed, add only the missing packages.

Peer dependencies

The package expects the consuming app to provide:

  • @playwright/test
  • @playwright/experimental-ct-react
  • react
  • react-dom

Supported peer ranges:

  • @playwright/test >=1.40.0 <2
  • @playwright/experimental-ct-react >=1.40.0 <2
  • react ^18.0.0 || ^19.0.0
  • react-dom ^18.0.0 || ^19.0.0

Playwright package setup

This package uses the consuming app's Playwright installation.

Keep these packages on the exact same version:

  • @playwright/test
  • @playwright/experimental-ct-react

This is a workspace package setup requirement. The package docs and workspace validation should keep these versions aligned; the fixture does not need extra runtime enforcement for this.

The workspace also runs tarball compatibility smoke tests in CI so the published package is revalidated against more than one consumer dependency shape.

What it exports

Main public APIs:

  • designComparison(...)
  • capturePageScreenshot(...)

Published entrypoint:

  • @compare-ui/playwright-test-fixture

That entrypoint is intended to resolve from the published build output, and the workspace verifies it through a tarball smoke test.

Full fixture

designComparison(...) is the main high-level fixture.

It registers one Playwright test per design file and handles:

  • viewport setup
  • component mounting
  • screenshot capture
  • comparison execution
  • report and artifact logging
  • failure reporting

The public contract of designComparison(...) is:

  • register tests
  • fail tests when comparison does not pass

It is not a result-returning API.

Call designComparison(...) directly in a Playwright component-test spec file.

Example:

import { designComparison } from '@compare-ui/playwright-test-fixture';

import { ExampleScreen } from '../../src/example-screen';

import comparisonConfig from '../../design-comparison.config.mts';

designComparison({
  config: comparisonConfig,
  name: 'example-screen',
  renderComponent: () => <ExampleScreen />,
  designFiles: [
    {
      viewport: { x: 320, y: 640 },
      path: './tests/fixtures/example-screen-reference-padded.png',
      crop: {
        bottom: 20,
      },
    },
  ],
});

Design files

Each design file entry describes one comparison case.

type ViewportSize = {
  x: number;
  y: number;
};

type DesignComparisonDesignFile = {
  viewport: ViewportSize;
  path?: string;
  url?: string;
  crop?: {
    top?: number;
    right?: number;
    bottom?: number;
    left?: number;
  };
};

viewport represents the original design viewport. If the reference is cropped, the effective comparison viewport is derived from the cropped reference size.

Comparison behavior such as:

  • crop handling
  • explicit size normalization
  • explicit transparent-background flattening

comes from the shared @compare-ui/core and @compare-ui/runner flow, not from fixture-specific image rules in this package.

Screenshot helper

capturePageScreenshot(...) is the smaller helper for writing a screenshot to disk from the current Playwright page or a selected screenshot target.

Example shape:

type CapturePageScreenshotOptions = {
  page: {
    setViewportSize(viewport: { width: number; height: number }): Promise<void>;
  };
  target: {
    screenshot(args: { path: string }): Promise<void>;
  };
  viewport: ViewportSize;
  screenshotPath: string;
};

Example:

await capturePageScreenshot({
  page,
  target: mountedComponent,
  viewport: { x: 320, y: 620 },
  screenshotPath: testInfo.outputPath('actual.png'),
});

Typical use cases:

  • capture a mounted component
  • capture the current page
  • capture a selected Playwright locator-like target

For the comparison step after a screenshot already exists, use @compare-ui/runner.

Typical workflow

At the package level, the common workflows are:

  1. Use designComparison(...) when you want the full Playwright component-test flow.
  2. Use capturePageScreenshot(...) when you only need screenshot capture.
  3. Use @compare-ui/runner when you already have a screenshot and want to run the comparison step explicitly.

When a comparison needs size normalization or transparent-background alignment, configure that through the shared core/runner comparison flow rather than through fixture-specific screenshot behavior.

Recipe: Component Test Against A Local Reference PNG

Use this package when you already know how to mount the component in Playwright component tests and want the fixture to handle the comparison flow.

import { designComparison } from '@compare-ui/playwright-test-fixture';

import comparisonConfig from '../../design-comparison.config.mts';
import { ExampleScreen } from '../../src/example-screen';

designComparison({
  config: comparisonConfig,
  name: 'example-screen',
  renderComponent: () => <ExampleScreen />,
  designFiles: [
    {
      viewport: { x: 320, y: 640 },
      path: './tests/fixtures/example-screen-reference.png',
      crop: {
        bottom: 20,
      },
    },
  ],
});

This recipe gives you:

  • one registered Playwright component test
  • automatic screenshot capture
  • comparison execution through the shared runner/core flow
  • report and artifact output when the comparison fails

Notes

  • This package is intended for Playwright-based usage.
  • It supports React 18 and React 19 component-test consumers within the documented peer range.
  • It is designed to be used with shared config from design-comparison.config.mts.
  • The workspace includes a dedicated example consumer at apps/playwright-example.