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

@react-lens/test

v0.2.0

Published

Visual snapshot testing for ReactLens previews

Downloads

280

Readme

@react-lens/test

Visual snapshot testing for React components using ReactLens @preview annotations.

Renders your components with Vite + Playwright, captures screenshots, and compares them against baselines using pixel-level diffing. Designed for CI — no browser UI needed.

Install

npm install --save-dev @react-lens/test playwright
npx playwright install chromium

Peer dependencies (you likely already have these):

npm install --save-dev vite @vitejs/plugin-react

How it works

  1. Scans your project for @preview annotations that include a snapshot field
  2. Spins up a Vite dev server and Playwright browser
  3. Renders each preview and captures a screenshot
  4. Compares against baseline PNGs in __snapshots__/
  5. Reports pass/fail with diff images for mismatches

Only previews with an explicit snapshot field are included — it's opt-in.

Annotate your components

Add a snapshot field to any @preview annotation:

/**
 * @preview {
 *   name: "Primary",
 *   snapshot: "button-primary",
 *   props: { label: "Click me", variant: "primary" }
 * }
 */
export function Button({ label, variant, onClick }: ButtonProps) {
  return <button className={variant} onClick={onClick}>{label}</button>;
}

For .preview.tsx files:

/**
 * @preview {
 *   name: "Card Previews",
 *   snapshot: "card"
 * }
 */
export default {
  'Basic': <Card title="Hello" />,
  'With Image': <Card title="Hello" image="/photo.jpg" />,
};

This generates snapshots card-basic and card-with-image.

CLI usage

# Run snapshot tests (compares against baselines)
npx reactlens test

# Create or update all baselines
npx reactlens test --update

# Update only baselines matching a filter
npx reactlens test --update button

Exit codes: 0 = all pass, 1 = mismatches or errors.

Output

ReactLens Visual Snapshot Tests

  PASS  button-primary
  FAIL  card-actions (0.45% diff, 1234 pixels)
        Diff: __snapshots__/card-actions-diff.png
  NEW   avatar-default (baseline created)

Results: 1 passed, 1 failed, 1 new | Duration: 4.2s

On failure, a -diff.png image is written showing the changed pixels in red.

Configuration

Create a reactlens.config.ts in your project root:

import { defineConfig } from '@react-lens/test';

export default defineConfig({
  // Glob patterns for finding component files (default: ['**/*.tsx', '**/*.jsx'])
  include: ['src/**/*.tsx'],

  // Snapshot settings
  snapshots: {
    // Output directory for baseline PNGs (default: '__snapshots__')
    directory: '__snapshots__',
    // Max fraction of pixels that can differ (0-1, default: 0.01 = 1%)
    threshold: 0.01,
  },
});

Programmatic API

import { runTests } from '@react-lens/test';

const summary = await runTests({
  projectRoot: process.cwd(),
  update: false,
  threshold: 0.01,
});

console.log(`${summary.passed} passed, ${summary.failed} failed`);

Individual modules are also exported:

import {
  discoverPreviews,   // Scan project for snapshot-enabled previews
  PreviewRenderer,    // Vite + Playwright screenshot capture
  compareImages,      // Pixel-level image comparison
  BaselineManager,    // Read/write baseline PNGs
} from '@react-lens/test';

CI setup

Add to your CI pipeline:

npm ci
npx playwright install --with-deps chromium
npx reactlens test

The test command exits with code 1 on mismatches, failing the build.

License

MIT