Skip to content

Commit

Permalink
refactor: rename isTestIncludedInPack to filterTestsIntoPack
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Nov 7, 2023
1 parent a1d8e97 commit 66acbf6
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestMeta>) => boolean`: this function
`filterTestsIntoPack: (testStaticOptions: TestStaticOptions<TestMeta>) => 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`.
Expand Down
6 changes: 3 additions & 3 deletions autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -32,7 +32,7 @@ export const pack: Pack = {
doAfterPack,
doBeforePack,
dockerImage: 'e2edhub/e2ed',
isTestIncludedInPack,
filterTestsIntoPack,
liteReportFileName: 'lite-report.json',
logFileName: 'pack-logs.log',
mapLogPayloadInConsole,
Expand Down
2 changes: 1 addition & 1 deletion autotests/types/packSpecific.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/constants/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import {ConsoleBackgroundColor} from './color';
import {TestRunStatus} from './testRun';

/**
* Status of LogEvent.
* Status of `LogEvent`.
*/
export const enum LogEventStatus {
Passed = 'passed',
Failed = 'failed',
}

/**
* Type of LogEvent.
* Type of `LogEvent`.
*/
export const enum LogEventType {
Action,
Expand Down
4 changes: 2 additions & 2 deletions src/context/waitForEventsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WaitForEventsState>();

/**
* 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 = (
Expand Down
4 changes: 2 additions & 2 deletions src/testcaferc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const fullPackConfig: FullPackConfig = {
const {
doAfterPack,
doBeforePack,
isTestIncludedInPack,
filterTestsIntoPack,
mapLogPayloadInConsole,
mapLogPayloadInLogFile,
mapLogPayloadInReport,
Expand All @@ -76,7 +76,7 @@ for (const fn of doBeforePack) {
setCustomInspectOnFunction(fn);
}

setCustomInspectOnFunction(isTestIncludedInPack);
setCustomInspectOnFunction(filterTestsIntoPack);
setCustomInspectOnFunction(mapLogPayloadInConsole);
setCustomInspectOnFunction(mapLogPayloadInLogFile);
setCustomInspectOnFunction(mapLogPayloadInReport);
Expand Down
4 changes: 2 additions & 2 deletions src/types/config/ownE2edConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestMeta>) => boolean;
filterTestsIntoPack: (this: void, testStaticOptions: TestStaticOptions<TestMeta>) => boolean;

/**
* The name of the file under which, after running the tests,
Expand Down
2 changes: 1 addition & 1 deletion src/types/userland/createPackSpecificTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export type CreatePackSpecificTypes<
> = Readonly<{
DoAfterPack: FullPackConfigByPack<Pack>['doAfterPack'][number];
DoBeforePack: FullPackConfigByPack<Pack>['doBeforePack'][number];
FilterTestsIntoPack: Pack['filterTestsIntoPack'];
GetFullPackConfig: () => FullPackConfigByPack<Pack>;
GetLogContext: Hooks['getLogContext'];
GetMainTestRunParams: Hooks['getMainTestRunParams'];
GetTestRunHash: Hooks['getTestRunHash'];
IsTestIncludedInPack: Pack['isTestIncludedInPack'];
IsTestSkipped: Hooks['isTestSkipped'];
LiteReport: LiteReport<
PackParameters['CustomPackProperties'],
Expand Down
6 changes: 3 additions & 3 deletions src/types/waitForEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export type AllRequestsCompletePredicateWithPromise = Readonly<{
}>;

/**
* Request predicate for waitForRequest function.
* Request predicate for `waitForRequest` function.
*/
export type RequestPredicate<SomeRequest extends Request = Request> = (
request: SomeRequest,
) => Promise<boolean> | boolean;

/**
* Response predicate for waitForResponse function.
* Response predicate for `waitForResponse` function.
*/
export type ResponsePredicate<SomeResponse extends Response = Response> = (
request: SomeResponse,
Expand Down Expand Up @@ -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<{
Expand Down
24 changes: 14 additions & 10 deletions src/utils/requestHooks/RequestHookToWaitForEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,12 +36,11 @@ export class RequestHookToWaitForEvents extends RequestHookWithEvents {
override async onRequest(event: RequestHookRequestEvent): Promise<void> {
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({
Expand All @@ -56,12 +56,16 @@ export class RequestHookToWaitForEvents extends RequestHookWithEvents {
*/
override async onResponse(event: RequestHookResponseEvent): Promise<void> {
const {headers} = event;
const requestHookContextId = (headers as Record<symbol, RequestHookContextId>)[
REQUEST_HOOK_CONTEXT_ID_KEY
];

assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined', {
requestHookResponseEvent: event,
});

if (headers) {
completeRequest(
(headers as Record<symbol, RequestHookContextId>)[REQUEST_HOOK_CONTEXT_ID_KEY],
this.waitForEventsState,
);
completeRequest(requestHookContextId, this.waitForEventsState);
}

if (this.waitForEventsState.responsePredicates.size > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/requestHooks/RequestHookWithEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getTestRunCallbackOptions = <Args extends readonly unknown[], Result, This
) => ({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[]) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/test/getIsTestIncludedInPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
6 changes: 2 additions & 4 deletions src/utils/waitForEvents/addNotCompleteRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assertValueIsDefined, assertValueIsUndefined} from '../asserts';
import {assertValueIsUndefined} from '../asserts';

import {processAllRequestsCompletePredicates} from './processAllRequestsCompletePredicates';

Expand All @@ -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<void> => {
assertValueIsDefined(requestHookContextId, 'requestHookContextId is defined', {request});

const {hashOfNotCompleteRequests} = waitForEventsState;

assertValueIsUndefined(
Expand Down
6 changes: 1 addition & 5 deletions src/utils/waitForEvents/completeRequest.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import {assertValueIsDefined} from '../asserts';

import type {RequestHookContextId, WaitForEventsState} from '../../types/internal';

/**
* Completes request on getting his response.
* @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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/waitForEvents/processEventsPredicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils/waitForEvents/processEventsPredicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ProcessEventsPredicates = ((options: OptionsForRequest) => Promise<void>) &
((options: OptionsForResponse) => Promise<void>);

/**
* Processes waitForRequest/waitForResponse predicates for new concrete request/response.
* Processes `waitForRequest`/`waitForResponse` predicates for new concrete request/response.
* @internal
*/
export const processEventsPredicates: ProcessEventsPredicates = async ({
Expand Down

0 comments on commit 66acbf6

Please sign in to comment.