Skip to content

Commit 1ae998f

Browse files
committed
ignore baseline if cannot open image
1 parent 36072fc commit 1ae998f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/test-runs/test-runs.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2-
import { PNG } from 'pngjs';
2+
import { PNG, PNGWithMetadata } from 'pngjs';
33
import Pixelmatch from 'pixelmatch';
44
import { CreateTestRequestDto } from 'src/test/dto/create-test-request.dto';
55
import { IgnoreAreaDto } from 'src/test/dto/ignore-area.dto';
@@ -49,7 +49,7 @@ export class TestRunsService {
4949
// save new baseline
5050
const baseline = this.staticService.getImage(testRun.imageName)
5151
const imageName = `${Date.now()}.baseline.png`;
52-
this.staticService.saveImage(imageName, baseline.data);
52+
this.staticService.saveImage(imageName, PNG.sync.write(baseline));
5353

5454
return this.prismaService.testRun.update({
5555
where: { id },
@@ -108,10 +108,18 @@ export class TestRunsService {
108108
status: TestStatus.new,
109109
};
110110

111-
// compare with baseline
111+
// get baseline image
112+
let baseline: PNGWithMetadata
112113
if (testVariation.baselineName) {
113-
const baseline = this.staticService.getImage(testVariation.baselineName);
114+
try {
115+
baseline = this.staticService.getImage(testVariation.baselineName)
116+
} catch (ex) {
117+
console.log(`Cannot load baseline image: ${testVariation.baselineName}. ${ex}`)
118+
}
119+
}
114120

121+
// compare with baseline
122+
if (baseline) {
115123
const diffImageKey = `${Date.now()}.diff.png`;
116124
const diff = new PNG({
117125
width: baseline.width,

0 commit comments

Comments
 (0)