Manifest

Converting to and from other formats

Every converter below but Loki's is run against the real tool in the repository's examples/converters:

Every converter below but Loki's is run against the real tool in the repository's examples/converters: the tool records baselines, one comparison is made to fail, one baseline is removed, and the converted manifest is checked against the files the tool left behind. The Allure export is fed to the real allure generate there. The JUnit export is checked against no CI system.

From the command line

The package ships a visual-regression-manifest command that runs the converters below without a script. It needs Node 20.9 or newer. Run it in the project the tool ran in:

# tools that write a JSON report: pass the report
npx visual-regression-manifest convert playwright report.json --max-diff-ratio 0.01

# tools that leave folders of images: the project root is scanned
npx visual-regression-manifest convert lost-pixel

# then review it
npx visual-regression-viewer .

The manifest is written to visual-regression-manifest.<tool>.json in the project root, next to the images it lists, which is where the viewer looks for them. -o <dir> writes it into another folder and -o <file>.json to that file. -p, --project-root <dir> names the project when you are not in it.

ToolReadsFlags besides -p, -o, --options
playwrightthe JSON report--max-diff-ratio, --max-diff-pixels, --color-threshold
vitestthe project root--max-diff-ratio, --max-diff-pixels, --color-threshold
jest-image-snapshotthe project root--max-diff-ratio, --max-diff-pixels, --color-threshold
cypress-image-snapshotcypress/snapshots in the project root--max-diff-ratio, --max-diff-pixels, --color-threshold
cypress-visual-regressionthe project root--max-diff-ratio, --max-diff-pixels, --color-threshold
cypress-image-diffthe JSON report--color-threshold
backstopjsbackstop_data/json_report/jsonReport.json by defaultnone
roborazzithe results-summary.json--max-diff-ratio
reg-clireg.json by default--max-diff-ratio, --max-diff-pixels, --color-threshold, --update
lost-pixelthe project root--max-diff-ratio (its threshold), --update
lokithe project root--configurations chrome.laptop,chrome.iphone7
allurethe results folder, allure-results by default--max-diff-ratio, --max-diff-pixels, --color-threshold
ctrfthe CTRF report--lenient

The flags are the options of the converters, described below for each tool: the limits are what your tool was configured with, because the files it leaves behind do not say. A flag the tool does not take is refused. Everything else a converter accepts (baselineDir, snapshotPathTemplate, runner, ...) goes into --options as a JSON object, which is merged over what the flags set:

npx visual-regression-manifest convert lost-pixel --options '{"baselineDir":"shots/baseline"}'

A report has to lie inside the project root, as the manifest only holds paths relative to it. The command exits with 1 and prints the reason when it cannot convert.

export goes the other way and writes a manifest as a report other tools read:

# an Allure results folder, for `allure generate`
npx visual-regression-manifest export allure visual-regression-manifest.json

# a JUnit XML report, for the test tab of your CI
npx visual-regression-manifest export junit visual-regression-manifest.json -o reports/visual.xml
FormatWrites-o default
allureAllure results, next to the ones in the folderallure-results
junitone JUnit XML filevisual-regression-junit.xml

Both write into the current directory unless -o says otherwise. The Allure export reads the images from the projectRoot the manifest records; when the manifest comes from another machine (a downloaded CI artifact), -p, --project-root <dir> says where they are now. The JUnit export reads no images and takes no -p; its options (name, attachmentPaths) go into --options as a JSON object.

CTRF

CTRF is the test results format a growing number of reporters write and CI integrations read (PR summaries, Slack messages, dashboards). A manifest becomes a CTRF report with one test of type: "visual" per entry, named after the screenshot, with the baseline, actual and diff images as attachments and everything CTRF has no field for under extra.visualRegression:

import fs from 'fs';
import { readManifestFile, toCtrf, fromCtrf } from 'visual-regression-manifest';

const manifest = readManifestFile('visual-regression-manifest.json');
fs.writeFileSync('ctrf-report.json', JSON.stringify(toCtrf(manifest), null, 2));

