mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
type: replace any with HTTPRequest (#48737)
* chore: code optimization * fix: fix * fix: fix * fix: fix --------- Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
parent
aa0a90fdd5
commit
13c5801ac1
@ -1,13 +1,13 @@
|
||||
import path from 'path';
|
||||
import React from 'react';
|
||||
// Reference: https://github.com/ant-design/ant-design/pull/24003#discussion_r427267386
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs';
|
||||
import dayjs from 'dayjs';
|
||||
import fse from 'fs-extra';
|
||||
import { globSync } from 'glob';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import MockDate from 'mockdate';
|
||||
import type { HTTPRequest } from 'puppeteer';
|
||||
import ReactDOMServer from 'react-dom/server';
|
||||
|
||||
import { App, ConfigProvider, theme } from '../../components';
|
||||
@ -72,7 +72,7 @@ export default function imageTest(
|
||||
unobserve() {},
|
||||
disconnect() {},
|
||||
};
|
||||
} as any;
|
||||
} as unknown as typeof ResizeObserver;
|
||||
|
||||
// Fake promise not called
|
||||
global.fetch = function mockFetch() {
|
||||
@ -87,15 +87,14 @@ export default function imageTest(
|
||||
return this;
|
||||
},
|
||||
};
|
||||
} as any;
|
||||
} as unknown as typeof fetch;
|
||||
|
||||
// Fake matchMedia
|
||||
win.matchMedia = () =>
|
||||
({
|
||||
matches: false,
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
}) as any;
|
||||
win.matchMedia = (() => ({
|
||||
matches: false,
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
})) as unknown as typeof matchMedia;
|
||||
|
||||
// Fill window
|
||||
fillWindowEnv(win);
|
||||
@ -112,7 +111,7 @@ export default function imageTest(
|
||||
it(name, async () => {
|
||||
await page.setViewport({ width: 800, height: 600 });
|
||||
|
||||
const onRequestHandle = (request: any) => {
|
||||
const onRequestHandle = (request: HTTPRequest) => {
|
||||
if (['image'].includes(request.resourceType())) {
|
||||
request.abort();
|
||||
} else {
|
||||
@ -178,20 +177,17 @@ export default function imageTest(
|
||||
}
|
||||
|
||||
await page.evaluate(
|
||||
(innerHTML, ssrStyle, triggerClassName) => {
|
||||
document.querySelector('#root')!.innerHTML = innerHTML;
|
||||
|
||||
const head = document.querySelector('head')!;
|
||||
(innerHTML: string, ssrStyle: string, triggerClassName?: string) => {
|
||||
document.querySelector<HTMLDivElement>('#root')!.innerHTML = innerHTML;
|
||||
const head = document.querySelector<HTMLElement>('head')!;
|
||||
head.innerHTML += ssrStyle;
|
||||
|
||||
// Inject open trigger with block style
|
||||
if (triggerClassName) {
|
||||
document.querySelectorAll(`.${triggerClassName}`).forEach((node) => {
|
||||
document.querySelectorAll<HTMLElement>(`.${triggerClassName}`).forEach((node) => {
|
||||
const blockStart = document.createElement('div');
|
||||
const blockEnd = document.createElement('div');
|
||||
|
||||
node.parentNode!.insertBefore(blockStart, node);
|
||||
node.parentNode!.insertBefore(blockEnd, node.nextSibling);
|
||||
node.parentNode?.insertBefore(blockStart, node);
|
||||
node.parentNode?.insertBefore(blockEnd, node.nextSibling);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user