reg-cli: Visual Regression Test Tool

0.18.14 · active · verified Wed Apr 22

reg-cli is a command-line interface (CLI) tool for performing visual regression testing on images and generating a comprehensive, interactive HTML report. It helps developers detect unintended visual changes in user interfaces over time by comparing 'actual' images with 'expected' baseline images. The current stable version is 0.18.14, with development actively focused on minor feature enhancements to the report UI, dependency updates, and security patches. Key differentiators include its flexible image comparison logic with adjustable thresholds, support for parallel processing, and the ability to generate reports from pre-existing JSON data. It requires Node.js v18 or newer for execution, ensuring compatibility with modern JavaScript environments. It is primarily used via its CLI but also exposes a programmatic API for integration into custom build workflows.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to run `reg-cli` from a Node.js script to compare images, generate a diff, and output an HTML report. It sets up dummy directories and files, then executes the CLI command with common options.

import { spawn } from 'node:child_process';
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const actualDir = './screenshots/actual';
const expectedDir = './screenshots/expected';
const diffDir = './screenshots/diff';
const reportPath = './reg-report/index.html';

async function setupDirs() {
  await mkdir(actualDir, { recursive: true });
  await mkdir(expectedDir, { recursive: true });
  await mkdir(diffDir, { recursive: true });
  // Simulate creating a dummy actual image
  await writeFile(join(actualDir, 'test.png'), Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', 'base64'));
  // Simulate creating a dummy expected image for comparison
  await writeFile(join(expectedDir, 'test.png'), Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', 'base64'));
}

async function runRegCli() {
  await setupDirs();

  const args = [
    actualDir,
    expectedDir,
    diffDir,
    '-R', reportPath,
    '--matchingThreshold', '0.01',
    '--thresholdRate', '0.001'
  ];

  const regCliProcess = spawn('npx', ['reg-cli', ...args], { stdio: 'inherit' });

  regCliProcess.on('close', (code) => {
    if (code === 0) {
      console.log('reg-cli comparison completed successfully. Check report at', reportPath);
    } else {
      console.error(`reg-cli exited with code ${code}. Visual differences might have been found.`);
    }
  });
}

runRegCli().catch(console.error);

view raw JSON →