mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
ci: implement screenshot diffing (#2571)
This commit is contained in:

committed by
GitHub

parent
171585491d
commit
e29af58661
32
tests/reftest-diff.ts
Normal file
32
tests/reftest-diff.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import {sync} from 'glob';
|
||||
import {resolve, basename} from 'path';
|
||||
import {existsSync, promises} from 'fs';
|
||||
import {toMatchImageSnapshot} from 'jest-image-snapshot';
|
||||
|
||||
const resultsDir = resolve(__dirname, '../results');
|
||||
const customSnapshotsDir = resolve(__dirname, '../tmp/snapshots');
|
||||
const customDiffDir = resolve(__dirname, '../tmp/snapshot-diffs');
|
||||
|
||||
expect.extend({toMatchImageSnapshot});
|
||||
|
||||
describe('Image diff', () => {
|
||||
const files: string[] = sync('../tmp/reftests/**/*.png', {
|
||||
cwd: __dirname,
|
||||
root: resolve(__dirname, '../../')
|
||||
}).filter((path) => existsSync(resolve(resultsDir, basename(path))));
|
||||
|
||||
it.each(files.map((path) => basename(path)))('%s', async (filename) => {
|
||||
const previous = resolve(resultsDir, filename);
|
||||
const previousSnap = resolve(customSnapshotsDir, `${filename}-snap.png`);
|
||||
await promises.copyFile(previous, previousSnap);
|
||||
const updated = resolve(__dirname, '../tmp/reftests/', filename);
|
||||
const buffer = await promises.readFile(updated);
|
||||
|
||||
// @ts-ignore
|
||||
expect(buffer).toMatchImageSnapshot({
|
||||
customSnapshotsDir,
|
||||
customSnapshotIdentifier: () => filename,
|
||||
customDiffDir
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user