// and back: a report made by `toCtrf` converts without loss
const same = fromCtrf(JSON.parse(fs.readFileSync('ctrf-report.json', 'utf8')));
manifestCTRF
toolresults.tool, generatedBy
createdAt, updatedAtsummary.start, summary.stop, timestamp
summarysummary.tests/passed/failed (via the status table above); verbatim in summary.extra
ci.commit, branchName, repositoryName, repositoryUrl, buildId, buildName, buildNumber, buildUrlenvironment.<same name>; ci.buildId also as the root runId
platform.osPlatform, osRelease, osVersionenvironment.<same name>
the rest of ci and platformenvironment.extra.visualRegression.{ci, platform}
specVersion, projectRoot, options, runner, uploadresults.extra.visualRegression
entry name, test.titlePath, test.filePath, message, duration, test.retrytest.name, suite, filePath, message, duration, retries
statustest.status (via the table) and test.rawStatus (verbatim)
recordedAttest.stop (and start when duration is known)
platform.browser, target.device.modeltest.browser, test.device
images.baseline/actual/diff, attachmentstest.attachments[], with extra.visualRegression.role, sizes and hashes on the images
comparison, images, hashes, variant, renderer, target, subject, viewport, ...test.extra.visualRegression
any other extra namespacethe same namespace on the CTRF object

fromCtrf reads reports made by toCtrf back without loss (apart from the entry order, which is re-sorted, and the summary, which is recomputed). With { lenient: true, projectRoot } it also converts the visual tests of reports from other reporters, taking the three images from attachments named or tagged baseline/expected, actual and diff, and the status from rawStatus or from which images exist; absolute paths become relative to projectRoot; one outside it has no safe relative form, so it is left out with a warning (onWarning, default process.emitWarning) and a test whose baseline is outside is skipped. A test without a baseline attachment has no entry, and a baseline the run just wrote looks like a failed comparison: a plain CTRF report cannot tell them apart.

Allure

Allure Report shows a screenshot comparison in its own view (expected, actual, diff, overlay, side by side) when a test carries an image diff attachment. A manifest becomes an Allure results folder with one test per entry:

import {
  readManifestFile,
  writeAllureResults,
} from 'visual-regression-manifest';

const manifest = readManifestFile('visual-regression-manifest.json');
writeAllureResults('allure-results', manifest);
// then: npx allure generate allure-results
manifestAllure result
entry namename, the last part of fullName
statusstatus: failed and missing-baseline are failed, the rest passed; verbatim in the visualRegression.status label
messagestatusDetails.message
test.filePath, test.titlePaththe parentSuite, suite and subSuite labels, titlePath
images of an entry with an actual imageone application/vnd.allure.image.diff attachment holding the images (the actual image alone when there is no baseline)
the baseline of an entry without an actual image, attachmentsplain attachments, copied into the folder
variantthe variant parameter
comparison.diffRatio, maxDiffRatio, colorThreshold, colorMetric, the browser, the OS, viewportparameters left out of the test's history
recordedAt, durationstop, start
runner.namethe framework label

The images are embedded in the attachment, so the results folder stands on its own. The files are added to whatever results the folder holds, and an entry always gets the same file names: exporting a run again overwrites its own files, but the files of entries that are gone stay until you empty the folder. toAllureResults gives the same files in memory, all at once; use writeAllureResults for a run with many or large images.

The manifest says which files are read (its projectRoot and its paths), so export a manifest only when you trust where it comes from. The export reads regular files inside the project root and nothing else: a file that cannot be read, is not an image where one is due, or lies outside the project (by its path or through a link) is left out with a warning (onWarning, default process.emitWarning). projectRoot says where the images are when that is not the manifest's own projectRoot. Everything else in the manifest (hashes, renderer, CI, options) has no place in Allure results and is not written.

The other way, fromAllureResults reads an Allure results folder and makes one entry per image diff attachment. The attachment is the same in every Allure adapter, whatever the framework and language; the converter is run against the results of allure-playwright only:

import { fromAllureResults } from 'visual-regression-manifest';

const manifest = fromAllureResults({
  projectRoot: process.cwd(),
  resultsDir: 'allure-results', // the default
  maxDiffRatio: 0.01, // what your tool was configured with
});

Allure keeps the images inside the attachment, and a manifest lists image files, so this converter, unlike the others, writes files: the images go into visual-regression-images inside the results folder (imagesDir to put them elsewhere in the project). The manifest's baseline is that copy, not the file your tool compares against: the manifest is good for reviewing a run, not for approving one.

A diff without an expected image is missing-baseline; any other is failed, or passed when the test passed; a visualRegression.status label wins over both. The variant is the variant parameter, else the test's parameters joined (a Playwright project, a browser). Only the last attempt of a retried test is converted. Allure records no diff ratio: it is 0 unless a diffRatio parameter says otherwise. A comparison that left no image diff attachment (a passing one, mostly) has no entry, and the test file is not known. That also holds for results writeAllureResults wrote: reading them back keeps the names, statuses, ratios and variants of the entries that have an actual image, and nothing else.

JUnit XML

Most CI systems read JUnit XML: the test tabs of GitLab and Jenkins, pull request annotations, flaky test dashboards. toJUnit gives a manifest as one report with a <testsuite> per test file and a <testcase> per entry:

