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
7 changes: 6 additions & 1 deletion src/shared/events/events.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export class EventsGateway {
this.server.emit('build_updated', build);
}

newTestRun(testRun: TestRun): void {
testRunCreated(testRun: TestRun): void {
this.server.emit('testRun_created', testRun);
}


testRunDeleted(testRun: TestRun): void {
this.server.emit('testRun_deleted', testRun);
}
}
25 changes: 12 additions & 13 deletions src/test-runs/test-runs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const initService = async ({
getImageMock = jest.fn(),
saveImageMock = jest.fn(),
deleteImageMock = jest.fn(),
eventNewTestRunMock = jest.fn(),
eventTestRunCreatedMock = jest.fn(),
eventTestRunDeletedMock = jest.fn(),
eventBuildUpdatedMock = jest.fn(),
eventBuildCreatedMock = jest.fn(),
buildFindOneMock = jest.fn(),
Expand Down Expand Up @@ -79,7 +80,8 @@ const initService = async ({
{
provide: EventsGateway,
useValue: {
newTestRun: eventNewTestRunMock,
testRunCreated: eventTestRunCreatedMock,
testRunDeleted: eventTestRunDeletedMock,
buildUpdated: eventBuildUpdatedMock,
buildCreated: eventBuildCreatedMock,
},
Expand Down Expand Up @@ -467,12 +469,9 @@ describe('TestRunsService', () => {
const saveImageMock = jest.fn().mockReturnValueOnce(imageName);
const image = 'image';
const baseline = 'baseline';
const getImageMock = jest
.fn()
.mockReturnValueOnce(baseline)
.mockReturnValueOnce(image);
const eventNewTestRunMock = jest.fn();
service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock });
const getImageMock = jest.fn().mockReturnValueOnce(baseline).mockReturnValueOnce(image);
const eventTestRunCreatedMock = jest.fn();
service = await initService({ testRunCreateMock, saveImageMock, getImageMock, eventTestRunCreatedMock });
const diffResult: DiffResult = {
status: TestStatus.unresolved,
diffName: 'diff image name',
Expand Down Expand Up @@ -526,7 +525,7 @@ describe('TestRunsService', () => {
});
expect(getDiffMock).toHaveBeenCalledWith(baseline, image, testRun.diffTollerancePercent, testRun.ignoreAreas);
expect(saveDiffResultMock).toHaveBeenCalledWith(testRun.id, diffResult);
expect(eventNewTestRunMock).toHaveBeenCalledWith(testRunWithResult);
expect(eventTestRunCreatedMock).toHaveBeenCalledWith(testRunWithResult);
expect(result).toBe(testRunWithResult);
});

Expand Down Expand Up @@ -665,10 +664,7 @@ describe('TestRunsService', () => {
const testRunUpdateMock = jest.fn();
const baselineMock = 'baseline image';
const imageeMock = 'image';
const getImageMock = jest
.fn()
.mockReturnValueOnce(baselineMock)
.mockReturnValueOnce(imageeMock);
const getImageMock = jest.fn().mockReturnValueOnce(baselineMock).mockReturnValueOnce(imageeMock);
const deleteImageMock = jest.fn();
const diffResult = {
id: 'test',
Expand Down Expand Up @@ -770,9 +766,11 @@ describe('TestRunsService', () => {
const findOneMock = jest.fn().mockResolvedValueOnce(testRun);
const deleteImageMock = jest.fn();
const testRunDeleteMock = jest.fn();
const eventTestRunDeletedMock = jest.fn();
service = await initService({
deleteImageMock,
testRunDeleteMock,
eventTestRunDeletedMock,
});
service.findOne = findOneMock;

Expand All @@ -784,6 +782,7 @@ describe('TestRunsService', () => {
expect(testRunDeleteMock).toHaveBeenCalledWith({
where: { id },
});
expect(eventTestRunDeletedMock).toHaveBeenCalledWith(testRun);
});

it('updateIgnoreAreas', async () => {
Expand Down
17 changes: 11 additions & 6 deletions src/test-runs/test-runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,23 @@ export class TestRunsService {
const diffResult = this.getDiff(baseline, image, testRun.diffTollerancePercent, testVariation.ignoreAreas);

const testRunWithResult = await this.saveDiffResult(testRun.id, diffResult);
this.eventsGateway.newTestRun(testRunWithResult);
this.eventsGateway.testRunCreated(testRunWithResult);
return testRunWithResult;
}

async delete(id: string): Promise<TestRun> {
const testRun = await this.findOne(id);

Promise.all([this.staticService.deleteImage(testRun.diffName), this.staticService.deleteImage(testRun.imageName)]);
await Promise.all([
this.staticService.deleteImage(testRun.diffName),
this.staticService.deleteImage(testRun.imageName),
this.prismaService.testRun.delete({
where: { id },
}),
]);

return this.prismaService.testRun.delete({
where: { id },
});
this.eventsGateway.testRunDeleted(testRun);
return testRun;
}

async updateIgnoreAreas(id: string, ignoreAreas: IgnoreAreaDto[]): Promise<TestRun> {
Expand Down Expand Up @@ -310,7 +315,7 @@ export class TestRunsService {
}

private applyIgnoreAreas(image: PNG, ignoreAreas: IgnoreAreaDto[]): Buffer {
ignoreAreas.forEach(area => {
ignoreAreas.forEach((area) => {
for (let y = area.y; y < area.y + area.height; y++) {
for (let x = area.x; x < area.x + area.width; x++) {
const k = 4 * (image.width * y + x);
Expand Down