From c465e04c815f4bb8ecdd92b6fb9f2f61dc387093 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Sun, 15 Nov 2020 22:14:17 +0800 Subject: [PATCH] test: disable image request --- tests/shared/imageTest.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/shared/imageTest.ts b/tests/shared/imageTest.ts index dd7c36016e..1e07f8bacc 100644 --- a/tests/shared/imageTest.ts +++ b/tests/shared/imageTest.ts @@ -17,7 +17,18 @@ expect.extend({ toMatchImageSnapshot }); // eslint-disable-next-line jest/no-export export default function imageTest(component: React.ReactElement) { it('component image screenshot should correct', async () => { + await jestPuppeteer.resetPage(); + await page.setRequestInterception(true); + const onRequestHandle = (request: any) => { + if (['image'].indexOf(request.resourceType()) !== -1) { + request.abort(); + } else { + request.continue(); + } + }; + MockDate.set(moment('2016-11-22').valueOf()); + page.on('request', onRequestHandle); await page.goto(`file://${process.cwd()}/tests/index.html`); await page.addStyleTag({ path: `${process.cwd()}/dist/antd.css` }); const html = ReactDOMServer.renderToString(component); @@ -30,6 +41,7 @@ export default function imageTest(component: React.ReactElement) { expect(image).toMatchImageSnapshot(); MockDate.reset(); + page.removeListener('request', onRequestHandle); }); }