From 3cedfa12cdb9c333df49aed7ae638bded9b0f23b Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Mon, 7 Nov 2022 22:59:11 +0800 Subject: [PATCH] test: correct jest config coverage --- .eslintrc.json | 18 ++++++++++++------ __tests__/.eslintrc.json | 8 +++++++- __tests__/utils.ts | 13 +++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index cefbd69..b3b9333 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" + } + } + ] } diff --git a/__tests__/.eslintrc.json b/__tests__/.eslintrc.json index 12eafbb..6746bdb 100644 --- a/__tests__/.eslintrc.json +++ b/__tests__/.eslintrc.json @@ -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"] + } + ] } diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 49d46b6..0e8dc1e 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -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( +export async function listenTo( event: string, target: 'document' | 'window', - callback: (...args: Args) => void, + callback: (...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)