From 80e16fea3bcaa83dd32a5bcb946d3f0cddf21711 Mon Sep 17 00:00:00 2001 From: uid11 Date: Fri, 16 Feb 2024 18:16:57 +0300 Subject: [PATCH 1/2] FI-1160 fix: prevent double exit from tests subprocess fix: totale number of successful tests in previous retries refactor: add more `@typescript-eslint/*` rules --- .eslintrc.yaml | 11 ++++ src/actions/takeScreenshot.ts | 7 ++- src/context/waitForEventsState.ts | 2 +- src/types/cdp/cdpClient.ts | 55 ++++++++++--------- src/types/extends.ts | 2 +- src/types/global.d.ts | 14 ++--- src/types/properties.ts | 3 +- src/types/selectors.ts | 52 +++++++++--------- src/types/stackTrace.ts | 28 +++++----- src/types/string.ts | 4 +- src/types/userland/userlandHooks.ts | 13 +++-- .../clone/cloneWithoutUndefinedProperties.ts | 2 +- src/utils/deepMerge.ts | 2 +- src/utils/fn/setCustomInspectOnFunction.ts | 2 +- src/utils/generalLog/index.ts | 5 +- .../generalLog/successfulTestRunCount.ts | 6 -- src/utils/report/client/clickOnRetry.ts | 5 +- src/utils/report/client/clickOnStep.ts | 5 +- src/utils/report/client/clickOnTestRun.ts | 5 +- src/utils/report/client/render/renderStep.ts | 1 - src/utils/request/oneTryOfRequest.ts | 2 +- src/utils/request/request.ts | 2 +- src/utils/retry/logRetryResult.ts | 10 +--- .../retry/updateRetriesStateAfterRetry.ts | 2 + src/utils/test/processBrokenTestRuns.ts | 4 +- src/utils/tests/exitFromTestsSubprocess.ts | 6 +- .../getShallowCopyOfObjectForLogs.ts | 2 +- src/utils/valueToString/wrapStringForLogs.ts | 2 +- 28 files changed, 134 insertions(+), 120 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index d5538aa2..d4665257 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -21,6 +21,7 @@ rules: complexity: [error, {max: 10}] curly: [error, all] default-param-last: off + dot-notation: off import/exports-last: error import/extensions: [error, never] import/named: error @@ -151,16 +152,25 @@ rules: - ['^\..*\u0000$'] sort-keys: [error, asc, {caseSensitive: true, natural: false}] typescript-sort-keys/string-enum: error + '@typescript-eslint/adjacent-overload-signatures': error + '@typescript-eslint/array-type': error '@typescript-eslint/ban-types': [error, {extendDefaults: true, types: {'{}': false}}] + '@typescript-eslint/class-literal-property-style': error + '@typescript-eslint/consistent-generic-constructors': error + '@typescript-eslint/consistent-indexed-object-style': error + '@typescript-eslint/consistent-type-assertions': + [error, {assertionStyle: as, objectLiteralTypeAssertions: never}] '@typescript-eslint/consistent-type-definitions': [error, type] '@typescript-eslint/consistent-type-exports': error '@typescript-eslint/consistent-type-imports': [error, {disallowTypeAnnotations: false}] '@typescript-eslint/default-param-last': error + '@typescript-eslint/dot-notation': error '@typescript-eslint/explicit-function-return-type': [error, {allowExpressions: true}] '@typescript-eslint/explicit-member-accessibility': [error, {accessibility: no-public}] '@typescript-eslint/explicit-module-boundary-types': error '@typescript-eslint/max-params': [error, {max: 3}] '@typescript-eslint/member-ordering': [error, {default: {order: alphabetically}}] + '@typescript-eslint/method-signature-style': error '@typescript-eslint/naming-convention': - error - {selector: default, format: [strictCamelCase, StrictPascalCase], leadingUnderscore: allow} @@ -173,6 +183,7 @@ rules: - {selector: [objectLiteralProperty, typeProperty], format: null, modifiers: [requiresQuotes]} - {selector: [classProperty, typeMethod], filter: '^toJSON$', format: null} '@typescript-eslint/no-import-type-side-effects': error + '@typescript-eslint/no-inferrable-types': error '@typescript-eslint/no-invalid-void-type': [error, {allowInGenericTypeArguments: true, allowAsThisParameter: true}] '@typescript-eslint/no-namespace': [error, {allowDeclarations: true}] diff --git a/src/actions/takeScreenshot.ts b/src/actions/takeScreenshot.ts index 8b02da7a..bdcfc115 100644 --- a/src/actions/takeScreenshot.ts +++ b/src/actions/takeScreenshot.ts @@ -18,7 +18,7 @@ type TakeScreenshot = ((path?: string) => Promise) & export const takeScreenshot: TakeScreenshot = (pathOrOptions) => { const options = typeof pathOrOptions === 'string' ? {path: pathOrOptions} : pathOrOptions; const { - fullPage, + fullPage = false, path: pathToScreenshot, timeout = DEFAULT_TAKE_SCREENSHOT_TIMEOUT_IN_MS, } = options ?? {}; @@ -31,7 +31,10 @@ export const takeScreenshot: TakeScreenshot = (pathOrOptions) => { LogEventType.InternalAction, ); - const takeScreenshotOptions = {fullPage, path: pathToScreenshot} as Inner.TakeScreenshotOptions; + const takeScreenshotOptions: Inner.TakeScreenshotOptions = { + fullPage, + path: pathToScreenshot as string, + }; const takeScreenshotPromise = testController.takeScreenshot(takeScreenshotOptions); if (!(timeout > 0)) { diff --git a/src/context/waitForEventsState.ts b/src/context/waitForEventsState.ts index c68c2d64..3337c6c6 100644 --- a/src/context/waitForEventsState.ts +++ b/src/context/waitForEventsState.ts @@ -34,7 +34,7 @@ export const getWaitForEventsState = ( hashOfNotCompleteRequests: Object.create( null, ) as WaitForEventsState['hashOfNotCompleteRequests'], - hook: {} as RequestHookToWaitForEvents, + hook: {} as unknown as RequestHookToWaitForEvents, redirects: Object.create(null) as Record, requestPredicates: new Set(), responsePredicates: new Set(), diff --git a/src/types/cdp/cdpClient.ts b/src/types/cdp/cdpClient.ts index 9550e40b..c634779c 100644 --- a/src/types/cdp/cdpClient.ts +++ b/src/types/cdp/cdpClient.ts @@ -101,42 +101,43 @@ export type CdpClient = Readonly<{ close: () => Promise; host: string; local: boolean; + on: ((event: 'event', callback: (message: EventMessage) => void) => void) & + ((event: 'disconnect' | 'ready', callback: () => void) => void) & + (( + event: T, + callback: (params: ProtocolMappingApi.Events[T][0], sessionId?: string) => void, + ) => void) & + ((event: string, callback: (params: object, sessionId?: string) => void) => void); port: number; protocol: Readonly<{ domains: readonly Domain[]; version: Readonly<{major: string; minor: string}>; }>; secure: boolean; - target: Target | string | ((targets: readonly Target[]) => Target | number) | undefined; - useHostName: boolean; - webSocketUrl: string; - on(event: 'event', callback: (message: EventMessage) => void): void; - on(event: 'disconnect' | 'ready', callback: () => void): void; - // '.' i.e. Network.requestWillBeSent - on( - event: T, - callback: (params: ProtocolMappingApi.Events[T][0], sessionId?: string) => void, - ): void; - // '..' i.e. Network.requestWillBeSent.abc123 - on(event: string, callback: (params: object, sessionId?: string) => void): void; // client.send(method, [params], [sessionId], [callback]) - send(event: T, callback: SendCallback): void; - send( - event: T, - params: ProtocolMappingApi.Commands[T]['paramsType'][0], - callback: SendCallback, - ): void; - send( + send: (( event: T, - params: ProtocolMappingApi.Commands[T]['paramsType'][0], - sessionId: string, callback: SendCallback, - ): void; - send( - event: T, - params?: ProtocolMappingApi.Commands[T]['paramsType'][0], - sessionId?: string, - ): Promise; + ) => void) & + (( + event: T, + params: ProtocolMappingApi.Commands[T]['paramsType'][0], + callback: SendCallback, + ) => void) & + (( + event: T, + params: ProtocolMappingApi.Commands[T]['paramsType'][0], + sessionId: string, + callback: SendCallback, + ) => void) & + (( + event: T, + params?: ProtocolMappingApi.Commands[T]['paramsType'][0], + sessionId?: string, + ) => Promise); + target: Target | string | ((targets: readonly Target[]) => Target | number) | undefined; + useHostName: boolean; + webSocketUrl: string; }> & EventPromises & EventCallbacks & diff --git a/src/types/extends.ts b/src/types/extends.ts index 4c76f8de..f891ae9a 100644 --- a/src/types/extends.ts +++ b/src/types/extends.ts @@ -12,9 +12,9 @@ declare module 'testcafe-without-typecheck' { interface TestController { readonly testRun: DeepReadonly<{ browserConnection: TestCafeBrowserConnection; + emit: (this: void, eventName: string) => Promise; errs: readonly OriginalTestRunError[]; test: {testFile: {filename: string}}; - emit(this: void, eventName: string): Promise; }>; } } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index e471e509..88bfd4bd 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -115,22 +115,22 @@ declare module 'testcafe-without-typecheck/lib/native-automation/request-hooks/e declare module 'testcafe-without-typecheck/lib/api/test-run-tracker' { type InternalTestRun = { controller: Readonly>; + executeAction: (apiMethodName: string, command: unknown, callsite: unknown) => Promise; + executeCommand: (command: unknown) => Promise; id: string; - executeAction(apiMethodName: string, command: unknown, callsite: unknown): Promise; - executeCommand(command: unknown): Promise; }; type Fn = (...args: never[]) => unknown; const testRunTracker: Readonly<{ - activeTestRuns: Record; /** * Wraps function in context tracker for asynchronous calls. */ - _createContextSwitchingFunctionHook(ctxSwitchingFn: Fn, patchedArgsCount: number): Fn; - addTrackingMarkerToFunction(testRunId: string, fn: Fn): Fn; - ensureEnabled(): void; - resolveContextTestRun(): InternalTestRun; + _createContextSwitchingFunctionHook: (ctxSwitchingFn: Fn, patchedArgsCount: number) => Fn; + activeTestRuns: Record; + addTrackingMarkerToFunction: (testRunId: string, fn: Fn) => Fn; + ensureEnabled: () => void; + resolveContextTestRun: () => InternalTestRun; }>; /** diff --git a/src/types/properties.ts b/src/types/properties.ts index feae6a9d..06f8629d 100644 --- a/src/types/properties.ts +++ b/src/types/properties.ts @@ -9,7 +9,8 @@ type DataPropertyDescriptor = Readonly< GenericPropertyDescriptor; type AccessorPropertyDescriptor = Readonly< - {get?(): Value; set(value: Value): void} | {get(): Value; set?(value: Value): void} + | {get: () => Value; set?: (value: Value) => void} + | {get?: () => Value; set: (value: Value) => void} > & GenericPropertyDescriptor; diff --git a/src/types/selectors.ts b/src/types/selectors.ts index 5e21b388..2f7c2ac8 100644 --- a/src/types/selectors.ts +++ b/src/types/selectors.ts @@ -86,89 +86,89 @@ export type Selector = ReplaceObjectSelectors & */ export type SelectorCustomMethods = Readonly<{ /** Finds all child elements (not nodes) of all nodes in the matching set and filters them by locatorId. */ - childByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + childByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all child elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */ - childByLocatorParameter( + childByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Creates a selector that filters a matching set by locatorId. */ - filterByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + filterByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Creates a selector that filters a matching set by locator parameter. */ - filterByLocatorParameter( + filterByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Finds all descendants of all nodes in the matching set and filters them by locatorId. */ - findByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + findByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all descendants of all nodes in the matching set and filters them by locator parameter. */ - findByLocatorParameter( + findByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Get string description of selector if any. */ - getDescription(this: TestCafeSelector): string | undefined; + getDescription: (this: TestCafeSelector) => string | undefined; /** Returns the value of the locator id. */ - getLocatorId(this: TestCafeSelector): Promise; + getLocatorId: (this: TestCafeSelector) => Promise; /** Returns the value of the locator parameter. */ - getLocatorParameter(this: TestCafeSelector, parameter: string): Promise; + getLocatorParameter: (this: TestCafeSelector, parameter: string) => Promise; /** true if the element has the locator id. */ - hasLocatorId(this: TestCafeSelector): Promise; + hasLocatorId: (this: TestCafeSelector) => Promise; /** true if the element has the locator parameter. */ - hasLocatorParameter(this: TestCafeSelector, parameter: string): Promise; + hasLocatorParameter: (this: TestCafeSelector, parameter: string) => Promise; /** Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */ - nextSiblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + nextSiblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */ - nextSiblingByLocatorParameter( + nextSiblingByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Finds all parents of all nodes in the matching set and filters them by locatorId. */ - parentByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + parentByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all parents of all nodes in the matching set and filters them by locator parameter. */ - parentByLocatorParameter( + parentByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */ - prevSiblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + prevSiblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */ - prevSiblingByLocatorParameter( + prevSiblingByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; /** Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by locatorId. */ - siblingByLocatorId(this: TestCafeSelector, locatorId: string): TestCafeSelector; + siblingByLocatorId: (this: TestCafeSelector, locatorId: string) => TestCafeSelector; /** Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by locator parameter. */ - siblingByLocatorParameter( + siblingByLocatorParameter: ( this: TestCafeSelector, parameter: string, value: string, - ): TestCafeSelector; + ) => TestCafeSelector; }>; /** diff --git a/src/types/stackTrace.ts b/src/types/stackTrace.ts index 4a4a4c6e..c6e9a95f 100644 --- a/src/types/stackTrace.ts +++ b/src/types/stackTrace.ts @@ -4,19 +4,19 @@ import type {Fn} from './fn'; * Frame object from V8 execution stack. */ export type StackFrame = Readonly<{ - getColumnNumber(): number; - getEvalOrigin(): string; - getFileName(): string; - getFunction(): SomeFunction; - getFunctionName(): string | null; - getLineNumber(): number; - getMethodName(): string; + getColumnNumber: () => number; + getEvalOrigin: () => string; + getFileName: () => string; + getFunction: () => SomeFunction; + getFunctionName: () => string | null; + getLineNumber: () => number; + getMethodName: () => string; // eslint-disable-next-line @typescript-eslint/naming-convention - getScriptNameOrSourceURL(): string; - getThis(): This; - getTypeName(): string; - isConstructor(): boolean; - isEval(): boolean; - isNative(): boolean; - isToplevel(): boolean; + getScriptNameOrSourceURL: () => string; + getThis: () => This; + getTypeName: () => string; + isConstructor: () => boolean; + isEval: () => boolean; + isNative: () => boolean; + isToplevel: () => boolean; }>; diff --git a/src/types/string.ts b/src/types/string.ts index 803d239d..107648a4 100644 --- a/src/types/string.ts +++ b/src/types/string.ts @@ -6,8 +6,8 @@ declare const custom: typeof inspect.custom; * `String` object for logs, with `toJSON` and `inspect.custom` methods. */ export type StringForLogs = Readonly<{ - [custom](this: StringForLogs): string; - toJSON(this: StringForLogs): string; + [custom]: (this: StringForLogs) => string; + toJSON: (this: StringForLogs) => string; }> & // eslint-disable-next-line @typescript-eslint/ban-types String; diff --git a/src/types/userland/userlandHooks.ts b/src/types/userland/userlandHooks.ts index b1c07a81..a6398d64 100644 --- a/src/types/userland/userlandHooks.ts +++ b/src/types/userland/userlandHooks.ts @@ -10,13 +10,16 @@ import type {TestMetaPlaceholder} from './placeholders'; * Hooks type that the e2ed/hooks userland module must correspond to. */ export type UserlandHooks = { - getLogContext( + getLogContext: ( this: void, message: string, payload: LogPayload | undefined, type: LogEventType, - ): LogContext | undefined; - getMainTestRunParams(this: void, testRun: TestRun): string; - getTestRunHash(this: void, testRun: TestRun): RunHash; - isTestSkipped(this: void, testStaticOptions: TestStaticOptions): IsTestSkippedResult; + ) => LogContext | undefined; + getMainTestRunParams: (this: void, testRun: TestRun) => string; + getTestRunHash: (this: void, testRun: TestRun) => RunHash; + isTestSkipped: ( + this: void, + testStaticOptions: TestStaticOptions, + ) => IsTestSkippedResult; }; diff --git a/src/utils/clone/cloneWithoutUndefinedProperties.ts b/src/utils/clone/cloneWithoutUndefinedProperties.ts index d90792fa..e2bdf2c0 100644 --- a/src/utils/clone/cloneWithoutUndefinedProperties.ts +++ b/src/utils/clone/cloneWithoutUndefinedProperties.ts @@ -8,7 +8,7 @@ import type {CloneWithoutUndefinedProperties, ObjectEntries} from '../../types/i export const cloneWithoutUndefinedProperties = ( x: Type, ): CloneWithoutUndefinedProperties => { - const result = {} as CloneWithoutUndefinedProperties; + const result = {} as unknown as CloneWithoutUndefinedProperties; for (const [key, value] of Object.entries(x) as ObjectEntries) { const descriptor = Object.getOwnPropertyDescriptor(x, key); diff --git a/src/utils/deepMerge.ts b/src/utils/deepMerge.ts index 417177ae..34696c13 100644 --- a/src/utils/deepMerge.ts +++ b/src/utils/deepMerge.ts @@ -8,7 +8,7 @@ import type {DeepPartial, ObjectEntries, Values} from '../types/internal'; * `y` overwrites `x`; `x` and `y` are immutable. */ export const deepMerge = (x: Type, y: DeepPartial): Type => { - const result = {} as Type; + const result = {} as unknown as Type; for (const key of Object.keys(x)) { const descriptor = Object.getOwnPropertyDescriptor(x, key); diff --git a/src/utils/fn/setCustomInspectOnFunction.ts b/src/utils/fn/setCustomInspectOnFunction.ts index 7840c9f5..3c844eeb 100644 --- a/src/utils/fn/setCustomInspectOnFunction.ts +++ b/src/utils/fn/setCustomInspectOnFunction.ts @@ -29,5 +29,5 @@ export const setCustomInspectOnFunction = StringForLogs | string}).toJSON = getFunctionPresentationForThis; }; diff --git a/src/utils/generalLog/index.ts b/src/utils/generalLog/index.ts index 49a5807d..4d00cabd 100644 --- a/src/utils/generalLog/index.ts +++ b/src/utils/generalLog/index.ts @@ -14,7 +14,4 @@ export {removeStyleFromString} from './removeStyleFromString'; /** @internal */ export {truncateArrayForLogs} from './truncateArrayForLogs'; /** @internal */ -export { - getSuccessfulTotalInPreviousRetries, - setSuccessfulTotalInPreviousRetries, -} from './successfulTestRunCount'; +export {setSuccessfulTotalInPreviousRetries} from './successfulTestRunCount'; diff --git a/src/utils/generalLog/successfulTestRunCount.ts b/src/utils/generalLog/successfulTestRunCount.ts index efb312c9..67b99730 100644 --- a/src/utils/generalLog/successfulTestRunCount.ts +++ b/src/utils/generalLog/successfulTestRunCount.ts @@ -32,12 +32,6 @@ export const getSuccessfulTestRunCount = (): string => { return `${successfulInCurrentRetry} in the current retry, ${successfulTotal} in total`; }; -/** - * Get total number of tests successful in all previous retries. - * @internal - */ -export const getSuccessfulTotalInPreviousRetries = (): number => successfulTotalInPreviousRetries; - /** * Set successful test runs total in previous retries * @internal diff --git a/src/utils/report/client/clickOnRetry.ts b/src/utils/report/client/clickOnRetry.ts index 0d02b47a..db67b0e1 100644 --- a/src/utils/report/client/clickOnRetry.ts +++ b/src/utils/report/client/clickOnRetry.ts @@ -17,10 +17,11 @@ export function clickOnRetry(element: HTMLElement): void { ); if (previousChosenRetryButton) { - previousChosenRetryButton.setAttribute('aria-selected', 'false'); + previousChosenRetryButton.ariaSelected = 'false'; } - element.setAttribute('aria-selected', 'true'); + // eslint-disable-next-line no-param-reassign + element.ariaSelected = 'true'; const leftSection = document.querySelector('.main__section._position_left'); diff --git a/src/utils/report/client/clickOnStep.ts b/src/utils/report/client/clickOnStep.ts index fe5a15d8..34b0f25b 100644 --- a/src/utils/report/client/clickOnStep.ts +++ b/src/utils/report/client/clickOnStep.ts @@ -4,7 +4,8 @@ * @internal */ export function clickOnStep(element: HTMLElement): void { - const expanded = element.getAttribute('aria-expanded') === 'true'; + const expanded = element.ariaExpanded === 'true'; - element.setAttribute('aria-expanded', String(!expanded)); + // eslint-disable-next-line no-param-reassign + element.ariaExpanded = String(!expanded); } diff --git a/src/utils/report/client/clickOnTestRun.ts b/src/utils/report/client/clickOnTestRun.ts index 8cbe0d9b..2c1aaa30 100644 --- a/src/utils/report/client/clickOnTestRun.ts +++ b/src/utils/report/client/clickOnTestRun.ts @@ -15,10 +15,11 @@ export function clickOnTestRun(element: HTMLElement): void { const previousChosenTestRunButton = document.querySelector('.test-button[aria-selected="true"]'); if (previousChosenTestRunButton) { - previousChosenTestRunButton.setAttribute('aria-selected', 'false'); + previousChosenTestRunButton.ariaSelected = 'false'; } - element.setAttribute('aria-selected', 'true'); + // eslint-disable-next-line no-param-reassign + element.ariaSelected = 'true'; chooseTestRun(runHash); } diff --git a/src/utils/report/client/render/renderStep.ts b/src/utils/report/client/render/renderStep.ts index ece9ef37..a3083391 100644 --- a/src/utils/report/client/render/renderStep.ts +++ b/src/utils/report/client/render/renderStep.ts @@ -31,7 +31,6 @@ export function renderStep({logEvent, nextLogEventTime}: Options): SafeHtml { let pathToScreenshotFromReportPage: string | undefined; - // eslint-disable-next-line dot-notation if (type === LogEventType.InternalAction && typeof payload?.['pathToScreenshot'] === 'string') { const {pathToScreenshot} = payload; const {pathToScreenshotsDirectoryForReport} = reportClientState; diff --git a/src/utils/request/oneTryOfRequest.ts b/src/utils/request/oneTryOfRequest.ts index bfefb529..a9015d48 100644 --- a/src/utils/request/oneTryOfRequest.ts +++ b/src/utils/request/oneTryOfRequest.ts @@ -69,7 +69,7 @@ export const oneTryOfRequest = ({ responseBody, responseHeaders: res.headers, statusCode, - } as SomeResponse; + } as unknown as SomeResponse; clearTimeout(endTimeout); resolve({fullLogParams, response}); diff --git a/src/utils/request/request.ts b/src/utils/request/request.ts index a55a5f41..4ae7ea40 100644 --- a/src/utils/request/request.ts +++ b/src/utils/request/request.ts @@ -38,7 +38,7 @@ export const request = async < requestBody, routeParams, timeout = 30_000, - }: Options = {} as Options< + }: Options = {} as unknown as Options< RouteParams, SomeRequest, SomeResponse diff --git a/src/utils/retry/logRetryResult.ts b/src/utils/retry/logRetryResult.ts index e19c4914..56b4cb11 100644 --- a/src/utils/retry/logRetryResult.ts +++ b/src/utils/retry/logRetryResult.ts @@ -1,9 +1,4 @@ -import { - failMessage, - generalLog, - getSuccessfulTotalInPreviousRetries, - okMessage, -} from '../generalLog'; +import {failMessage, generalLog, okMessage} from '../generalLog'; import {getDurationWithUnits} from '../getDurationWithUnits'; import {getPrintedRetry} from './getPrintedRetry'; @@ -16,6 +11,7 @@ type Options = Readonly<{ newLength: number; retriesState: RetriesState; successfulLength: number; + successfulTotalInPreviousRetries: number; unbrokenLength: number; }>; @@ -28,13 +24,13 @@ export const logRetryResult = ({ newLength, retriesState, successfulLength, + successfulTotalInPreviousRetries, unbrokenLength, }: Options): void => { const {concurrency, maxRetriesCount, retryIndex, startLastRetryTimeInMs} = retriesState; const printedRetry = getPrintedRetry({maxRetriesCount, retryIndex}); const stateMessage = retriesState.isLastRetrySuccessful ? okMessage : failMessage; - const successfulTotalInPreviousRetries = getSuccessfulTotalInPreviousRetries(); const durationWithUnits = getDurationWithUnits(Date.now() - startLastRetryTimeInMs); diff --git a/src/utils/retry/updateRetriesStateAfterRetry.ts b/src/utils/retry/updateRetriesStateAfterRetry.ts index 9508f9bb..2382cca6 100644 --- a/src/utils/retry/updateRetriesStateAfterRetry.ts +++ b/src/utils/retry/updateRetriesStateAfterRetry.ts @@ -37,6 +37,7 @@ export const updateRetriesStateAfterRetry = async (retriesState: RetriesState): ); const printedRetry = getPrintedRetry({maxRetriesCount, retryIndex}); + const successfulTotalInPreviousRetries = Object.keys(successfulTestRunNamesHash).length; for (const successfulNewFullTestRun of successfulNewFullTestRuns) { const {name} = successfulNewFullTestRun; @@ -59,6 +60,7 @@ export const updateRetriesStateAfterRetry = async (retriesState: RetriesState): newLength: newFullTestRuns.length, retriesState, successfulLength: successfulNewFullTestRuns.length, + successfulTotalInPreviousRetries, unbrokenLength: unbrokenNewFullTestRuns.length, }); diff --git a/src/utils/test/processBrokenTestRuns.ts b/src/utils/test/processBrokenTestRuns.ts index bf59ee8c..28b9ed8a 100644 --- a/src/utils/test/processBrokenTestRuns.ts +++ b/src/utils/test/processBrokenTestRuns.ts @@ -22,11 +22,11 @@ export const processBrokenTestRuns = (testRunEvent: TestRunEvent): void => { assertTestRunEventIsPreviousOfTestRunEvent(previousTestRunEvent, testRunEvent); - const errorParamsForBrokenTest = { + const errorParamsForBrokenTest: MaybeWithIsTestRunBroken & Record = { isTestRunBroken: true, previousTestRunEvent: cloneWithoutLogEvents(previousTestRunEvent), testRunEvent: cloneWithoutLogEvents(testRunEvent), - } as MaybeWithIsTestRunBroken; + }; if (previousTestRunEvent.status !== TestRunStatus.Unknown) { if (previousTestRunEvent.status === TestRunStatus.Failed) { diff --git a/src/utils/tests/exitFromTestsSubprocess.ts b/src/utils/tests/exitFromTestsSubprocess.ts index 72d1050e..52329f20 100644 --- a/src/utils/tests/exitFromTestsSubprocess.ts +++ b/src/utils/tests/exitFromTestsSubprocess.ts @@ -12,6 +12,8 @@ import {getMaybeTestCafeInstance} from '../testCafe'; */ const closingTestcafeInstanceTimeoutInMs = 20_000; +let isExitAlreadyCalled = false; + type Options = Readonly<{hasError: boolean; reason: string}>; /** @@ -19,10 +21,12 @@ type Options = Readonly<{hasError: boolean; reason: string}>; * @internal */ export const exitFromTestsSubprocess = async ({hasError, reason}: Options): Promise => { - if (isLocalRun) { + if (isExitAlreadyCalled || isLocalRun) { return; } + isExitAlreadyCalled = true; + generalLog( `Exit from tests subprocess${hasError ? ' with error' : ''} for the reason: ${reason}`, ); diff --git a/src/utils/valueToString/getShallowCopyOfObjectForLogs.ts b/src/utils/valueToString/getShallowCopyOfObjectForLogs.ts index b3b29e1a..0b85201a 100644 --- a/src/utils/valueToString/getShallowCopyOfObjectForLogs.ts +++ b/src/utils/valueToString/getShallowCopyOfObjectForLogs.ts @@ -7,7 +7,7 @@ type Return = Readonly>; * Property values that are objects are cast to a string. */ export const getShallowCopyOfObjectForLogs = (value: object): Return => { - const copy = {} as Mutable; + const copy = {} as unknown as Mutable; for (const key of Reflect.ownKeys(value)) { const property = (value as Record)[key]; diff --git a/src/utils/valueToString/wrapStringForLogs.ts b/src/utils/valueToString/wrapStringForLogs.ts index c28c47d9..d7ea6b7a 100644 --- a/src/utils/valueToString/wrapStringForLogs.ts +++ b/src/utils/valueToString/wrapStringForLogs.ts @@ -36,7 +36,7 @@ export const wrapStringForLogs = (text: string, options?: Options): StringForLog const toString = options?.doNotWrapInBacktick ? String.prototype.toString : toMultipleString; result[inspect.custom as unknown as number] = toString as unknown as string; - (result as unknown as {toJSON(): string}).toJSON = toString; + (result as unknown as {toJSON: () => string}).toJSON = toString; return result; }; From 8fb02ffd7101c037ce55f02676f705c4c23332a4 Mon Sep 17 00:00:00 2001 From: uid11 Date: Fri, 16 Feb 2024 18:25:11 +0300 Subject: [PATCH 2/2] chore: update `devDependencies` (`@types/node`, etc) --- package-lock.json | 24 ++++++++++++------------ package.json | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5503ff2b..de43ec14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,19 +21,19 @@ "e2ed-init": "bin/init.js" }, "devDependencies": { - "@types/node": "20.11.17", + "@types/node": "20.11.19", "@typescript-eslint/eslint-plugin": "6.21.0", "@typescript-eslint/parser": "6.21.0", "assert-modules-support-case-insensitive-fs": "1.0.1", "assert-package-lock-is-consistent": "1.0.0", - "devtools-protocol": "0.0.1259648", + "devtools-protocol": "0.0.1261483", "eslint": "8.56.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-import": "2.29.1", "eslint-plugin-simple-import-sort": "12.0.0", "eslint-plugin-typescript-sort-keys": "3.1.0", - "husky": "9.0.10", + "husky": "9.0.11", "prettier": "3.2.5", "testcafe": "3.5.0", "typescript": "5.3.3" @@ -2202,9 +2202,9 @@ "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==" }, "node_modules/@types/node": { - "version": "20.11.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.17.tgz", - "integrity": "sha512-QmgQZGWu1Yw9TDyAP9ZzpFJKynYNeOvwMJmaxABfieQoVoiVOS6MN1WSpqpRcbeA5+RW82kraAVxCCJg+780Qw==", + "version": "20.11.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", + "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", "dependencies": { "undici-types": "~5.26.4" } @@ -3409,9 +3409,9 @@ "integrity": "sha512-fYXbFSeilT7bnKWFi4OERSPHdtaEoDGn4aUhV5Nly6/I+Tp6JZ/6Icmd7LVIF5euyodGpxz2e/bfUmDnIdSIDw==" }, "node_modules/devtools-protocol": { - "version": "0.0.1259648", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1259648.tgz", - "integrity": "sha512-1JbIS/6OOXPfOZLneuAQEeTmCKxFPToMGoyjfhVHLzmnmVhfGGJwuYg03lQuV6uDHnta/2hC8mxI73BRUorGgw==", + "version": "0.0.1261483", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1261483.tgz", + "integrity": "sha512-7vJvejpzA5DTfZVkr7a8sGpEAzEiAqcgmRTB0LSUrWeOicwL09lMQTzxHtFNVhJ1OOJkgYdH6Txvy9E5j3VOUQ==", "dev": true }, "node_modules/diff": { @@ -4812,9 +4812,9 @@ "integrity": "sha512-qLo/08cNc3Tb0uD7jK0jAcU5cnqCM0n568918E7R2XhMr/+7F37p4EY062W/stg7tmzvknNn9b/1+UhVRzsYrQ==" }, "node_modules/husky": { - "version": "9.0.10", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.10.tgz", - "integrity": "sha512-TQGNknoiy6bURzIO77pPRu+XHi6zI7T93rX+QnJsoYFf3xdjKOur+IlfqzJGMHIK/wXrLg+GsvMs8Op7vI2jVA==", + "version": "9.0.11", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", + "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", "dev": true, "bin": { "husky": "bin.mjs" diff --git a/package.json b/package.json index 26cb5b5b..5eb46894 100644 --- a/package.json +++ b/package.json @@ -32,19 +32,19 @@ "testcafe-without-typecheck": "3.5.0-rc.2" }, "devDependencies": { - "@types/node": "20.11.17", + "@types/node": "20.11.19", "@typescript-eslint/eslint-plugin": "6.21.0", "@typescript-eslint/parser": "6.21.0", "assert-modules-support-case-insensitive-fs": "1.0.1", "assert-package-lock-is-consistent": "1.0.0", - "devtools-protocol": "0.0.1259648", + "devtools-protocol": "0.0.1261483", "eslint": "8.56.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-import": "2.29.1", "eslint-plugin-simple-import-sort": "12.0.0", "eslint-plugin-typescript-sort-keys": "3.1.0", - "husky": "9.0.10", + "husky": "9.0.11", "prettier": "3.2.5", "testcafe": "3.5.0", "typescript": "5.3.3"