From 6e72e7bfbee81cadf968829ca896c3510c736d8a Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sun, 14 Sep 2025 18:08:55 +0800 Subject: [PATCH] test: add removeAllListeners for imageTest (#55015) * test: add try/catch for visual diff * Update tests/shared/imageTest.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: lijianan <574980606@qq.com> * update * update * update --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/shared/imageTest.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/shared/imageTest.tsx b/tests/shared/imageTest.tsx index 79bfe97d13..2c52f2cd1d 100644 --- a/tests/shared/imageTest.tsx +++ b/tests/shared/imageTest.tsx @@ -46,9 +46,7 @@ export default function imageTest( let container: HTMLDivElement; beforeAll(async () => { - const dom = new JSDOM('', { - url: 'http://localhost/', - }); + const dom = new JSDOM('', { url: 'http://localhost/' }); const win = dom.window; doc = win.document; @@ -112,6 +110,14 @@ export default function imageTest( container = doc.querySelector('#root')!; }); + afterEach(() => { + page.removeAllListeners('request'); // 保证没有历史残留 + }); + + afterAll(async () => { + await page.setRequestInterception(false); + }); + const test = ( name: string, suffix: string, @@ -234,7 +240,6 @@ export default function imageTest( ); await page.setViewport({ width: 800, height: bodyHeight, ...sharedViewportConfig }); } - const image = await page.screenshot({ fullPage: !options.onlyViewport }); await fse.writeFile(path.join(snapshotPath, `${identifier}${suffix}.png`), image); MockDate.reset();