Skip to content

Commit de9579e

Browse files
committed
fix: multiple fixes
- fix pipeline - fix native app rectangles
1 parent 140f787 commit de9579e

3 files changed

Lines changed: 110 additions & 8 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
steps:
2424
- name: 🧐 Determine Job to Run
2525
id: set-vars
26+
shell: bash
2627
run: |
2728
PR_TITLE="${{ github.event.pull_request.title }}"
2829
UNIT_TEST_REGEX='(@typescript-eslint|vitest|eslint|@types|@tsconfig|ts-node|jsdom|typescript)'

packages/image-comparison-core/src/methods/rectangles.test.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,5 +1455,100 @@ describe('rectangles', () => {
14551455
expect(result.hasIgnoreRectangles).toBe(true)
14561456
expect(result.ignoredBoxes).toMatchSnapshot()
14571457
})
1458+
1459+
it('should scale ignoreRegions by DPR for native iOS app (logical → device pixels)', async () => {
1460+
const options = createPrepareIgnoreRectanglesOptions({
1461+
ignoreRegions: [
1462+
{ x: 10, y: 20, width: 100, height: 50 },
1463+
],
1464+
devicePixelRatio: 3,
1465+
isMobile: true,
1466+
isNativeContext: true,
1467+
isAndroid: false,
1468+
})
1469+
1470+
const result = await prepareIgnoreRectangles(options)
1471+
1472+
expect(result.hasIgnoreRectangles).toBe(true)
1473+
expect(result.ignoredBoxes).toHaveLength(1)
1474+
expect(result.ignoredBoxes[0]).toEqual({
1475+
left: 30,
1476+
top: 60,
1477+
right: 330,
1478+
bottom: 210,
1479+
})
1480+
})
1481+
1482+
it('should scale multiple ignoreRegions by DPR for native iOS app', async () => {
1483+
const options = createPrepareIgnoreRectanglesOptions({
1484+
ignoreRegions: [
1485+
{ x: 0, y: 0, width: 390, height: 47 },
1486+
{ x: 50, y: 100, width: 200, height: 80 },
1487+
],
1488+
devicePixelRatio: 3,
1489+
isMobile: true,
1490+
isNativeContext: true,
1491+
isAndroid: false,
1492+
})
1493+
1494+
const result = await prepareIgnoreRectangles(options)
1495+
1496+
expect(result.hasIgnoreRectangles).toBe(true)
1497+
expect(result.ignoredBoxes).toHaveLength(2)
1498+
expect(result.ignoredBoxes[0]).toEqual({
1499+
left: 0,
1500+
top: 0,
1501+
right: 1170,
1502+
bottom: 141,
1503+
})
1504+
expect(result.ignoredBoxes[1]).toEqual({
1505+
left: 150,
1506+
top: 300,
1507+
right: 750,
1508+
bottom: 540,
1509+
})
1510+
})
1511+
1512+
it('should not scale ignoreRegions for native Android app', async () => {
1513+
const options = createPrepareIgnoreRectanglesOptions({
1514+
ignoreRegions: [{ x: 100, y: 200, width: 150, height: 75 }],
1515+
devicePixelRatio: 3,
1516+
isMobile: true,
1517+
isNativeContext: true,
1518+
isAndroid: true,
1519+
})
1520+
1521+
const result = await prepareIgnoreRectangles(options)
1522+
1523+
expect(result.hasIgnoreRectangles).toBe(true)
1524+
expect(result.ignoredBoxes).toHaveLength(1)
1525+
expect(result.ignoredBoxes[0]).toEqual({
1526+
left: 100,
1527+
top: 200,
1528+
right: 250,
1529+
bottom: 275,
1530+
})
1531+
})
1532+
1533+
it('should not scale ignoreRegions when not native context (e.g. web)', async () => {
1534+
const options = createPrepareIgnoreRectanglesOptions({
1535+
ignoreRegions: [{ x: 10, y: 20, width: 100, height: 50 }],
1536+
devicePixelRatio: 3,
1537+
isMobile: true,
1538+
isNativeContext: false,
1539+
isAndroid: false,
1540+
})
1541+
1542+
const result = await prepareIgnoreRectangles(options)
1543+
1544+
expect(result.hasIgnoreRectangles).toBe(true)
1545+
expect(result.ignoredBoxes).toHaveLength(1)
1546+
expect(result.ignoredBoxes[0]).toEqual({
1547+
left: 10,
1548+
top: 20,
1549+
right: 110,
1550+
bottom: 70,
1551+
})
1552+
})
14581553
})
14591554
})

packages/image-comparison-core/src/methods/rectangles.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,22 @@ export async function prepareIgnoreRectangles(options: PrepareIgnoreRectanglesOp
657657
},
658658
)
659659

660-
// ignoreRegions are already in device pixels (pre-scaled by the caller),
661-
// only convert to the ResembleJS format (top/left/bottom/right)
662-
const preScaledIgnoreBoxes = ignoreRegions.map(
663-
(rectangles) => ({
664-
bottom: rectangles.y + rectangles.height,
665-
right: rectangles.x + rectangles.width,
660+
// ignoreRegions: for web they are already in device pixels (pre-scaled by the caller).
661+
// For native iOS app they are in logical pixels (getElementRect / statusBar/homeBar),
662+
// so we scale by DPR here to match the device-pixel screenshot.
663+
const isNativeIos = isNativeContext && isMobile && !isAndroid
664+
const preScaledIgnoreBoxes = ignoreRegions.map((rectangles) => {
665+
const box = {
666666
left: rectangles.x,
667667
top: rectangles.y,
668-
}),
669-
)
668+
right: rectangles.x + rectangles.width,
669+
bottom: rectangles.y + rectangles.height,
670+
}
671+
if (isNativeIos) {
672+
return calculateDprData({ ...box }, devicePixelRatio)
673+
}
674+
return box
675+
})
670676

671677
const ignoredBoxes = [...dprScaledBoxes, ...preScaledIgnoreBoxes]
672678

0 commit comments

Comments
 (0)