Skip to content

Commit 5f93444

Browse files
authored
Merge pull request #1 from Visual-Regression-Tracker/7-baseline_image_removed
Baseline image is removed together with test
2 parents 46527ff + 1ae998f commit 5f93444

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 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';
@@ -40,6 +40,17 @@ export class TestRunsService {
4040
testVariation: TestVariation;
4141
}> {
4242
const testRun = await this.findOne(id);
43+
44+
// remove old baseline
45+
if (testRun.testVariation.baselineName) {
46+
this.staticService.deleteImage(testRun.testVariation.baselineName);
47+
}
48+
49+
// save new baseline
50+
const baseline = this.staticService.getImage(testRun.imageName)
51+
const imageName = `${Date.now()}.baseline.png`;
52+
this.staticService.saveImage(imageName, PNG.sync.write(baseline));
53+
4354
return this.prismaService.testRun.update({
4455
where: { id },
4556
include: {
@@ -49,7 +60,7 @@ export class TestRunsService {
4960
status: TestStatus.ok,
5061
testVariation: {
5162
update: {
52-
baselineName: testRun.imageName,
63+
baselineName: imageName,
5364
},
5465
},
5566
},
@@ -97,10 +108,18 @@ export class TestRunsService {
97108
status: TestStatus.new,
98109
};
99110

100-
// compare with baseline
111+
// get baseline image
112+
let baseline: PNGWithMetadata
101113
if (testVariation.baselineName) {
102-
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+
}
103120

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

0 commit comments

Comments
 (0)