import fs from 'fs';
import { readManifestFile, toJUnit } from 'visual-regression-manifest';

const manifest = readManifestFile('visual-regression-manifest.json');
fs.writeFileSync('visual-regression-junit.xml', toJUnit(manifest));

failed and missing-baseline entries carry a <failure> with the entry's message (or one made from the diff ratio and the limit); every other status passes. JUnit XML has no place for a comparison, so this export loses most of it, and a manifest cannot be read back from the report:

  • The status, the diff ratio, the limit and the variant are <properties> of the test case (visualRegression.status, ...), which most readers ignore.
  • The images are [[ATTACHMENT|path]] lines in <system-out>, the convention GitLab and the Jenkins JUnit Attachments plugin read. The diff comes first, then the actual image, then the baseline, and nothing says which is which. A reader copies the files these lines name, so a path that leaves the project is never written.
  • The test cases carry <properties> and a file attribute, which lenient readers accept and a strict JUnit schema does not.

attachmentPaths chooses the paths: 'repository' (the default) writes them relative to the repository root, which GitLab expects, and falls back to the project root when the manifest does not know the repository; 'absolute' writes them under the manifest's projectRoot, which Jenkins expects; false leaves the lines out. name names the root <testsuites> (default: the manifest's tool.name).

Playwright's toHaveScreenshot

Run with the JSON reporter and convert the report:

npx playwright test --reporter=json > report.json
import fs from 'fs';
import {
  fromPlaywrightReport,
  writeManifestFile,
} from 'visual-regression-manifest';

const manifest = fromPlaywrightReport(
  JSON.parse(fs.readFileSync('report.json', 'utf8')),
  {
    projectRoot: process.cwd(), // the report's rootDir is your testDir, not the project
    maxDiffRatio: 0.01, // your maxDiffPixelRatio; or maxDiffPixels: 100, converted with each image's size
    // colorThreshold: 0.2, // your pixelmatch `threshold` (colorMetric defaults to 'yiq')
    // the report carries none of these, so they come from your config
    // snapshotPathTemplate / snapshotDir: only when changed in playwright.config
    // browsers: { chromium: { name: 'chromium', version: '130' } } for richer `platform` blocks
  },
);
writeManifestFile(
  'test-results/visual-regression-manifest.playwright.json',
  manifest,
);

Only comparisons that left a trace can be recovered: failed (expected, actual and diff attachments), created (the written baseline and the actual) and missing-baseline (with updateSnapshots: 'none' nothing is attached, the entry comes from the error naming the file). A passing toHaveScreenshot leaves no trace in the report, and of a retried test only the last attempt counts. Baseline paths are computed from the snapshot path template because the report only lists the copies in test-results; the diff ratio is parsed from the assertion message.

Vitest's toMatchScreenshot

Vitest (browser mode) keeps references in __screenshots__/<test file>/ next to the tests and writes <name>-actual-<browser>-<platform>.png and <name>-diff-...png under .vitest/attachments/<test file dir>/<test file>/ at the project root for failed comparisons. The converter scans the project for both:

import { fromVitestScreenshots } from 'visual-regression-manifest';

const manifest = fromVitestScreenshots({
  projectRoot: process.cwd(),
  maxDiffRatio: 0.01, // your allowedMismatchedPixelRatio; or maxDiffPixels for allowedMismatchedPixels
  // colorThreshold: 0.2, // your pixelmatch `threshold`
  // roots: ['src', 'tests'], screenshotsDirName, attachmentsDir: when changed
});

A reference without attachments passed, attachments without a reference are missing-baseline (on CI Vitest writes no reference but a <name>-reference-...png attachment; elsewhere it writes the reference, and the files look like a passed comparison), and the browser and platform are read off the file name (button-chromium-darwin).

jest-image-snapshot and cypress-image-snapshot

Baselines are <id>.png in __image_snapshots__/, where <id> is your customSnapshotIdentifier or <test file>-<test name>-<n>-snap; failures leave <id>-diff.png (a baseline | diff | received composite unless onlyDiff) in __image_snapshots__/__diff_output__/, plus <id>-received.png in __image_snapshots__/__received_output__/ when storeReceivedOnFailure is on:

import { fromJestImageSnapshots } from 'visual-regression-manifest';

const manifest = fromJestImageSnapshots({
  projectRoot: process.cwd(),
  runner: { name: 'cypress' }, // for cypress-image-snapshot; defaults to jest
  maxDiffRatio: 0.01, // your failureThreshold with failureThresholdType 'percent'; or maxDiffPixels with 'pixel'
  // colorThreshold: 0.1, // your customDiffConfig.threshold
  // snapshotsDirName, diffDirName, receivedDirName, snapshotPostfix, diffPostfix, receivedPostfix: when customized
});

