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>
This commit is contained in:
lijianan
2025-09-14 18:08:55 +08:00
committed by GitHub
parent 21e88f1f05
commit 6e72e7bfbe

View File

@@ -46,9 +46,7 @@ export default function imageTest(
let container: HTMLDivElement;
beforeAll(async () => {
const dom = new JSDOM('<!DOCTYPE html><body></body></html>', {
url: 'http://localhost/',
});
const dom = new JSDOM('<!DOCTYPE html><body></body></html>', { url: 'http://localhost/' });
const win = dom.window;
doc = win.document;
@@ -112,6 +110,14 @@ export default function imageTest(
container = doc.querySelector<HTMLDivElement>('#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();