Emailens
Engine Package

Diff Results

Compare two sets of transform results to see what improved or regressed.

diffResults

Compares two sets of transform results (before/after) and returns the differences.

function diffResults(
  before: TransformResult[],
  after: TransformResult[]
): DiffResult[]

Parameters

ParameterTypeDescription
beforeTransformResult[]Previous transform results
afterTransformResult[]New transform results

Returns

An array of DiffResult objects, one per client:

interface DiffResult {
  clientId: string;
  scoreBefore: number;
  scoreAfter: number;
  scoreDelta: number;       // Positive = improved
  fixed: CSSWarning[];      // Warnings that were resolved
  introduced: CSSWarning[]; // New warnings
  unchanged: CSSWarning[];  // Warnings still present
}

Example

import {
  transformForAllClients,
  analyzeEmail,
  generateCompatibilityScore,
  diffResults,
} from "@emailens/engine";

// Before changes
const beforeTransforms = transformForAllClients(originalHtml);

// After changes
const afterTransforms = transformForAllClients(updatedHtml);

const diffs = diffResults(beforeTransforms, afterTransforms);

for (const diff of diffs) {
  if (diff.scoreDelta > 0) {
    console.log(`${diff.clientId}: improved by ${diff.scoreDelta} points`);
    console.log(`  Fixed: ${diff.fixed.length} issues`);
  } else if (diff.scoreDelta < 0) {
    console.log(`${diff.clientId}: regressed by ${Math.abs(diff.scoreDelta)} points`);
    console.log(`  New issues: ${diff.introduced.length}`);
  }
}

Use cases

  • Dashboard: the web app shows diffs when you edit a saved preview
  • CI/CD: compare current PR against the main branch
  • Iteration: track progress as you fix compatibility issues

On this page