Skip to content

Commit

Permalink
test: different sizes of actual and expected
Browse files Browse the repository at this point in the history
  • Loading branch information
raphiz committed Aug 20, 2024
1 parent 44b629d commit 4ab2e41
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/src/compare.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs/promises";
import { compare } from "./compare.js";
import { PNG } from "pngjs";

describe("compare", () => {
it("returns the number of pixels that differ", async () => {
Expand All @@ -14,4 +15,20 @@ describe("compare", () => {
expect(result.actual).toStrictEqual(actual);
expect(result.diff).toStrictEqual(expectedDiff);
});

it("enlarges images to be able to create diffs", async () => {
const expected = emptyPNG(1920, 1024);
const actual = emptyPNG(2000, 800);

const result = await compare(expected, actual);

const diff = PNG.sync.read(result.diff);
expect(diff.width).toStrictEqual(2000);
expect(diff.height).toStrictEqual(1024);
});
});

function emptyPNG(width, height) {
const png = new PNG({ width, height });
return PNG.sync.write(png);
}

0 comments on commit 4ab2e41

Please sign in to comment.