Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/test-runs/dto/create-test-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsOptional, IsUUID, IsNumber, IsBoolean, IsBase64 } from 'class-validator';
import { BaselineDataDto } from '../../shared/dto/baseline-data.dto';
import { IgnoreAreaDto } from './ignore-area.dto';

export class CreateTestRequestDto extends BaselineDataDto {
@ApiProperty()
Expand All @@ -26,4 +27,8 @@ export class CreateTestRequestDto extends BaselineDataDto {
@IsBoolean()
@IsOptional()
merge?: boolean;

@ApiProperty({ type: [IgnoreAreaDto] })
@IsOptional()
ignoreAreas?: IgnoreAreaDto[];
}
43 changes: 29 additions & 14 deletions src/test-runs/test-runs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ describe('TestRunsService', () => {
diffTollerancePercent: undefined,
branchName: 'develop',
merge: true,
ignoreAreas: [
{
x: 1,
y: 2,
width: 100,
height: 200,
},
],
};
const testRunWithResult = {
id: 'id',
Expand Down Expand Up @@ -457,7 +465,7 @@ describe('TestRunsService', () => {
browser: 'browser',
viewport: 'viewport',
device: 'device',
ignoreAreas: '[]',
ignoreAreas: '[{"x":3,"y":4,"width":500,"height":600}]',
comment: 'some comment',
createdAt: new Date(),
updatedAt: new Date(),
Expand Down Expand Up @@ -487,12 +495,6 @@ describe('TestRunsService', () => {
const result = await service.create(testVariation, createTestRequestDto);

expect(saveImageMock).toHaveBeenCalledWith('screenshot', Buffer.from(createTestRequestDto.imageBase64, 'base64'));
expect(service.getDiff).toHaveBeenCalledWith(
baseline,
image,
testRun.diffTollerancePercent,
testVariation.ignoreAreas
);
expect(getImageMock).toHaveBeenNthCalledWith(1, testVariation.baselineName);
expect(getImageMock).toHaveBeenNthCalledWith(2, imageName);
expect(testRunCreateMock).toHaveBeenCalledWith({
Expand Down Expand Up @@ -523,7 +525,20 @@ describe('TestRunsService', () => {
status: TestStatus.new,
},
});
expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, [
{
x: 3,
y: 4,
width: 500,
height: 600,
},
{
x: 1,
y: 2,
width: 100,
height: 200,
},
]);
expect(saveDiffResultMock).toHaveBeenCalledWith(testRun.id, diffResult);
expect(eventTestRunCreatedMock).toHaveBeenCalledWith(testRunWithResult);
expect(result).toBe(testRunWithResult);
Expand All @@ -538,7 +553,7 @@ describe('TestRunsService', () => {
});
service = await initService({});

const result = service.getDiff(baseline, image, 0, '[]');
const result = service.getDiff(baseline, image, 0, []);

expect(result).toStrictEqual({
status: undefined,
Expand All @@ -560,7 +575,7 @@ describe('TestRunsService', () => {
});
service = await initService({});

const result = service.getDiff(baseline, image, 0, '[]');
const result = service.getDiff(baseline, image, 0, []);

expect(result).toStrictEqual({
status: TestStatus.unresolved,
Expand All @@ -583,7 +598,7 @@ describe('TestRunsService', () => {
service = await initService({});
mocked(Pixelmatch).mockReturnValueOnce(0);

const result = service.getDiff(baseline, image, 0, '[]');
const result = service.getDiff(baseline, image, 0, []);

expect(result).toStrictEqual({
status: TestStatus.ok,
Expand All @@ -608,7 +623,7 @@ describe('TestRunsService', () => {
const pixelMisMatchCount = 150;
mocked(Pixelmatch).mockReturnValueOnce(pixelMisMatchCount);

const result = service.getDiff(baseline, image, 1.5, '[]');
const result = service.getDiff(baseline, image, 1.5, []);

expect(saveImageMock).toHaveBeenCalledTimes(0);
expect(result).toStrictEqual({
Expand Down Expand Up @@ -637,7 +652,7 @@ describe('TestRunsService', () => {
saveImageMock,
});

const result = service.getDiff(baseline, image, 1, '[]');
const result = service.getDiff(baseline, image, 1, []);

expect(saveImageMock).toHaveBeenCalledTimes(1);
expect(result).toStrictEqual({
Expand Down Expand Up @@ -689,7 +704,7 @@ describe('TestRunsService', () => {
baselineMock,
imageeMock,
testRun.diffTollerancePercent,
testRun.ignoreAreas
JSON.parse(testRun.ignoreAreas)
);
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId);
});
Expand Down
14 changes: 9 additions & 5 deletions src/test-runs/test-runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class TestRunsService {
const image = this.staticService.getImage(testRun.imageName);
await this.staticService.deleteImage(testRun.diffName);

const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, JSON.parse(testRun.ignoreAreas));
const updatedTestRun = await this.saveDiffResult(id, diffResult);
this.emitUpdateBuildEvent(testRun.buildId);
return updatedTestRun;
Expand Down Expand Up @@ -227,7 +227,11 @@ export class TestRunsService {
const baseline = this.staticService.getImage(testRun.baselineName);
const image = this.staticService.getImage(imageName);

const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas);
let ignoreAreas: IgnoreAreaDto[] = JSON.parse(testVariation.ignoreAreas);
if (createTestRequestDto.ignoreAreas?.length > 0) {
ignoreAreas = ignoreAreas.concat(createTestRequestDto.ignoreAreas);
}
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, ignoreAreas);

const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult);
this.eventsGateway.testRunCreated(testRunWithResult);
Expand Down Expand Up @@ -267,7 +271,7 @@ export class TestRunsService {
});
}

getDiff(baseline: PNG, image: PNG, diffTollerancePercent: number, ignoreAreas: string): DiffResult {
getDiff(baseline: PNG, image: PNG, diffTollerancePercent: number, ignoreAreas: IgnoreAreaDto[]): DiffResult {
const result: DiffResult = {
status: undefined,
diffName: null,
Expand All @@ -287,8 +291,8 @@ export class TestRunsService {

// compare
result.pixelMisMatchCount = Pixelmatch(
this.applyIgnoreAreas(baseline, JSON.parse(ignoreAreas)),
this.applyIgnoreAreas(image, JSON.parse(ignoreAreas)),
this.applyIgnoreAreas(baseline, ignoreAreas),
this.applyIgnoreAreas(image, ignoreAreas),
diff.data,
baseline.width,
baseline.height,
Expand Down
2 changes: 2 additions & 0 deletions src/test-variations/test-variations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,15 @@ describe('TestVariationsService', () => {
imageBase64: PNG.sync.write(image).toString('base64'),
diffTollerancePercent: 0,
merge: true,
ignoreAreas: JSON.parse(testVariation.ignoreAreas),
});
expect(testRunCreateMock).toHaveBeenNthCalledWith(2, testVariationMainBranch, {
...testVariationSecond,
buildId: build.id,
imageBase64: PNG.sync.write(image).toString('base64'),
diffTollerancePercent: 0,
merge: true,
ignoreAreas: JSON.parse(testVariationSecond.ignoreAreas),
});
expect(testRunCreateMock).toHaveBeenCalledTimes(2);
expect(buildStopMock).toHaveBeenCalledWith(build.id);
Expand Down
1 change: 1 addition & 0 deletions src/test-variations/test-variations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class TestVariationsService {
imageBase64,
diffTollerancePercent: 0,
merge: true,
ignoreAreas: JSON.parse(sideBranchTestVariation.ignoreAreas)
};

return this.testRunsService.create(mainBranchTestVariation, createTestRequestDto);
Expand Down