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

@digital-commons-official/codeceptjs-visual-helper

v3.1.1

Published

Visual regression testing helper for CodeceptJS with Playwright, Puppeteer, WebDriver, Appium & TestCafe support

Readme

👁️ codeceptjs-visual-helper

pipeline status

A visual regression testing helper for CodeceptJS, providing pixel-by-pixel screenshot comparison with comprehensive support for Playwright, Puppeteer, WebDriver, Appium, WebDriverIO and TestCafe.

Overview 📖

This helper enables automated visual regression testing by comparing screenshots captured during test execution against established baseline images. When differences are detected, the helper generates diff images that highlight the discrepancies, facilitating rapid identification of unintended visual changes.

Key Features

  • Multi-driver Support — Seamlessly integrates with Playwright, Puppeteer, WebDriver, Appium, WebDriverIO and TestCafe
  • Configurable Tolerance — Define acceptable thresholds for pixel differences
  • Ignore Regions — Exclude dynamic content areas from comparison
  • Baseline Variations — Support multiple baseline versions for responsive or themed layouts
  • Detailed Reporting — Comprehensive diff images and statistics for each comparison

Installation 📦

Requires Node.js 22.19.0 or later. The package is tested with CodeceptJS 4 on Node 22.23.4, 24.22.1 and 26.12.1. Node 18 and 20 are no longer supported.

npm install @digital-commons-official/codeceptjs-visual-helper --save-dev

Configuration ⚙️

Add the helper to your codecept.conf.js configuration file:

helpers: {
  Playwright: {
    // Your browser helper configuration
  },
  VisualHelper: {
    require: '@digital-commons-official/codeceptjs-visual-helper',
    baselineDir: './tests/screenshots/baseline/',
    diffDir: './tests/screenshots/diff/',
    actualDir: './tests/output/',
    tolerance: 1.5,
    threshold: 0.1
  }
}

Configuration Options

| Option | Type | Default | Description | | |--------------------------|-----------|---------------------------------|-----------------------------------------------------|----------------------------------------------------------------| | baselineDir | string | ./tests/screenshots/baseline/ | Directory containing baseline images | | | diffDir | string | false | ./tests/screenshots/diff/ | Directory for generated diff images; set to false to disable | | actualDir | string | global.output_dir | Directory for captured screenshots | | | tolerance | number | 0 | Permitted percentage of differing pixels (0–100) | | | threshold | number | 0.1 | Pixelmatch colour comparison threshold (0–1) | | | diffPrefix | string | Diff_ | Filename prefix for diff images | | | imageFormat | string | 'webp' | 'webp' (lossless) or 'png' for older baselines | | | saveIntermediateImages | boolean | false | Retain intermediate processing images for debugging | | | captureActual | boolean | 'missing' | 'missing' | Automatic capture of actual screenshots | | captureBaseline | boolean | 'missing' | 'missing' | Automatic capture of baseline images |

Usage 🚀

Asserting Visual Matches

The assertVisualMatch method compares the current viewport against a baseline image, failing the test if differences exceed the configured tolerance:

// Basic full-page comparison
await I.assertVisualMatch('homepage');

// With custom tolerance
await I.assertVisualMatch('dashboard', { tolerance: 2.5 });

// Element-specific comparison
await I.assertVisualMatch('navigation', { element: '#main-nav' });

// Excluding dynamic regions
await I.assertVisualMatch('profile-page', {
  ignoreRegions: [
    { x: 10, y: 10, width: 200, height: 50 }  // Timestamp area
  ]
});

Comparing Without Assertions

The compareVisual method performs comparison and returns detailed results without throwing exceptions:

const result = await I.compareVisual('checkout-form');

if (!result.isMatch) {
  console.log(`Visual difference detected: ${result.differencePercent}%`);
  console.log(`Diff image saved to: ${result.diffImagePath}`);
}

Capturing Screenshots

// Capture current viewport as actual image
await I.captureScreenshot('landing-page');

// Capture and save as new baseline
await I.captureScreenshot('landing-page', 'baseline');

// Capture specific element
await I.captureScreenshot('footer', 'baseline', 'footer.main');

Comparison Options

| Option | Type | Description | |------------------|----------|----------------------------------------------------------------| | tolerance | number | Override the default tolerance for this comparison | | compareWith | string | Specify a custom baseline image name | | element | string | CSS selector for element-specific comparison | | bounds | object | Bounding box { x, y, width, height } to constrain comparison | | ignoreRegions | array | Array of regions [{ x, y, width, height }] to exclude | | pixelmatchArgs | object | Override pixelmatch library options |

