MCPcopy
hub / github.com/jwagner/simplex-noise.js / assertMatchesImage

Function assertMatchesImage

test/matches-snapshot.ts:14–38  ·  view source on GitHub ↗
(actual: ImageDataLike, imageFilename: string)

Source from the content-addressed store, hash-verified

12};
13
14export function assertMatchesImage(actual: ImageDataLike, imageFilename: string): void {
15 if (!imageFilename.endsWith('.png')) {
16 console.log('throwing');
17 throw new Error('imageFilename must end in .png');
18 }
19 let fileBuffer;
20 try {
21 fileBuffer = fs.readFileSync(path.join(snapshotsPath, imageFilename));
22 }
23 catch (_) {
24 writeImageSnapshot(actual, imageFilename);
25 return;
26 }
27 const png = PNG.sync.read(fileBuffer);
28 if (actual.data.length * 4 !== png.data.length) {
29 throw new Error('Expected actual.length to match png.data.length');
30 }
31 const identical = actual.data.every((value, i) => value == png.data[i * 4]);
32 if (!identical) {
33 console.log(png.data);
34 writeImageSnapshot(actual, imageFilename.replace('.png', '.error.png'));
35 throw new Error('expected data to be identitcal');
36 }
37
38}
39
40function writeImageSnapshot(actual: ImageDataLike, imageFilename: string) {
41 const png = new PNG({

Callers 1

Calls 1

writeImageSnapshotFunction · 0.85

Tested by

no test coverage detected