Skip to content

Commit

Permalink
fix: e2e wait for canvas render
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Sep 25, 2024
1 parent 2fc56ff commit 4d0b948
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 7 additions & 9 deletions e2e/perf/scroll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ async function measureFPS(page: Page, testDuration = 5, deltaX: number, deltaY:
};

// start mock wheel event.
continuousWheelSimulation(filteredCanvasElements[0], interval);
if (filteredCanvasElements.length > 0) {
continuousWheelSimulation(filteredCanvasElements[0], interval);
} else {
throw new Error('main canvas element not found');
}
};

const getMaxFrameTimes = (arr, n) => {
Expand Down Expand Up @@ -146,15 +150,8 @@ const createTest = (title: string, sheetData: IJsonObject, minFpsValue: number,
window.E2EControllerAPI.disposeCurrSheetUnit();
window.univer.createUniverSheet(sheetData);
}, { sheetData, window: windowOfPage });

// wait for canvas has data
// await page.waitForFunction(() => {
// const canvaslist = document.querySelectorAll('canvas');
// if (canvaslist.length > 2) {
// const imgData = canvaslist[2]!.getContext('2d')!.getImageData(40, 40, 1, 1).data;
// return imgData[3] !== 0;
// }
// });
await page.waitForTimeout(2000);
});

try {
Expand All @@ -168,6 +165,7 @@ const createTest = (title: string, sheetData: IJsonObject, minFpsValue: number,
} catch (error) {
console.error('error when exec scrolling test', error);
} finally {
// if you want to debug, use `await page.pause();` to pause browser
console.log('Test case completed.');
}
});
Expand Down
5 changes: 1 addition & 4 deletions packages/engine-render/src/basics/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,7 @@ export function expandRangeIfIntersects(mainRanges: IRange[], ranges: IRange[])
}
}
}
// return [...mainRanges, ...intersects];
// mainRanges.push(...intersects);
// return mainRanges;
return mainRanges.concat(intersects); // concat is slightly faster than spread
return mainRanges.concat(intersects); // do not use [...mainRanges, ...intersects], because concat is slightly faster than spread
}

export function clampRanges(range: IRange) {
Expand Down

0 comments on commit 4d0b948

Please sign in to comment.