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();