Baseline Variations

The helper supports multiple baseline variations using the tilde (~) suffix convention:

homepage.png           # Primary baseline
homepage~dark.png      # Dark theme variant
homepage~tablet.png    # Tablet viewport variant

During comparison, the helper evaluates all matching variations and reports the best match, enabling comprehensive testing across different visual states.

Comparison Result Object

interface VisualComparisonResult {
  isMatch: boolean;           // Whether difference is within tolerance
  differencePercent: number;  // Percentage of differing pixels
  differentPixels: number;    // Count of differing pixels
  totalPixels: number;        // Total pixels in the image
  comparedPixels: number;     // Pixels compared (excluding masked regions)
  variationName: string;      // Name of the matched variation
  diffImagePath: string;      // Path to the generated diff image
  variations: Array<...>;     // Results for all evaluated variations
}

Filming a Terminal 🖥️

TerminalHelper, on its own sub-path, types a command in a real ttyd terminal, waits for the shell prompt to come back, and saves the command, its output and the prompt as a card image, without the install noise (apt, npm, uv, git push). A project that does not load it loads nothing of it.

Your project provides ttyd (the helper checks its version at start, 1.7.7 by default) and runs the browser helper and VisualHelper next to it:

helpers: {
  Playwright: { /* ... */ },
  VisualHelper: { require: '@digital-commons-official/codeceptjs-visual-helper' },
  TerminalHelper: {
    require: '@digital-commons-official/codeceptjs-visual-helper/terminal',
    prompt: 'demo@terminal:[^\\r\\n]*\\$\\s*$', // the last row once a command is over
    noise: ['^Downloading ']                     // more rows to drop from every card
  }
}
// ttyd started by the helper, stopped after the test
await I.startTerminal({ cwd: '/tmp/demo' })
// or a ttyd your project already runs (a Compose service, a URL)
await I.openTerminal('http://ubuntu:7681')

const { image, text } = await I.runInTerminal('task --list', { name: 'task-list' })

image is the card's path, for a storyboard or assertVisualMatch, and text is what the screen says. A wrong prompt pattern fails in seconds with the pattern and the screen, and startTerminal writes ttyd's own log next to the test output (ttyd-<port>.log). ttyd needs the DOM renderer (-t rendererType=dom): startTerminal sets it, a ttyd your project runs needs it in its own command line. The shell startTerminal opens is writable without a password, so ttyd listens on 127.0.0.1 only.

Development 🛠️

Project Structure

project/helper/
├── src/
│   ├── index.js              # Main VisualHelper class
│   ├── index.d.ts            # TypeScript declarations
│   ├── config/
│   │   └── defaults.js       # Default configuration values
│   ├── drivers/
│   │   └── adapter.js        # Browser driver abstraction layer
│   ├── services/
│   │   ├── comparator.js     # Image comparison logic
│   │   └── path-builder.js   # File path construction
│   └── utils/
│       ├── conversion.js     # Type conversion utilities
│       ├── filesystem.js     # File system operations
│       └── image.js          # PNG and WebP manipulation functions
└── tests/
    ├── config/               # Configuration tests
    ├── services/             # Service tests
    ├── utils/                # Utility tests
    └── integration/          # Visual comparison integration tests

Running Tests

# Execute all tests (unit, integration, e2e)
task test

# Execute helper unit tests only
task project:test:helper

# Execute integration tests with visual diff output
task project:test:helper:integration

# Execute the CodeceptJS storyboards of project/tests/e2e
task project:test:e2e

Integration Tests

The integration tests generate actual diff images that may be inspected visually. Following execution, examine the project/helper/test-output/ directory to review:

  • Identical comparison — Baseline and actual images with zero differences
  • Different comparison — Images with intentional differences and highlighted diff output
  • Tolerance comparison — Demonstration of strict versus lenient tolerance settings
  • UI simulation — Complex page comparison with ignore regions

Release & Publishing

The helper is designed to be published as an npm package. The following tasks support the release workflow:

# Inspect package contents locally without publishing
task project:release:helper

# Check the publishing authorization rules in an isolated runner
task project:test:e2e -- --grep "@npm-trusted-publishing"

GitLab CI publishes from the protected default branch using npm trusted publishing (OIDC). The release job takes the default runner tag, served by the group's self-hosted runners, and requests the npm identity. npm rejects provenance from self-hosted runners, so versions after 3.0.0 carry no provenance attestation. No long-lived npm token or local .npmrc is needed.

Licence 📜

EUPL-1.2