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
75 changes: 38 additions & 37 deletions src/test-runs/test-runs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ describe('TestRunsService', () => {
});
});

it('diff not found', async () => {
const baseline = new PNG({
width: 20,
height: 20,
});
const image = new PNG({
width: 20,
height: 20,
});
service = await initService({});

const result = service.getDiff(baseline, image, baseTestRun);

expect(result).toStrictEqual({
status: TestStatus.ok,
diffName: null,
pixelMisMatchCount: 0,
diffPercent: 0,
isSameDimension: true,
});
});

it('diff image dimensions mismatch', async () => {
delete process.env.ALLOW_DIFF_DIMENSIONS;
const baseline = new PNG({
Expand All @@ -341,35 +363,35 @@ describe('TestRunsService', () => {
it('diff image dimensions mismatch ALLOWED', async () => {
process.env.ALLOW_DIFF_DIMENSIONS = 'true';
const baseline = new PNG({
width: 20,
height: 10,
width: 1,
height: 5,
});
const image = new PNG({
width: 10,
height: 20,
width: 2,
height: 4,
});
const diffName = 'diff name';
const saveImageMock = jest.fn().mockReturnValueOnce(diffName);
mocked(Pixelmatch).mockReturnValueOnce(200);
mocked(Pixelmatch).mockReturnValueOnce(5);
service = await initService({ saveImageMock });

const result = service.getDiff(baseline, image, baseTestRun);

expect(mocked(Pixelmatch)).toHaveBeenCalledWith(
new PNG({
width: 20,
height: 20,
width: 2,
height: 5,
}).data,
new PNG({
width: 20,
height: 20,
width: 2,
height: 5,
}).data,
new PNG({
width: 20,
height: 20,
width: 2,
height: 5,
}).data,
20,
20,
2,
5,
{
includeAA: true,
}
Expand All @@ -378,35 +400,12 @@ describe('TestRunsService', () => {
expect(result).toStrictEqual({
status: TestStatus.unresolved,
diffName,
pixelMisMatchCount: 200,
pixelMisMatchCount: 5,
diffPercent: 50,
isSameDimension: false,
});
});

it('diff not found', async () => {
const baseline = new PNG({
width: 10,
height: 10,
});
const image = new PNG({
width: 10,
height: 10,
});
service = await initService({});
mocked(Pixelmatch).mockReturnValueOnce(0);

const result = service.getDiff(baseline, image, baseTestRun);

expect(result).toStrictEqual({
status: TestStatus.ok,
diffName: null,
pixelMisMatchCount: 0,
diffPercent: 0,
isSameDimension: true,
});
});

it('diff found < tollerance', async () => {
const testRun: TestRun = {
...baseTestRun,
Expand All @@ -418,6 +417,7 @@ describe('TestRunsService', () => {
width: 100,
height: 100,
});
baseline.data[0] = 1
const image = new PNG({
width: 100,
height: 100,
Expand Down Expand Up @@ -450,6 +450,7 @@ describe('TestRunsService', () => {
width: 100,
height: 100,
});
baseline.data[0] = 1
const image = new PNG({
width: 100,
height: 100,
Expand Down
9 changes: 9 additions & 0 deletions src/test-runs/test-runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,20 @@ export class TestRunsService {

result.isSameDimension = baseline.width === image.width && baseline.height === image.height;

if (baseline.data.equals(image.data)) {
// equal images
result.status = TestStatus.ok;
result.pixelMisMatchCount = 0;
result.diffPercent = 0;
return result;
}

if (!result.isSameDimension && !process.env.ALLOW_DIFF_DIMENSIONS) {
// diff dimensions
result.status = TestStatus.unresolved;
return result;
}

// scale image to max size
const maxWidth = Math.max(baseline.width, image.width);
const maxHeight = Math.max(baseline.height, image.height);
Expand Down