Skip to content

Commit

Permalink
FI-678 fix: do not exit from tests subprocess prematurely
Browse files Browse the repository at this point in the history
chore: turn on `@typescript-eslint/max-params` rule
chore: turn on `@typescript-eslint/member-ordering` rule
  • Loading branch information
uid11 committed Feb 13, 2024
1 parent b0b1d45 commit 16006a9
Show file tree
Hide file tree
Showing 31 changed files with 289 additions and 251 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extends:
- airbnb-base
- plugin:import/recommended
- plugin:import/typescript
- plugin:typescript-sort-keys/recommended
- plugin:@typescript-eslint/recommended
- plugin:@typescript-eslint/recommended-requiring-type-checking
- plugin:@typescript-eslint/strict
Expand Down Expand Up @@ -113,7 +112,7 @@ rules:
max-depth: [error, {max: 3}]
max-lines: [error, {max: 120, skipBlankLines: true, skipComments: true}]
max-lines-per-function: [error, {IIFEs: true, max: 100, skipBlankLines: true, skipComments: true}]
max-params: [error, {max: 3}]
max-params: off
max-statements: [error, {max: 25}]
padding-line-between-statements:
- error
Expand Down Expand Up @@ -151,6 +150,7 @@ rules:
- ['^\.\./.*\u0000$']
- ['^\..*\u0000$']
sort-keys: [error, asc, {caseSensitive: true, natural: false}]
typescript-sort-keys/string-enum: error
'@typescript-eslint/ban-types': [error, {extendDefaults: true, types: {'{}': false}}]
'@typescript-eslint/consistent-type-definitions': [error, type]
'@typescript-eslint/consistent-type-exports': error
Expand All @@ -159,6 +159,8 @@ rules:
'@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/naming-convention':
- error
- {selector: default, format: [strictCamelCase, StrictPascalCase], leadingUnderscore: allow}
Expand Down
58 changes: 33 additions & 25 deletions autotests/pageObjects/pages/E2edReportExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,47 @@ type CustomPageParams = {pageCookies?: readonly Cookie[]; pageRequestHeaders?: H
*/
export class E2edReportExample extends Page<CustomPageParams> {
/**
* Cookies that we set (additionally) on a page before navigating to it.
* Navigation bar with test retries.
*/
readonly pageCookies!: readonly Cookie[];
readonly navigationRetries: Selector = locatorIdSelector('app-navigation-retries');

/**
* Request headers that we add to page request.
* Button tabs in navigation bar with test retries.
*/
readonly pageRequestHeaders: Headers | undefined;

override readonly pageStabilizationInterval = 600;

override init(this: E2edReportExample): void {
const {pageCookies = [], pageRequestHeaders} = this.pageParams ?? {};

setReadonlyProperty(this, 'pageCookies', pageCookies);
setReadonlyProperty(this, 'pageRequestHeaders', pageRequestHeaders);
}

getRoute(): E2edReportExampleRoute {
return new E2edReportExampleRoute();
}

/** Navigation bar with test retries */
readonly navigationRetries: Selector = locatorIdSelector('app-navigation-retries');

/** Button tabs in navigation bar with test retries */
readonly navigationRetriesButton: Selector = this.navigationRetries.findByLocatorId(
'app-navigation-retries-button',
);

/** Selected button tab in navigation bar with test retries */
/**
* Selected button tab in navigation bar with test retries.
*/
readonly navigationRetriesButtonSelected: Selector =
this.navigationRetriesButton.filterByLocatorParameter('selected', 'true');

/**
* List of test runs of retry.
* Cookies that we set (additionally) on a page before navigating to it.
*/
readonly testRunsList: Selector = locatorIdSelector('app-column1');
readonly pageCookies!: readonly Cookie[];

/**
* Request headers that we add to page request.
*/
readonly pageRequestHeaders: Headers | undefined;

override readonly pageStabilizationInterval = 600;

/**
* Test run button.
*/
readonly testRunButton: Selector = this.testRunsList.findByLocatorId('app-retries-retry-button');

/**
* List of test runs of retry.
*/
get testRunsList(): Selector {
return locatorIdSelector('app-column1');
}

/**
* Set page cookies and page request headers to context before navigate.
*/
Expand All @@ -74,6 +71,17 @@ export class E2edReportExample extends Page<CustomPageParams> {
}
}

getRoute(): E2edReportExampleRoute {
return new E2edReportExampleRoute();
}

override init(this: E2edReportExample): void {
const {pageCookies = [], pageRequestHeaders} = this.pageParams ?? {};

setReadonlyProperty(this, 'pageCookies', pageCookies);
setReadonlyProperty(this, 'pageRequestHeaders', pageRequestHeaders);
}

override navigateToPage(url: Url): Promise<void> {
if (this.pageRequestHeaders) {
return setPageRequestHeadersAndNavigateToUrl(url, this.pageRequestHeaders);
Expand Down
34 changes: 17 additions & 17 deletions autotests/pageObjects/pages/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ const mainPageLocator = createLocator<MainLocator, Selector>('google', {
* The Main (index) page.
*/
export class Main extends Page<CustomPageParams> {
/**
* Page language.
*/
readonly language!: Language;

override init(this: Main): void {
const {language = 'de'} = this.pageParams ?? {};

setReadonlyProperty(this, 'language', language);
}

getRoute(): MainRoute {
const {language} = this;

return new MainRoute({language});
}

/**
* Body selector.
*/
Expand All @@ -55,6 +38,11 @@ export class Main extends Page<CustomPageParams> {
*/
readonly header = mainPageLocator.header();

/**
* Page language.
*/
readonly language!: Language;

/**
* Search input.
*/
Expand All @@ -67,6 +55,18 @@ export class Main extends Page<CustomPageParams> {
return this.searchInput.value;
}

getRoute(): MainRoute {
const {language} = this;

return new MainRoute({language});
}

override init(this: Main): void {
const {language = 'de'} = this.pageParams ?? {};

setReadonlyProperty(this, 'language', language);
}

/**
* Type text into a search input.
*/
Expand Down
12 changes: 6 additions & 6 deletions autotests/pageObjects/pages/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export class Search extends MobilePage<CustomPageParams> {
*/
readonly searchQuery!: string;

override init(this: Search): void {
const searchQuery = this.pageParams.searchQuery ?? 'foo';

setReadonlyProperty(this, 'searchQuery', searchQuery);
}

getRoute(): SearchRoute {
const {searchQuery} = this;

return new SearchRoute({searchQuery});
}

override init(this: Search): void {
const searchQuery = this.pageParams.searchQuery ?? 'foo';

setReadonlyProperty(this, 'searchQuery', searchQuery);
}

override async waitForPageLoaded(): Promise<void> {
await waitForAllRequestsComplete(
({url}) => {
Expand Down
10 changes: 5 additions & 5 deletions src/ApiRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export abstract class ApiRoute<
SomeRequest extends Request = Request,
SomeResponse extends Response = Response,
> extends Route<Params> {
/**
* Get HTTP method of API route.
*/
abstract getMethod(): Method;

/**
* Request type of API route.
*/
Expand Down Expand Up @@ -59,4 +54,9 @@ export abstract class ApiRoute<
getOrigin(): Url {
return 'http://localhost' as Url;
}

/**
* Get HTTP method of API route.
*/
abstract getMethod(): Method;
}
58 changes: 29 additions & 29 deletions src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,10 @@ declare const PARAMS_KEY: ParamsKeyType;
* Abstract page with base methods.
*/
export abstract class Page<PageParams = undefined> {
constructor(...args: PageClassTypeArgs<PageParams>) {
const [createPageToken, pageParams] = args;

assertValueIsTrue(createPageToken === CREATE_PAGE_TOKEN, 'createPageToken is correct', {
createPageToken,
pageParams,
});

this.pageParams = pageParams as PageParams;

const {
pageStabilizationInterval,
waitForAllRequestsComplete: {maxIntervalBetweenRequestsInMs},
} = getFullPackConfig();

this.maxIntervalBetweenRequestsInMs = maxIntervalBetweenRequestsInMs;
this.pageStabilizationInterval = pageStabilizationInterval;
}
/**
* Type of page parameters.
*/
declare readonly [PARAMS_KEY]: PageParams;

/**
* Default maximum interval (in milliseconds) between requests.
Expand All @@ -61,16 +47,24 @@ export abstract class Page<PageParams = undefined> {
*/
readonly pageStabilizationInterval: number;

/**
* Type of page parameters.
*/
declare readonly [PARAMS_KEY]: PageParams;
constructor(...args: PageClassTypeArgs<PageParams>) {
const [createPageToken, pageParams] = args;

/**
* Optional initialization (asynchronous or synchronous) of the page after
* the synchronous constructor has run.
*/
init?(): AsyncVoid;
assertValueIsTrue(createPageToken === CREATE_PAGE_TOKEN, 'createPageToken is correct', {
createPageToken,
pageParams,
});

this.pageParams = pageParams as PageParams;

const {
pageStabilizationInterval,
waitForAllRequestsComplete: {maxIntervalBetweenRequestsInMs},
} = getFullPackConfig();

this.maxIntervalBetweenRequestsInMs = maxIntervalBetweenRequestsInMs;
this.pageStabilizationInterval = pageStabilizationInterval;
}

/**
* Optional hook that runs after asserts the page.
Expand Down Expand Up @@ -113,9 +107,10 @@ export abstract class Page<PageParams = undefined> {
beforeReloadPage?(): AsyncVoid;

/**
* Get page route (for navigation to the page).
* Optional initialization (asynchronous or synchronous) of the page after
* the synchronous constructor has run.
*/
abstract getRoute(): PageRoute<unknown>;
init?(): AsyncVoid;

/**
* Navigates to the page by url.
Expand All @@ -141,4 +136,9 @@ export abstract class Page<PageParams = undefined> {

await waitForInterfaceStabilization(this.pageStabilizationInterval);
}

/**
* Get page route (for navigation to the page).
*/
abstract getRoute(): PageRoute<unknown>;
}
34 changes: 17 additions & 17 deletions src/Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,34 @@ declare const PARAMS_KEY: ParamsKeyType;
*/
export abstract class Route<RouteParams> {
/**
* Returns route params from the passed url.
* @throws {Error} If the route does not match on the url.
* Type of route parameters.
*/
static getParamsFromUrl?(url: Url): unknown;
declare readonly [PARAMS_KEY]: RouteParams;

/**
* Immutable route parameters.
*/
readonly routeParams: RouteParams;

constructor(...args: ZeroOrOneArg<RouteParams>) {
[this.routeParams] = args as [params: RouteParams];
}

/**
* Immutable route parameters.
* Returns route params from the passed url.
* @throws {Error} If the route does not match on the url.
*/
readonly routeParams: RouteParams;
static getParamsFromUrl?(url: Url): unknown;

/**
* Type of route parameters.
* Returns the url of the route.
*/
declare readonly [PARAMS_KEY]: RouteParams;
getUrl(): Url {
const originWithoutSlashesAtTheEnd = this.getOrigin().replace(SLASHES_AT_THE_END_REGEXP, '');
const pathWithoutSlashesAtTheStart = this.getPath().replace(SLASHES_AT_THE_START_REGEXP, '');

return `${originWithoutSlashesAtTheEnd}/${pathWithoutSlashesAtTheStart}` as Url;
}

/**
* Returns `true` if url matches the page with given parameters, and `false` otherwise.
Expand All @@ -44,14 +54,4 @@ export abstract class Route<RouteParams> {
* Returns the path-part of the route.
*/
abstract getPath(): string;

/**
* Returns the url of the route.
*/
getUrl(): Url {
const originWithoutSlashesAtTheEnd = this.getOrigin().replace(SLASHES_AT_THE_END_REGEXP, '');
const pathWithoutSlashesAtTheStart = this.getPath().replace(SLASHES_AT_THE_START_REGEXP, '');

return `${originWithoutSlashesAtTheEnd}/${pathWithoutSlashesAtTheStart}` as Url;
}
}
2 changes: 1 addition & 1 deletion src/actions/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const drag = async (
dragOffsetX: number,
dragOffsetY: number,
{stabilizationInterval, ...options}: Options = {},
// eslint-disable-next-line max-params
// eslint-disable-next-line @typescript-eslint/max-params
): Promise<void> => {
const description = getDescriptionFromSelector(selector);

Expand Down
2 changes: 1 addition & 1 deletion src/actions/selectText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const selectText = (
startPos = 0,
endPos?: number,
options?: Options,
// eslint-disable-next-line max-params
// eslint-disable-next-line @typescript-eslint/max-params
): Promise<void> => {
const description = getDescriptionFromSelector(selector);

Expand Down
4 changes: 2 additions & 2 deletions src/bin/runTestsSubprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ testIdleTimeoutObject.unref();
*/
process.on('message', (runRetryOptions: RunRetryOptions) => {
void runTests(runRetryOptions).then(
() => exitFromTestsSubprocess({hasError: false, reason: 'Run of tests is correctly completed'}),
() => exitFromTestsSubprocess({hasError: true, reason: 'Run of tests completed with error'}),
() => exitFromTestsSubprocess({hasError: false, reason: 'run of tests is correctly completed'}),
() => exitFromTestsSubprocess({hasError: true, reason: 'run of tests completed with error'}),
);
});
Loading

0 comments on commit 16006a9

Please sign in to comment.