From 66acbf620031c881c7d6dd1a4e7ec461b1d6feff Mon Sep 17 00:00:00 2001 From: uid11 Date: Tue, 7 Nov 2023 21:47:25 +0300 Subject: [PATCH] refactor: rename `isTestIncludedInPack` to `filterTestsIntoPack` --- README.md | 4 ++-- autotests/packs/allTests.ts | 6 ++--- autotests/types/packSpecific.ts | 2 +- package-lock.json | 12 +++++----- src/constants/log.ts | 4 ++-- src/context/waitForEventsState.ts | 4 ++-- src/testcaferc.ts | 4 ++-- src/types/config/ownE2edConfig.ts | 4 ++-- src/types/userland/createPackSpecificTypes.ts | 2 +- src/types/waitForEvents.ts | 6 ++--- .../RequestHookToWaitForEvents.ts | 24 +++++++++++-------- .../requestHooks/RequestHookWithEvents.ts | 2 +- src/utils/test/getIsTestIncludedInPack.ts | 6 ++--- .../waitForEvents/addNotCompleteRequest.ts | 6 ++--- src/utils/waitForEvents/completeRequest.ts | 6 +---- .../waitForEvents/processEventsPredicate.ts | 2 +- .../waitForEvents/processEventsPredicates.ts | 2 +- 17 files changed, 47 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 6e330d33..ce904781 100644 --- a/README.md +++ b/README.md @@ -265,9 +265,9 @@ Each function can thus access the results of the previous function. `dockerImage: string`: the name of the docker image where the tests will run. The image must be based on the e2ed base image. -`isTestIncludedInPack: (testStaticOptions: TestStaticOptions) => boolean`: this function +`filterTestsIntoPack: (testStaticOptions: TestStaticOptions) => boolean`: this function filters tests (tasks) by their static options — -only those tests for which the function returned true get into the pack. +only those tests for which the function returned `true` get into the pack. `liteReportFileName: string | null`: the name of the file under which, after running the tests, the lite JSON report will be saved in the `autotests/reports` directory, for example, `lite-report.json`. diff --git a/autotests/packs/allTests.ts b/autotests/packs/allTests.ts index ccbc33d5..9ddc3dc1 100644 --- a/autotests/packs/allTests.ts +++ b/autotests/packs/allTests.ts @@ -9,14 +9,14 @@ import {RunEnvironment, runEnvironment} from 'e2ed/configurator'; import {doAfterPack, doBeforePack, mapLogPayloadInConsole, skipTests} from '../configurator'; -import type {IsTestIncludedInPack, Pack} from 'autotests/types/packSpecific'; +import type {FilterTestsIntoPack, Pack} from 'autotests/types/packSpecific'; const isLocalRun = runEnvironment === RunEnvironment.Local; const browser = isLocalRun ? 'chrome:headless' : 'chromium:headless'; const browserFlags = ['--disable-dev-shm-usage', '--disable-web-security']; -const isTestIncludedInPack: IsTestIncludedInPack = ({options}) => options.meta.testId !== '13'; +const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.testId !== '13'; /** * Pack of tests or tasks (pack configuration object). @@ -32,7 +32,7 @@ export const pack: Pack = { doAfterPack, doBeforePack, dockerImage: 'e2edhub/e2ed', - isTestIncludedInPack, + filterTestsIntoPack, liteReportFileName: 'lite-report.json', logFileName: 'pack-logs.log', mapLogPayloadInConsole, diff --git a/autotests/types/packSpecific.ts b/autotests/types/packSpecific.ts index 7ceed624..3ae25f29 100644 --- a/autotests/types/packSpecific.ts +++ b/autotests/types/packSpecific.ts @@ -12,7 +12,7 @@ export type GetFullPackConfig = PackSpecificTypes['GetFullPackConfig']; export type GetLogContext = PackSpecificTypes['GetLogContext']; export type GetMainTestRunParams = PackSpecificTypes['GetMainTestRunParams']; export type GetTestRunHash = PackSpecificTypes['GetTestRunHash']; -export type IsTestIncludedInPack = PackSpecificTypes['IsTestIncludedInPack']; +export type FilterTestsIntoPack = PackSpecificTypes['FilterTestsIntoPack']; export type IsTestSkipped = PackSpecificTypes['IsTestSkipped']; export type LiteReport = PackSpecificTypes['LiteReport']; export type MapLogPayloadInConsole = PackSpecificTypes['MapLogPayloadInConsole']; diff --git a/package-lock.json b/package-lock.json index 2d1daee5..103ee96f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7297,9 +7297,9 @@ } }, "node_modules/universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", "engines": { "node": ">= 10.0.0" } @@ -12855,9 +12855,9 @@ "integrity": "sha512-6t3foTQI9qne+OZoVQB/8x8rk2k1eVy1gRXhV3oFQ5T6R1dqQ1xtin3XqSlx3+ATBkliTaR/hHyJBm+LVPNM8w==" }, "universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==" }, "unquote": { "version": "1.1.1", diff --git a/src/constants/log.ts b/src/constants/log.ts index 274c4127..fe1791f1 100644 --- a/src/constants/log.ts +++ b/src/constants/log.ts @@ -2,7 +2,7 @@ import {ConsoleBackgroundColor} from './color'; import {TestRunStatus} from './testRun'; /** - * Status of LogEvent. + * Status of `LogEvent`. */ export const enum LogEventStatus { Passed = 'passed', @@ -10,7 +10,7 @@ export const enum LogEventStatus { } /** - * Type of LogEvent. + * Type of `LogEvent`. */ export const enum LogEventType { Action, diff --git a/src/context/waitForEventsState.ts b/src/context/waitForEventsState.ts index f539d77d..8de3d4a6 100644 --- a/src/context/waitForEventsState.ts +++ b/src/context/waitForEventsState.ts @@ -10,13 +10,13 @@ import type { import type {RequestHookToWaitForEvents} from '../utils/requestHooks'; /** - * Raw get and set internal (maybe undefined) "wait for events" state. + * Raw get and set internal (maybe `undefined`) "wait for events" state. * @internal */ const [getRawWaitForEventsState, setRawWaitForEventsState] = useContext(); /** - * Get internal always defined "wait for events" state (for waitForRequest/waitForResponse). + * Get internal always defined "wait for events" state (for `waitForRequest`/`waitForResponse`). * @internal */ export const getWaitForEventsState = ( diff --git a/src/testcaferc.ts b/src/testcaferc.ts index 54274dc0..0efa9691 100644 --- a/src/testcaferc.ts +++ b/src/testcaferc.ts @@ -62,7 +62,7 @@ const fullPackConfig: FullPackConfig = { const { doAfterPack, doBeforePack, - isTestIncludedInPack, + filterTestsIntoPack, mapLogPayloadInConsole, mapLogPayloadInLogFile, mapLogPayloadInReport, @@ -76,7 +76,7 @@ for (const fn of doBeforePack) { setCustomInspectOnFunction(fn); } -setCustomInspectOnFunction(isTestIncludedInPack); +setCustomInspectOnFunction(filterTestsIntoPack); setCustomInspectOnFunction(mapLogPayloadInConsole); setCustomInspectOnFunction(mapLogPayloadInLogFile); setCustomInspectOnFunction(mapLogPayloadInReport); diff --git a/src/types/config/ownE2edConfig.ts b/src/types/config/ownE2edConfig.ts index 09525b2d..95146753 100644 --- a/src/types/config/ownE2edConfig.ts +++ b/src/types/config/ownE2edConfig.ts @@ -43,9 +43,9 @@ export type OwnE2edConfig< /** * This function filters tests (tasks) by their static options — - * only those tests for which the function returned true get into the pack. + * only those tests for which the function returned `true` get into the pack. */ - isTestIncludedInPack: (this: void, testStaticOptions: TestStaticOptions) => boolean; + filterTestsIntoPack: (this: void, testStaticOptions: TestStaticOptions) => boolean; /** * The name of the file under which, after running the tests, diff --git a/src/types/userland/createPackSpecificTypes.ts b/src/types/userland/createPackSpecificTypes.ts index 9dbb977f..fd66ac2c 100644 --- a/src/types/userland/createPackSpecificTypes.ts +++ b/src/types/userland/createPackSpecificTypes.ts @@ -15,11 +15,11 @@ export type CreatePackSpecificTypes< > = Readonly<{ DoAfterPack: FullPackConfigByPack['doAfterPack'][number]; DoBeforePack: FullPackConfigByPack['doBeforePack'][number]; + FilterTestsIntoPack: Pack['filterTestsIntoPack']; GetFullPackConfig: () => FullPackConfigByPack; GetLogContext: Hooks['getLogContext']; GetMainTestRunParams: Hooks['getMainTestRunParams']; GetTestRunHash: Hooks['getTestRunHash']; - IsTestIncludedInPack: Pack['isTestIncludedInPack']; IsTestSkipped: Hooks['isTestSkipped']; LiteReport: LiteReport< PackParameters['CustomPackProperties'], diff --git a/src/types/waitForEvents.ts b/src/types/waitForEvents.ts index 67f9a1a6..4339be41 100644 --- a/src/types/waitForEvents.ts +++ b/src/types/waitForEvents.ts @@ -32,14 +32,14 @@ export type AllRequestsCompletePredicateWithPromise = Readonly<{ }>; /** - * Request predicate for waitForRequest function. + * Request predicate for `waitForRequest` function. */ export type RequestPredicate = ( request: SomeRequest, ) => Promise | boolean; /** - * Response predicate for waitForResponse function. + * Response predicate for `waitForResponse` function. */ export type ResponsePredicate = ( request: SomeResponse, @@ -79,7 +79,7 @@ export type ResponsePredicateWithPromise = Readonly<{ }>; /** - * State of requests/responses predicates for waitForRequest/waitForResponse. + * State of requests/responses predicates for `waitForRequest`/`waitForResponse`. * @internal */ export type WaitForEventsState = Readonly<{ diff --git a/src/utils/requestHooks/RequestHookToWaitForEvents.ts b/src/utils/requestHooks/RequestHookToWaitForEvents.ts index 02f38e54..7278438f 100644 --- a/src/utils/requestHooks/RequestHookToWaitForEvents.ts +++ b/src/utils/requestHooks/RequestHookToWaitForEvents.ts @@ -21,7 +21,8 @@ import type { } from '../../types/internal'; /** - * RequestHook to wait for request/response events (waitForRequest/waitForResponse). + * `RequestHook` to wait for request/response events (`waitForAllRequestsComplete`, + * `waitForRequest`/`waitForResponse`). * @internal */ export class RequestHookToWaitForEvents extends RequestHookWithEvents { @@ -35,12 +36,11 @@ export class RequestHookToWaitForEvents extends RequestHookWithEvents { override async onRequest(event: RequestHookRequestEvent): Promise { const request = getRequestFromRequestOptions(event.requestOptions); const requestHookContext = event.requestOptions[REQUEST_HOOK_CONTEXT_KEY]; + const requestHookContextId = requestHookContext[REQUEST_HOOK_CONTEXT_ID_KEY]; + + assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined', {request}); - await addNotCompleteRequest( - request, - requestHookContext[REQUEST_HOOK_CONTEXT_ID_KEY], - this.waitForEventsState, - ); + await addNotCompleteRequest(request, requestHookContextId, this.waitForEventsState); if (this.waitForEventsState.requestPredicates.size > 0) { await processEventsPredicates({ @@ -56,12 +56,16 @@ export class RequestHookToWaitForEvents extends RequestHookWithEvents { */ override async onResponse(event: RequestHookResponseEvent): Promise { const {headers} = event; + const requestHookContextId = (headers as Record)[ + REQUEST_HOOK_CONTEXT_ID_KEY + ]; + + assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined', { + requestHookResponseEvent: event, + }); if (headers) { - completeRequest( - (headers as Record)[REQUEST_HOOK_CONTEXT_ID_KEY], - this.waitForEventsState, - ); + completeRequest(requestHookContextId, this.waitForEventsState); } if (this.waitForEventsState.responsePredicates.size > 0) { diff --git a/src/utils/requestHooks/RequestHookWithEvents.ts b/src/utils/requestHooks/RequestHookWithEvents.ts index fccbaf4f..a0191c63 100644 --- a/src/utils/requestHooks/RequestHookWithEvents.ts +++ b/src/utils/requestHooks/RequestHookWithEvents.ts @@ -32,7 +32,7 @@ const getTestRunCallbackOptions = ({targetFunction, throwExceptionAtCallPoint: false}) as const; /** - * Abstract RequestHook class with request/respons events. + * Abstract `RequestHook` class with request/response events. */ abstract class RequestHookWithEvents extends RequestHook { constructor(...args: unknown[]) { diff --git a/src/utils/test/getIsTestIncludedInPack.ts b/src/utils/test/getIsTestIncludedInPack.ts index e585406b..a01aa945 100644 --- a/src/utils/test/getIsTestIncludedInPack.ts +++ b/src/utils/test/getIsTestIncludedInPack.ts @@ -3,11 +3,11 @@ import {getFullPackConfig} from '../getFullPackConfig'; import type {TestStaticOptions} from '../../types/internal'; /** - * Get flag isTestIncludedInPack for filtering tests by the complete test options. + * Get flag "is test included in pack" for filtering tests by the complete test options. * @internal */ export const getIsTestIncludedInPack = (testStaticOptions: TestStaticOptions): boolean => { - const {isTestIncludedInPack} = getFullPackConfig(); + const {filterTestsIntoPack} = getFullPackConfig(); - return isTestIncludedInPack(testStaticOptions); + return filterTestsIntoPack(testStaticOptions); }; diff --git a/src/utils/waitForEvents/addNotCompleteRequest.ts b/src/utils/waitForEvents/addNotCompleteRequest.ts index 26dc2b75..3e66071a 100644 --- a/src/utils/waitForEvents/addNotCompleteRequest.ts +++ b/src/utils/waitForEvents/addNotCompleteRequest.ts @@ -1,4 +1,4 @@ -import {assertValueIsDefined, assertValueIsUndefined} from '../asserts'; +import {assertValueIsUndefined} from '../asserts'; import {processAllRequestsCompletePredicates} from './processAllRequestsCompletePredicates'; @@ -10,11 +10,9 @@ import type {Request, RequestHookContextId, WaitForEventsState} from '../../type */ export const addNotCompleteRequest = async ( request: Request, - requestHookContextId: RequestHookContextId | undefined, + requestHookContextId: RequestHookContextId, waitForEventsState: WaitForEventsState, ): Promise => { - assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined', {request}); - const {hashOfNotCompleteRequests} = waitForEventsState; assertValueIsUndefined( diff --git a/src/utils/waitForEvents/completeRequest.ts b/src/utils/waitForEvents/completeRequest.ts index 3bf449bc..33135281 100644 --- a/src/utils/waitForEvents/completeRequest.ts +++ b/src/utils/waitForEvents/completeRequest.ts @@ -1,5 +1,3 @@ -import {assertValueIsDefined} from '../asserts'; - import type {RequestHookContextId, WaitForEventsState} from '../../types/internal'; /** @@ -7,11 +5,9 @@ import type {RequestHookContextId, WaitForEventsState} from '../../types/interna * @internal */ export const completeRequest = ( - requestHookContextId: RequestHookContextId | undefined, + requestHookContextId: RequestHookContextId, waitForEventsState: WaitForEventsState, ): void => { - assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined'); - const {allRequestsCompletePredicates, hashOfNotCompleteRequests} = waitForEventsState; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete diff --git a/src/utils/waitForEvents/processEventsPredicate.ts b/src/utils/waitForEvents/processEventsPredicate.ts index c183fbf3..bdd3ddf7 100644 --- a/src/utils/waitForEvents/processEventsPredicate.ts +++ b/src/utils/waitForEvents/processEventsPredicate.ts @@ -13,7 +13,7 @@ type Options = Readonly<{ }>; /** - * Resolve/reject waitForRequest/waitForResponse promise if request/response matches one predicate. + * Resolve/reject `waitForRequest`/`waitForResponse` promise if request/response matches one predicate. * Returns `true` if the promise was fulfilled, and `false` otherwise. * @internal */ diff --git a/src/utils/waitForEvents/processEventsPredicates.ts b/src/utils/waitForEvents/processEventsPredicates.ts index 0e5d22d3..e0157ff8 100644 --- a/src/utils/waitForEvents/processEventsPredicates.ts +++ b/src/utils/waitForEvents/processEventsPredicates.ts @@ -23,7 +23,7 @@ type ProcessEventsPredicates = ((options: OptionsForRequest) => Promise) & ((options: OptionsForResponse) => Promise); /** - * Processes waitForRequest/waitForResponse predicates for new concrete request/response. + * Processes `waitForRequest`/`waitForResponse` predicates for new concrete request/response. * @internal */ export const processEventsPredicates: ProcessEventsPredicates = async ({