From 41ad5f771c144f0c075becb54bcadf7daa4f262b Mon Sep 17 00:00:00 2001 From: uid11 Date: Wed, 4 Dec 2024 10:38:30 +0300 Subject: [PATCH] FI-1569 feat: add `addLogsWithTags` field to pack config chore: update `prettier` to 3.4.2 --- README.md | 3 +++ autotests/packs/allTests.ts | 1 + package-lock.json | 8 ++++---- package.json | 2 +- src/types/config/ownE2edConfig.ts | 8 +++++++- src/types/index.ts | 1 + src/types/internal.ts | 1 + src/types/log.ts | 6 ++++++ src/utils/log/log.ts | 7 ++++++- src/utils/test/preparePage.ts | 8 +------- src/utils/waitForEvents/addNotCompleteRequest.ts | 11 +++++++++++ src/utils/waitForEvents/completeRequest.ts | 7 +++++++ 12 files changed, 49 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bd4d4dd7..b8efb9c3 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,9 @@ that exports the pack's config under the name `pack`. Here are the basic fields of the pack config. +`addLogsWithTags: readonly LogTag[]`: array of additional log tags. Logs with a specific tag +(in `logTag` field) will be added only if their tag is specified in this array. + `browserFlags: string[]`: array of browser flags, like `--disable-dev-shm-usage`, with which the browser is launched to run tests. diff --git a/autotests/packs/allTests.ts b/autotests/packs/allTests.ts index be8a3699..f5353dfc 100644 --- a/autotests/packs/allTests.ts +++ b/autotests/packs/allTests.ts @@ -42,6 +42,7 @@ const waitBeforeRetryTimeout = 1_000; * Pack of tests or tasks (pack configuration object). */ export const pack: Pack = { + addLogsWithTags: [], assertionTimeout: 5_000, browserFlags, browserName: 'chromium', diff --git a/package-lock.json b/package-lock.json index 722eab52..1807997c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "eslint-plugin-simple-import-sort": "12.1.1", "eslint-plugin-typescript-sort-keys": "3.3.0", "husky": "9.1.7", - "prettier": "3.4.1", + "prettier": "3.4.2", "typescript": "5.7.2" }, "engines": { @@ -2780,9 +2780,9 @@ } }, "node_modules/prettier": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.1.tgz", - "integrity": "sha512-G+YdqtITVZmOJje6QkXQWzl3fSfMxFwm1tjTyo9exhkmWSqC4Yhd1+lug++IlR2mvRVAxEDDWYkQdeSztajqgg==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "dev": true, "license": "MIT", "bin": { diff --git a/package.json b/package.json index ff125186..98cc5c55 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "eslint-plugin-simple-import-sort": "12.1.1", "eslint-plugin-typescript-sort-keys": "3.3.0", "husky": "9.1.7", - "prettier": "3.4.1", + "prettier": "3.4.2", "typescript": "5.7.2" }, "peerDependencies": { diff --git a/src/types/config/ownE2edConfig.ts b/src/types/config/ownE2edConfig.ts index 911791c1..eedc6726 100644 --- a/src/types/config/ownE2edConfig.ts +++ b/src/types/config/ownE2edConfig.ts @@ -3,7 +3,7 @@ import type {PlaywrightTestConfig} from '@playwright/test'; import type {TestRunStatus} from '../../constants/internal'; import type {FullMocksConfig} from '../fullMocks'; -import type {MapBackendResponseToLog, MapLogPayload, MapLogPayloadInReport} from '../log'; +import type {LogTag, MapBackendResponseToLog, MapLogPayload, MapLogPayloadInReport} from '../log'; import type {MaybePromise} from '../promise'; import type {LiteReport} from '../report'; import type {TestOptions, TestStaticOptions} from '../testRun'; @@ -26,6 +26,12 @@ export type OwnE2edConfig< SkipTests = SkipTestsPlaceholder, TestMeta = TestMetaPlaceholder, > = Readonly<{ + /** + * Array of additional log tags. Logs with a specific tag (in `logTag` field) + * will be added only if their tag is specified in this array. + */ + addLogsWithTags: readonly LogTag[]; + /** * Array of browser flags, like `--disable-dev-shm-usage`, with which the browser is launched to run tests. */ diff --git a/src/types/index.ts b/src/types/index.ts index cfb6d7c6..8582d665 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -37,6 +37,7 @@ export type { Url, } from './http'; export type {KeyboardPressKey} from './keyboard'; +export type {Log, LogContext, LogParams, LogPayload, LogTag} from './log'; export type {ApiMockFunction} from './mockApiRoute'; export type {WebSocketMockFunction} from './mockWebSocketRoute'; export type {NavigateToUrlOptions} from './navigation'; diff --git a/src/types/internal.ts b/src/types/internal.ts index 1d970803..9b3cf3d7 100644 --- a/src/types/internal.ts +++ b/src/types/internal.ts @@ -62,6 +62,7 @@ export type { LogContext, LogParams, LogPayload, + LogTag, MapBackendResponseToLog, MapLogPayload, MapLogPayloadInReport, diff --git a/src/types/log.ts b/src/types/log.ts index 90f14b0b..b40ab88e 100644 --- a/src/types/log.ts +++ b/src/types/log.ts @@ -30,10 +30,16 @@ export type LogPayload = Readonly<{ backendResponses?: readonly Payload[]; filePath?: unknown; logEventStatus?: LogEventStatus; + logTag?: LogTag; successful?: unknown; }> & Payload; +/** + * Type for `log` tags. + */ +export type LogTag = 'waitForAllRequestsComplete'; + /** * Maps responses from the backend to logs during the test. * Log the `responseBody` field carefully, as the body of backend response can be very large. diff --git a/src/utils/log/log.ts b/src/utils/log/log.ts index bdc955af..14ae261a 100644 --- a/src/utils/log/log.ts +++ b/src/utils/log/log.ts @@ -21,7 +21,12 @@ export const log: Log = (message, maybePayload?: unknown, maybeLogEventType?: un ? (maybePayload as LogEventType) : ((maybeLogEventType as LogEventType) ?? LogEventType.Unspecified); - const {mapLogPayloadInReport} = getFullPackConfig(); + const {addLogsWithTags, mapLogPayloadInReport} = getFullPackConfig(); + + if (payload && 'logTag' in payload && !addLogsWithTags.includes(payload.logTag)) { + return; + } + const payloadInReport = mapLogPayloadInReport(message, payload, type); registerLogEvent(runId, {message, payload: payloadInReport, time, type}); diff --git a/src/utils/test/preparePage.ts b/src/utils/test/preparePage.ts index d3e4dd13..d37f324e 100644 --- a/src/utils/test/preparePage.ts +++ b/src/utils/test/preparePage.ts @@ -1,7 +1,7 @@ import {AsyncLocalStorage} from 'node:async_hooks'; import {getConsoleMessagesFromContext} from '../../context/consoleMessages'; -import {getIsPageNavigatingNow, setIsPageNavigatingNow} from '../../context/isPageNavigatingNow'; +import {setIsPageNavigatingNow} from '../../context/isPageNavigatingNow'; import {getJsErrorsFromContext} from '../../context/jsError'; import {getNavigationDelay} from '../../context/navigationDelay'; import {getOnResponseCallbacks} from '../../context/onResponseCallbacks'; @@ -49,7 +49,6 @@ export const preparePage = async (page: Page): Promise<() => Promise> => { ); let navigationRequestsCount = 0; - const skippedRequestUrls = Object.create(null) as Record; const consoleListener = AsyncLocalStorage.bind(async (message: PlaywrightConsoleMessage) => { const args: unknown[] = []; @@ -73,11 +72,6 @@ export const preparePage = async (page: Page): Promise<() => Promise> => { const requestListener = AsyncLocalStorage.bind(async (newRequest: PlaywrightRequest) => { const isNavigationRequest = newRequest.isNavigationRequest(); - const isPageNavigatingNow = getIsPageNavigatingNow(); - - if (isPageNavigatingNow) { - skippedRequestUrls[newRequest.url()] = true; - } if (isNavigationRequest) { navigationRequestsCount += 1; diff --git a/src/utils/waitForEvents/addNotCompleteRequest.ts b/src/utils/waitForEvents/addNotCompleteRequest.ts index b12ad0bd..0ef7cef7 100644 --- a/src/utils/waitForEvents/addNotCompleteRequest.ts +++ b/src/utils/waitForEvents/addNotCompleteRequest.ts @@ -1,4 +1,5 @@ import {assertValueIsDefined} from '../asserts'; +import {log} from '../log'; import {isReRequest} from './isReRequest'; import {processAllRequestsCompletePredicates} from './processAllRequestsCompletePredicates'; @@ -22,6 +23,11 @@ export const addNotCompleteRequest = async ( hashOfNotCompleteRequests[requestHookContextId] = request; + log(`Add not complete request with url ${request.url}`, { + logTag: 'waitForAllRequestsComplete', + requestHookContextId, + }); + for (const previousRequestId of Object.keys( hashOfNotCompleteRequests, ) as RequestHookContextId[]) { @@ -37,6 +43,11 @@ export const addNotCompleteRequest = async ( }); if (isReRequest(request, previousRequest)) { + log(`Remove duplicate request with url ${previousRequest.url}`, { + logTag: 'waitForAllRequestsComplete', + previousRequestId, + }); + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete hashOfNotCompleteRequests[previousRequestId]; } diff --git a/src/utils/waitForEvents/completeRequest.ts b/src/utils/waitForEvents/completeRequest.ts index a6a0acbb..52e89007 100644 --- a/src/utils/waitForEvents/completeRequest.ts +++ b/src/utils/waitForEvents/completeRequest.ts @@ -1,3 +1,5 @@ +import {log} from '../log'; + import type {RequestHookContextId, WaitForEventsState} from '../../types/internal'; /** @@ -10,6 +12,11 @@ export const completeRequest = ( ): void => { const {allRequestsCompletePredicates, hashOfNotCompleteRequests} = waitForEventsState; + log(`Complete request with url ${hashOfNotCompleteRequests[requestHookContextId]?.url}`, { + logTag: 'waitForAllRequestsComplete', + requestHookContextId, + }); + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete hashOfNotCompleteRequests[requestHookContextId];