Skip to content

Commit 9347227

Browse files
authored
Merge pull request #6 from Visual-Regression-Tracker/32-recalculate
32 recalculate
2 parents e3cb2e7 + 25d571a commit 9347227

File tree

5 files changed

+330
-137
lines changed

5 files changed

+330
-137
lines changed

src/shared/static/static.service.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ import { ConfigService } from '@nestjs/config';
66

77
@Injectable()
88
export class StaticService {
9-
constructor(private configService: ConfigService) {
10-
}
9+
constructor(private configService: ConfigService) {}
1110

1211
saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): string {
13-
const imageName = `${Date.now()}.${type}.png`
12+
const imageName = `${Date.now()}.${type}.png`;
1413
writeFileSync(this.getImagePath(imageName), imageBuffer);
15-
return imageName
14+
return imageName;
1615
}
1716

1817
getImage(imageName: string): PNGWithMetadata {
19-
let image: PNGWithMetadata
18+
if (!imageName) return;
19+
let image: PNGWithMetadata;
2020
try {
21-
image = PNG.sync.read(readFileSync(this.getImagePath(imageName)))
21+
image = PNG.sync.read(readFileSync(this.getImagePath(imageName)));
2222
} catch (ex) {
23-
console.log(`Cannot image: ${imageName}. ${ex}`)
23+
console.log(`Cannot image: ${imageName}. ${ex}`);
2424
}
2525
return image;
2626
}
2727

2828
async deleteImage(imageName: string): Promise<boolean> {
29+
if (!imageName) return;
2930
return new Promise((resolvePromise, reject) => {
3031
unlink(this.getImagePath(imageName), err => {
3132
if (err) {
@@ -37,18 +38,18 @@ export class StaticService {
3738
}
3839

3940
private getImagePath(imageName: string): string {
40-
const dir = this.configService.get('IMG_UPLOAD_FOLDER')
41-
this.ensureDirectoryExistence(dir)
41+
const dir = this.configService.get('IMG_UPLOAD_FOLDER');
42+
this.ensureDirectoryExistence(dir);
4243
return path.resolve(dir, imageName);
4344
}
4445

4546
private ensureDirectoryExistence(dir: string) {
46-
const filePath = path.resolve(dir)
47+
const filePath = path.resolve(dir);
4748
if (existsSync(filePath)) {
4849
return true;
4950
} else {
5051
mkdirSync(dir, { recursive: true });
51-
this.ensureDirectoryExistence(dir)
52+
this.ensureDirectoryExistence(dir);
5253
}
5354
}
5455
}

src/test-runs/diffResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TestStatus } from '@prisma/client';
22

33
export interface DiffResult {
44
status: TestStatus;
5-
imageName: string;
5+
diffName: string;
66
pixelMisMatchCount: number;
77
diffPercent: number;
88
isSameDimension: boolean;

src/test-runs/test-runs.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export class TestRunsController {
1818
return this.testRunsService.findMany(buildId);
1919
}
2020

21+
@Get('recalculateDiff/:id')
22+
@ApiParam({ name: 'id', required: true })
23+
@ApiBearerAuth()
24+
@UseGuards(JwtAuthGuard)
25+
recalculateDiff(@Param('id', new ParseUUIDPipe()) id: string): Promise<TestRun> {
26+
return this.testRunsService.recalculateDiff(id);
27+
}
28+
2129
@Get('approve/:id')
2230
@ApiParam({ name: 'id', required: true })
2331
@ApiBearerAuth()

0 commit comments

Comments
 (0)