test: correct jest config coverage

This commit is contained in:
EnixCoda 2022-11-07 22:59:11 +08:00
parent 933839fb00
commit 3cedfa12cd
3 changed files with 26 additions and 13 deletions

View file

@ -3,10 +3,16 @@
"env": {
"es2022": true
},
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
}
"overrides": [
{
"files": ["*.tsx?"],
"excludedFiles": ["*.d.ts"],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
}
}
]
}

View file

@ -2,5 +2,11 @@
"env": {
"jest": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"]
"overrides": [
{
"files": ["*.ts"],
"excludedFiles": ["*.d.ts"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"]
}
]
}

View file

@ -19,7 +19,7 @@ export async function scroll({
}) {
let distance = 0
while ((distance += stepDistance) < totalDistance) {
await (page.mouse as any).wheel({ deltaY: stepDistance })
await page.mouse.wheel({ deltaY: stepDistance })
}
}
@ -28,19 +28,20 @@ export function assert(condition: boolean, err?: Error | string): asserts condit
}
let counter = 0
export async function listenTo<Args extends any[] = any[]>(
export async function listenTo(
event: string,
target: 'document' | 'window',
callback: (...args: Args) => void,
callback: <Args extends unknown[]>(...args: Args) => void,
oneTime?: boolean,
) {
const callbackName = 'onEvent' + ++counter
await page.exposeFunction(callbackName, callback)
await page.evaluate(
(event, target, callbackName, oneTime) => {
(event: string, target: 'window' | 'document', callbackName: string, oneTime?: boolean) => {
const t = target === 'document' ? document : window
const onEvent = (...args: any[]): void => {
;(window[callbackName as any] as any as (...args: any[]) => void)(...args)
const onEvent = (...args: unknown[]): void => {
const method = window[callbackName as keyof Window]
method?.(...args)
if (oneTime) t.removeEventListener(event, onEvent)
}
t.addEventListener(event, onEvent)