Skip to content

Commit

Permalink
FI-1031 feat: add typed browser parameters to pack config
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Dec 30, 2023
1 parent 5fd37e3 commit ab3e25c
Show file tree
Hide file tree
Showing 48 changed files with 371 additions and 72 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ that exports the pack's config under the name `pack`.

Here are the basic fields of the pack config.

`browser: string`: browser name as a command to launch it
(like `chrome`, `chromium`, `firefox`, `webkit`, etc).

`browserFlags: string[]`: array of browser flags, like `--disable-dev-shm-usage`,
with which the browser is launched to run tests.

`concurrency: number`: the number of browser windows in which tests will run in parallel.

`customPackProperties: CustomPackProperties`: a custom set of fields defined within the project.
Expand All @@ -265,6 +271,16 @@ 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.

`enableChromeDevToolsProtocol: boolean`: enables [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/)
for browser control in tests (instead of `testcafe-hammerhead`).

`enableHeadlessMode: boolean`: enables headless mode (if browser supports such mode).

`enableMobileDeviceMode: boolean`: enables Chromium [mobile device mode](https://developer.chrome.com/docs/devtools/device-mode).

`enableTouchEventEmulation: boolean`: enables touch event emulation.
If `true`, page fires `touch` events when test interact with the page (instead of `click` events).

`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.
Expand Down Expand Up @@ -314,6 +330,8 @@ If the mapping returns `undefined`, the log entry is not skipped, but is printed
`your-project/autotests/bin/runDocker.sh` (until the test passes).
For example, if it is equal to three, the test will be run no more than three times.

`overriddenUserAgent: string | null`: if not `null`, then this value will override the browser's user agent in tests.

`packTimeout: number`: timeout (in millisecond) for the entire pack of tests (tasks).
If the test pack takes longer than this timeout, the pack will fail with the appropriate error.

Expand Down Expand Up @@ -356,6 +374,10 @@ This parameter can be overridden in the test-specific options.
If the test run takes longer than this timeout, the test fails and rerun on the next retry.
This parameter can be overridden in the test-specific options.

`viewportHeight: number`: height of viewport of page in pixels.

`viewportWidth: number`: width of viewport of page in pixels.

`waitForAllRequestsComplete.maxIntervalBetweenRequestsInMs: number`: default maximum interval
(in milliseconds) between requests for `waitForAllRequestsComplete` function.
If there are no new requests for more than this interval, then the promise
Expand Down
19 changes: 15 additions & 4 deletions autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@ 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',
'--ignore-certificate-errors',
];

const browser = isLocalRun ? 'chrome' : 'chromium';

const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.testId !== '13';

const overriddenUserAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.35 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.35';

/**
* Pack of tests or tasks (pack configuration object).
*/
export const pack: Pack = {
ajaxRequestTimeout: 40_000,
assertionTimeout: 5_000,
browser: [browser, ...browserFlags].join(' '),
browser,
browserFlags,
browserInitTimeout: 60_000,
concurrency: isLocalRun ? 1 : 2,
customPackProperties: {internalPackRunId: 0, name: 'allTests'},
disableNativeAutomation: true,
doAfterPack,
doBeforePack,
dockerImage: 'e2edhub/e2ed',
enableChromeDevToolsProtocol: true,
enableHeadlessMode: true,
enableMobileDeviceMode: false,
enableTouchEventEmulation: false,
filterTestsIntoPack,
liteReportFileName: 'lite-report.json',
logFileName: 'pack-logs.log',
Expand All @@ -54,7 +62,8 @@ export const pack: Pack = {
mapLogPayloadInLogFile,
mapLogPayloadInReport,
maxRetriesCountInDocker: 3,
packTimeout: 90 * 60_000,
overriddenUserAgent,
packTimeout: 5 * 60_000,
pageRequestTimeout: 30_000,
pageStabilizationInterval: 500,
pathToScreenshotsDirectoryForReport: './screenshots',
Expand All @@ -68,6 +77,8 @@ export const pack: Pack = {
testFileGlobs: ['./autotests/tests/**/*.ts', '!**/*.skip.ts'],
testIdleTimeout: 20_000,
testTimeout: 60_000,
viewportHeight: 800,
viewportWidth: 1280,
waitForAllRequestsComplete: {
maxIntervalBetweenRequestsInMs: 500,
timeout: 30_000,
Expand Down
2 changes: 1 addition & 1 deletion src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {waitForAllRequestsComplete, waitForInterfaceStabilization} from './actions/waitFor';
import {CREATE_PAGE_TOKEN} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
import {getFullPackConfig} from './utils/getFullPackConfig';
import {getFullPackConfig} from './utils/config';

import type {PageRoute} from './PageRoute';
import type {AsyncVoid, PageClassTypeArgs, ParamsKeyType} from './types/internal';
Expand Down
41 changes: 21 additions & 20 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Modules in the dependency graph should only import the modules above them:
1. `types`
2. `configurator`
3. `constants`
4. `testcaferc`
5. `testcafe`
6. `esm`
7. `generators`
4. `testcafe`
5. `esm`
6. `generators`
7. `utils/browser`
8. `utils/getDurationWithUnits`
9. `utils/setReadonlyProperty`
10. `utils/selectors`
Expand All @@ -22,19 +22,20 @@ Modules in the dependency graph should only import the modules above them:
15. `utils/userland`
16. `utils/fn`
17. `utils/environment`
18. `utils/getFullPackConfig`
19. `utils/runLabel`
20. `utils/generalLog`
21. `utils/fs`
22. `selectors`
23. `Route`
24. `ApiRoute`
25. `PageRoute`
26. `testController`
27. `useContext`
28. `context`
29. `utils/log`
30. `utils/waitForEvents`
31. `utils/expect`
32. `expect`
33. ...
18. `testcaferc`
19. `utils/config`
20. `utils/runLabel`
21. `utils/generalLog`
22. `utils/fs`
23. `selectors`
24. `Route`
25. `ApiRoute`
26. `PageRoute`
27. `testController`
28. `useContext`
29. `context`
30. `utils/log`
31. `utils/waitForEvents`
32. `utils/expect`
33. `expect`
34. ...
2 changes: 1 addition & 1 deletion src/actions/navigateToUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {LogEventType} from '../constants/internal';
import {createClientFunction} from '../createClientFunction';
import {testController} from '../testController';
import {getFullPackConfig} from '../utils/getFullPackConfig';
import {getFullPackConfig} from '../utils/config';
import {log} from '../utils/log';

import type {Url, Void} from '../types/internal';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForAllRequestsComplete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {LogEventType} from '../../constants/internal';
import {getTestRunPromise} from '../../context/testRunPromise';
import {getWaitForEventsState} from '../../context/waitForEventsState';
import {getFullPackConfig} from '../../utils/config';
import {E2edError} from '../../utils/error';
import {setCustomInspectOnFunction} from '../../utils/fn';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {log} from '../../utils/log';
import {getPromiseWithResolveAndReject} from '../../utils/promise';
import {RequestHookToWaitForEvents} from '../../utils/requestHooks';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForInterfaceStabilization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import {LogEventType} from '../../constants/internal';
import {createClientFunction} from '../../createClientFunction';
import {getFullPackConfig} from '../../utils/config';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {log} from '../../utils/log';

import type {UtcTimeInMs} from '../../types/internal';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {LogEventType} from '../../constants/internal';
import {getTestRunPromise} from '../../context/testRunPromise';
import {getWaitForEventsState} from '../../context/waitForEventsState';
import {getFullPackConfig} from '../../utils/config';
import {E2edError} from '../../utils/error';
import {setCustomInspectOnFunction} from '../../utils/fn';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {log} from '../../utils/log';
import {getPromiseWithResolveAndReject} from '../../utils/promise';
import {RequestHookToWaitForEvents} from '../../utils/requestHooks';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForRequestToRoute.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {LogEventType} from '../../constants/internal';
import {assertValueIsDefined, assertValueIsUndefined} from '../../utils/asserts';
import {getFullPackConfig} from '../../utils/config';
import {setCustomInspectOnFunction} from '../../utils/fn';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {getRouteInstanceFromUrl} from '../../utils/getRouteInstanceFromUrl';
import {log} from '../../utils/log';

Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {LogEventType} from '../../constants/internal';
import {getTestRunPromise} from '../../context/testRunPromise';
import {getWaitForEventsState} from '../../context/waitForEventsState';
import {getFullPackConfig} from '../../utils/config';
import {E2edError} from '../../utils/error';
import {setCustomInspectOnFunction} from '../../utils/fn';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {log} from '../../utils/log';
import {getPromiseWithResolveAndReject} from '../../utils/promise';
import {RequestHookToWaitForEvents} from '../../utils/requestHooks';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/waitFor/waitForResponseToRoute.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {LogEventType} from '../../constants/internal';
import {assertValueIsDefined, assertValueIsUndefined} from '../../utils/asserts';
import {getFullPackConfig} from '../../utils/config';
import {setCustomInspectOnFunction} from '../../utils/fn';
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
import {getFullPackConfig} from '../../utils/getFullPackConfig';
import {getRouteInstanceFromUrl} from '../../utils/getRouteInstanceFromUrl';
import {log} from '../../utils/log';

Expand Down
2 changes: 1 addition & 1 deletion src/bin/runTestsSubprocess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getFullPackConfig} from '../utils/getFullPackConfig';
import {getFullPackConfig} from '../utils/config';
import {runTests} from '../utils/tests';

import type {RunRetryOptions} from '../types/internal';
Expand Down
20 changes: 13 additions & 7 deletions src/testcaferc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Full pack configuration (extended TestCafe configuration) for running tests.
* Don't import this module. Instead, use `utils/getFullPackConfig`.
* Don't import this module. Instead, use `getFullPackConfig` from `utils/config`.
*/

import {join} from 'node:path';
Expand All @@ -11,6 +11,9 @@ import {
SCREENSHOTS_DIRECTORY_PATH,
} from './constants/internal';
import {assertValueIsTrue} from './utils/asserts';
import {getTestCafeBrowsersString} from './utils/browser';
// eslint-disable-next-line import/no-internal-modules
import {assertUserlandPack} from './utils/config/assertUserlandPack';
import {getPathToPack} from './utils/environment';
import {setCustomInspectOnFunction} from './utils/fn';

Expand All @@ -31,13 +34,11 @@ const absoluteCompiledUserlandPackPath = join(
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require
const userlandPack = require<{pack: UserlandPack}>(absoluteCompiledUserlandPackPath).pack;

assertUserlandPack(userlandPack);

const frozenPartOfTestCafeConfig: FrozenPartOfTestCafeConfig = {
color: true,
compilerOptions: {
typescript: {
options: {esModuleInterop: true, resolveJsonModule: true},
},
},
compilerOptions: {typescript: {options: {esModuleInterop: true, resolveJsonModule: true}}},
disableMultipleWindows: true,
hostname: 'localhost',
pageLoadTimeout: 0,
Expand All @@ -55,7 +56,8 @@ const frozenPartOfTestCafeConfig: FrozenPartOfTestCafeConfig = {

const fullPackConfig: FullPackConfig = {
...userlandPack,
browsers: userlandPack.browser,
browsers: getTestCafeBrowsersString(userlandPack),
disableNativeAutomation: !userlandPack.enableChromeDevToolsProtocol,
src: userlandPack.testFileGlobs,
...frozenPartOfTestCafeConfig,
};
Expand All @@ -64,6 +66,8 @@ const {
doAfterPack,
doBeforePack,
filterTestsIntoPack,
mapBackendResponseErrorToLog,
mapBackendResponseToLog,
mapLogPayloadInConsole,
mapLogPayloadInLogFile,
mapLogPayloadInReport,
Expand All @@ -78,6 +82,8 @@ for (const fn of doBeforePack) {
}

setCustomInspectOnFunction(filterTestsIntoPack);
setCustomInspectOnFunction(mapBackendResponseErrorToLog);
setCustomInspectOnFunction(mapBackendResponseToLog);
setCustomInspectOnFunction(mapLogPayloadInConsole);
setCustomInspectOnFunction(mapLogPayloadInLogFile);
setCustomInspectOnFunction(mapLogPayloadInReport);
Expand Down
4 changes: 1 addition & 3 deletions src/types/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import type {OwnE2edConfig} from './ownE2edConfig';
type UserlandTestCafeConfig = Readonly<{
ajaxRequestTimeout: number;
assertionTimeout: number;
browser: string;
browserInitTimeout: number;
concurrency: number;
disableNativeAutomation: boolean;
pageRequestTimeout: number;
port1: number;
port2: number;
Expand Down Expand Up @@ -67,7 +65,7 @@ export type FullPackConfigWithoutDoBeforePack<
TestMeta
>) &
FrozenPartOfTestCafeConfig &
Readonly<{browsers: string; src: readonly string[]}>;
Readonly<{browsers: string; disableNativeAutomation: boolean; src: readonly string[]}>;

/**
* The complete userland pack config.
Expand Down
Loading

0 comments on commit ab3e25c

Please sign in to comment.