Manifest

Reading manifests

import {
import {
  readManifestFiles,
  readManifestFile,
  parseManifest,
  ManifestParseError,
} from 'visual-regression-manifest';

// every manifest below a directory (an unpacked CI artifact), sorted by path
const found = readManifestFiles('artifacts/test');
// -> [{ file: '.../visual-regression-manifest.e2e.json', manifest: {...} }, ...]

// one file
const manifest = readManifestFile(
  'cypress/screenshots/visual-regression-manifest.e2e.json',
);

// already-parsed JSON from anywhere (a zip entry, an HTTP body)
try {
  const manifest = parseManifest(
    json,
    'test.zip:visual-regression-manifest.e2e.json',
  );
} catch (error) {
  if (error instanceof ManifestParseError)
    console.error(error.message, error.issues);
}

parseManifest validates against the shipped schema with a small built-in interpreter (cross-checked against Ajv in the test suite); validateManifest returns the issues without throwing and isManifest is the type guard. Unknown keys pass through untouched.