Skip to content

Commit 7f5f049

Browse files
committed
test
1 parent 2653cb0 commit 7f5f049

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/compare/libs/odiff/odiff.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export class OdiffService implements ImageComparator {
2727
this.hddService = this.staticService as unknown as HddService;
2828
}
2929

30-
parseConfig(configJson: string): OdiffConfig {
31-
return parseConfig(configJson, DEFAULT_CONFIG, this.logger);
30+
parseConfig(configInput: string | OdiffConfig): OdiffConfig {
31+
if (typeof configInput === 'string') {
32+
return parseConfig(configInput, DEFAULT_CONFIG, this.logger);
33+
}
34+
return { ...DEFAULT_CONFIG, ...configInput };
3235
}
3336

3437
async getDiff(data: ImageCompareInput, config: OdiffConfig): Promise<DiffResult> {

src/compare/libs/pixelmatch/pixelmatch.service.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { PixelmatchConfig } from './pixelmatch.types';
88

99
const mockPixelmatch = jest.fn();
1010

11+
// Helper to create a Uint8Array for a PNG of given dimensions
12+
const createUint8ArrayForPng = (width: number, height: number): Uint8Array => {
13+
const png = new PNG({ width, height });
14+
// Access the underlying buffer and create a Uint8Array view
15+
return new Uint8Array(png.data.buffer, png.data.byteOffset, png.data.byteLength);
16+
};
17+
1118
const initService = async ({ getImageMock = jest.fn(), saveImageMock = jest.fn(), deleteImageMock = jest.fn() }) => {
1219
const module: TestingModule = await Test.createTestingModule({
1320
providers: [
@@ -129,6 +136,12 @@ describe('getDiff', () => {
129136
mockPixelmatch.mockReturnValueOnce(5);
130137
service = await initService({ saveImageMock, getImageMock });
131138

139+
const testConfig = {
140+
allowDiffDimensions: true,
141+
ignoreAntialiasing: true,
142+
threshold: 0.1,
143+
};
144+
132145
const result = await service.getDiff(
133146
{
134147
baseline: 'image',
@@ -137,31 +150,18 @@ describe('getDiff', () => {
137150
ignoreAreas: [],
138151
saveDiffAsFile: true,
139152
},
140-
{
141-
allowDiffDimensions: true,
142-
ignoreAntialiasing: true,
143-
threshold: 0.1,
144-
}
153+
testConfig
145154
);
146155

147156
expect(mockPixelmatch).toHaveBeenCalledWith(
148-
new PNG({
149-
width: 2,
150-
height: 5,
151-
}).data,
152-
new PNG({
153-
width: 2,
154-
height: 5,
155-
}).data,
156-
new PNG({
157-
width: 2,
158-
height: 5,
159-
}).data,
157+
createUint8ArrayForPng(2, 5),
158+
createUint8ArrayForPng(2, 5),
159+
createUint8ArrayForPng(2, 5),
160160
2,
161161
5,
162162
{
163-
includeAA: true,
164-
threshold: 0.1,
163+
includeAA: testConfig.ignoreAntialiasing,
164+
threshold: testConfig.threshold,
165165
}
166166
);
167167
expect(saveImageMock).toHaveBeenCalledTimes(1);

src/compare/libs/pixelmatch/pixelmatch.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ export class PixelmatchService implements ImageComparator {
2222
return pixelmatch;
2323
}
2424

25-
parseConfig(configJson: string): PixelmatchConfig {
26-
return parseConfig(configJson, DEFAULT_CONFIG, this.logger);
25+
parseConfig(configInput: string | PixelmatchConfig): PixelmatchConfig {
26+
if (typeof configInput === 'string') {
27+
return parseConfig(configInput, DEFAULT_CONFIG, this.logger);
28+
}
29+
return { ...DEFAULT_CONFIG, ...configInput };
2730
}
2831

2932
async getDiff(data: ImageCompareInput, config: PixelmatchConfig): Promise<DiffResult> {

0 commit comments

Comments
 (0)