Skip to content

Commit

Permalink
type: replace any with HTTPRequest (#48737)
Browse files Browse the repository at this point in the history
* chore: code optimization

* fix: fix

* fix: fix

* fix: fix

---------

Co-authored-by: afc163 <afc163@gmail.com>
  • Loading branch information
li-jia-nan and afc163 committed May 2, 2024
1 parent aa0a90f commit 13c5801
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions tests/shared/imageTest.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
});
}
},
Expand Down

1 comment on commit 13c5801

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.