The received image is the entry's actual when it exists; the diff composite is the entry's diff image either way. A trailing -snap is dropped from the entry name.

cypress-image-snapshot keeps one folder per spec file under cypress/snapshots/ (next to Cypress's screenshots folder), with <name>.snap.png baselines and __diff_output__/<name>.diff.png diffs; point the converter at that folder:

const manifest = fromJestImageSnapshots({
  projectRoot: process.cwd(),
  runner: { name: 'cypress' },
  snapshotsDir: 'cypress/snapshots',
  snapshotPostfix: '.snap',
  diffPostfix: '.diff',
});

The spec folder becomes the entry's test file.

cypress-visual-regression

Reads the base, actual and diff folders (cypress/snapshots/... by default), nested by spec file; the actual screenshots sit below the spec prefix Cypress adds, which the converter matches to the base images:

import { fromCypressVisualRegression } from 'visual-regression-manifest';

const manifest = fromCypressVisualRegression({
  projectRoot: process.cwd(),
  maxDiffRatio: 0.05, // your errorThreshold; or maxDiffPixels when it counts pixels
  // baseDirectory, actualDirectory, diffDirectory, generateDiff: when changed
});

Cypress writes an actual image for every comparison, so a diff image is what marks a failure (visualRegressionGenerateDiff: 'fail', the default); pass generateDiff when the run used another mode.

cypress-image-diff-js

The plugin keeps baseline/, comparison/ and diff/ folders under <ROOT_DIR>/cypress-image-diff-screenshots/ and, with JSON_REPORT in its config (on by default), writes a JSON report per run into <ROOT_DIR>/cypress-image-diff-html-report/ (report_<date>.json, or <FILENAME>.json):

import fs from 'fs';
import { fromCypressImageDiff } from 'visual-regression-manifest';

const manifest = fromCypressImageDiff(
  JSON.parse(
    fs.readFileSync('cypress-image-diff-html-report/report.json', 'utf8'),
  ),
  {
    projectRoot: process.cwd(), // the report's paths are relative to the Cypress working directory
    // colorThreshold: 0.1, // your COMPARISON_OPTIONS.threshold (pixelmatch; the plugin's default)
    // reportDir, screenshotsDir: when the report was moved or ROOT_DIR is set
  },
);

One entry per compareSnapshot, named after the screenshot (<spec name>-<name> unless exactName or a nameTemplate was used), in the spec that took it; the report's browser becomes the entry's platform.browser and its Cypress version the runner version. The plugin's "percentage" is the square root of the share of differing pixels, and so is its testThreshold; the converter squares both back into diffRatio and maxDiffRatio and keeps the plugin's own numbers under extra.cypressImageDiff. The report leaves a path empty when the file did not exist, so the converter derives it from the folder layout. A failed test without a baseline is missing-baseline (FAIL_ON_MISSING_BASELINE); by default the plugin copies the comparison to the baseline instead and the test passes.

BackstopJS

With "report": ["json"] BackstopJS writes backstop_data/json_report/jsonReport.json. Its paths are relative to that directory:

import fs from 'fs';
import { fromBackstopReport } from 'visual-regression-manifest';

const manifest = fromBackstopReport(
  JSON.parse(
    fs.readFileSync('backstop_data/json_report/jsonReport.json', 'utf8'),
  ),
  { projectRoot: process.cwd() }, // reportDir: when json_report was moved
);

One entry per scenario and viewport (titlePath: [label, viewportLabel], variant: viewportLabel), the mismatch percentage as diffRatio, misMatchThreshold as maxDiffRatio, a Reference file not found error as missing-baseline, and the scenario's url, selector and the raw diff block under extra.backstop.

Roborazzi

compareRoborazzi* and recordRoborazzi* write build/test-results/roborazzi/<variant>/results-summary.json with absolute paths:

import fs from 'fs';
import { fromRoborazziResults } from 'visual-regression-manifest';

const manifest = fromRoborazziResults(
  JSON.parse(
    fs.readFileSync(
      'build/test-results/roborazzi/debug/results-summary.json',
      'utf8',
    ),
  ),
  { projectRoot: process.cwd(), maxDiffRatio: 0.01 }, // your changeThreshold
);

changed is failed (with diff_percentage as the ratio and the _compare composite as the diff image), added is missing-baseline, unchanged is passed and recorded is updated. Entries carry an emulated Android target and a robolectric renderer; context_data lands under extra.roborazzi.

reg-cli and reg-suit

reg-cli compares a folder of actual images with a folder of expected ones and writes a JSON report (-J, reg.json by default) listing the items by file name; reg-suit runs it under the hood:

npx reg-cli actual expected diff -J reg.json
import fs from 'fs';
import { fromRegCli } from 'visual-regression-manifest';

const manifest = fromRegCli(JSON.parse(fs.readFileSync('reg.json', 'utf8')), {
  projectRoot: process.cwd(),
  // the report carries no ratios and no thresholds, so they come from your options
  maxDiffRatio: 0.01, // your --thresholdRate; or maxDiffPixels for --thresholdPixel
  // colorThreshold: 0.1, // your --matchingThreshold (pixelmatch)
  // reportDir: when reg.json was moved; actualDir, expectedDir, diffDir: when the report names URLs (--urlPrefix)
  // update: true, // the run was -U
});

The report's folders are relative to the report file. failedItems are failed with the diff image from the diff folder, newItems (an actual image with no expected one) are missing-baseline, passedItems are passed; after a -U run, which copies the failed and new actuals over the expected images, pass update: true to get updated and created instead. deletedItems, expected images with no actual, have no entry, as the manifest has no status for a baseline nothing was compared against; they are listed under extra.regCli.deletedItems on the manifest. Entries are named by the item path without its extension, so nested folders stay apart.

Lost Pixel

In its generateOnly mode Lost Pixel keeps .lostpixel/baseline/, .lostpixel/current/ (emptied and rewritten on every run) and .lostpixel/difference/ (one image per shot over its threshold). Run it with LOST_PIXEL_GENERATE_META=true to also get .lostpixel/current/meta.json, every comparison's pixel difference and verdict:

import { fromLostPixel } from 'visual-regression-manifest';

const manifest = fromLostPixel({
  projectRoot: process.cwd(),
  threshold: 0, // your `threshold`: a 0..1 share of the pixels, or a pixel count from 1 up
  // update: true, // the run was `lost-pixel update`
  // baselineDir, currentDir, differenceDir: your imagePathBaseline/Current/Difference, when changed
  // meta: 'path/to/meta.json' or false: when it was moved, or to ignore one
});

A current image without a baseline is missing-baseline; with a baseline, meta.json decides between passed and failed (and carries the diffRatio), or without it the difference image does. After lost-pixel update, which writes the baselines of changed and new shots, pass update: true: a changed shot is updated and a shot missing from meta.json (it had no baseline to compare against) is created; without the meta file a created baseline looks like a passed shot. A baseline with no current image was not shot in this run and gets no entry (listed under extra.lostPixel.baselinesWithoutShot). The breakpoint and browser labels Lost Pixel puts in file names (home__[w320px|chromium]) become the entry's variant and platform.browser.

Loki

Loki keeps .loki/reference/, .loki/current/ and .loki/difference/ with one <configuration>_<kind>_<story>.png per story and configuration, and writes no report:

import { fromLoki } from 'visual-regression-manifest';

const manifest = fromLoki({
  projectRoot: process.cwd(),
  configurations: ['chrome.laptop', 'chrome.iphone7'], // the keys of your loki `configurations`
  // tolerance: 2.3, // your chromeTolerance (pixelmatch's color threshold, in percent)
  // diffingEngine: 'looks-same', // when not pixelmatch, whose limit is "no differing pixel" (maxDiffRatio 0)
  // referenceDir, currentDir, differenceDir: when changed
});

A current image with a difference image is failed, without one passed, and without a reference missing-baseline (requireReference, Loki's default on CI; elsewhere it writes the reference and the story passes). A reference with no current image was not shot in this run and gets no entry; those files are listed under extra.loki.referencesWithoutShot. Entries are named after the files; a recognized configuration becomes the variant. File names follow the slug of Loki's default fileNameFormatter (checked against its source, not against a run); a custom formatter needs no configurations, the entries just get no variant. This converter is the one not proven against a real run: Loki needs Storybook plus Chrome, which the converter examples do not drive, so its unit test uses the documented layout.

Plain image files

For any tool that leaves a baseline and, on failure, an actual and a diff image next to it:

import { fromImageTriples } from 'visual-regression-manifest';

const manifest = fromImageTriples({
  projectRoot: process.cwd(),
  runner: { name: 'my-tool' },
  triples: baselines.map((baseline) => ({ baseline })), // actual/diff default to `.actual`/`.diff` siblings
});

The status is inferred from which files exist (inferStatus), image sizes are read from the PNG headers, and every field can be given explicitly (actual, diff, name, testFile, titlePath, status, diffRatio, ...).