-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1153 from argos-ci/improve-visual-testing-algo
feat: improve visual testing algo
- Loading branch information
Showing
16 changed files
with
259 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
Binary file added
BIN
+804 KB
...end/src/screenshot-diff/util/image-diff/__fixtures__/imageCompression4/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+804 KB
.../src/screenshot-diff/util/image-diff/__fixtures__/imageCompression4/compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+79.2 KB
.../backend/src/screenshot-diff/util/image-diff/__fixtures__/minorChange1/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+79.2 KB
...ckend/src/screenshot-diff/util/image-diff/__fixtures__/minorChange1/compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+551 KB
.../backend/src/screenshot-diff/util/image-diff/__fixtures__/minorChange2/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+551 KB
...ckend/src/screenshot-diff/util/image-diff/__fixtures__/minorChange2/compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+125 KB
apps/backend/src/screenshot-diff/util/image-diff/__fixtures__/tableAlpha/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+131 KB
...backend/src/screenshot-diff/util/image-diff/__fixtures__/tableAlpha/compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 0 additions & 78 deletions
78
apps/backend/src/screenshot-diff/util/image-diff/imageDifference.ts
This file was deleted.
Oops, something went wrong.
165 changes: 34 additions & 131 deletions
165
apps/backend/src/screenshot-diff/util/image-diff/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,52 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { join } from "node:path"; | ||
import { resolve } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { describe, expect, it } from "vitest"; | ||
import { describe, expect, test } from "vitest"; | ||
import { copyFile, unlink } from "node:fs/promises"; | ||
|
||
import { LocalImageFile } from "@/storage/index.js"; | ||
|
||
import { diffImages } from "./index.js"; | ||
|
||
const __dirname = fileURLToPath(new URL(".", import.meta.url)); | ||
|
||
describe("#diffImages", () => { | ||
it("simple", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/simple/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/simple/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ score: 0, width: 1425, height: 1146 }); | ||
}); | ||
|
||
it("alphaBackground", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/alphaBackground/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/alphaBackground/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ score: 0, width: 1400, height: 300 }); | ||
}); | ||
|
||
it("boxShadow", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/boxShadow/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/boxShadow/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ score: 0, width: 250, height: 300 }); | ||
}); | ||
|
||
it("border", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/border/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/border/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ | ||
score: 0, | ||
width: 1000, | ||
height: 786, | ||
}); | ||
}); | ||
|
||
it("fontAliasing", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/fontAliasing/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/fontAliasing/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ | ||
score: 0.00182697201018, | ||
width: 250, | ||
height: 786, | ||
}); | ||
}); | ||
const tests = [ | ||
["alphaBackground", false], | ||
["big-images", true], | ||
["border", false], | ||
["boxShadow", false], | ||
["fontAliasing", false], | ||
["imageCompression1", false], | ||
["imageCompression2", false], | ||
["imageCompression3", false], | ||
["imageCompression4", false], | ||
["imageCompression4", false], | ||
["simple", true], | ||
["tableAlpha", true], | ||
["minorChange1", true], | ||
["minorChange2", true], | ||
]; | ||
|
||
it("imageCompression", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ score: 0, width: 327, height: 665 }); | ||
}); | ||
|
||
it("imageCompression2", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression2/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression2/base.png"), | ||
}), | ||
}); | ||
|
||
expect(result).toEqual({ | ||
height: 665, | ||
score: 0, | ||
width: 327, | ||
}); | ||
}); | ||
describe("#diffImages", () => { | ||
test.each(tests)("diffImages %s", async (name, hasDiff) => { | ||
const dir = resolve(__dirname, `__fixtures__/${name}`); | ||
|
||
it("imageCompression3", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression3/compare.png"), | ||
const result = await diffImages( | ||
new LocalImageFile({ | ||
filepath: resolve(dir, "compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/imageCompression3/base.png"), | ||
new LocalImageFile({ | ||
filepath: resolve(dir, "base.png"), | ||
}), | ||
}); | ||
); | ||
|
||
expect(result).toEqual({ | ||
score: 0.0000729166666667, | ||
width: 1280, | ||
height: 600, | ||
}); | ||
}); | ||
const diffPath = resolve(dir, "diff_tmp.png"); | ||
await unlink(diffPath).catch(() => {}); | ||
|
||
it("big images", async () => { | ||
const { filepath, ...result } = await diffImages({ | ||
baseImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/big-images/compare.png"), | ||
}), | ||
compareImage: new LocalImageFile({ | ||
filepath: join(__dirname, "__fixtures__/big-images/base.png"), | ||
}), | ||
}); | ||
if (result) { | ||
await copyFile(result.filepath, diffPath); | ||
} | ||
|
||
expect(result).toEqual({ | ||
score: 0.846446632356, | ||
width: 1000, | ||
height: 4469, | ||
}); | ||
expect(Boolean(result)).toBe(hasDiff); | ||
}); | ||
}); |
Oops, something went wrong.