Skip to content

Commit

Permalink
FI-1344 refactor: Playwright config (use object)
Browse files Browse the repository at this point in the history
refactor: reexport `devices` from `@playwright/test`
  • Loading branch information
uid11 committed Aug 27, 2024
1 parent 25b6186 commit a2c7916
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 40 deletions.
60 changes: 20 additions & 40 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {isLocalRun} from './configurator';

import type {FullPackConfig, Mutable, UserlandPack} from './types/internal';

import {defineConfig} from '@playwright/test';
import {defineConfig, type PlaywrightTestConfig} from '@playwright/test';

const maxTimeoutInMs = 3600_000;

Expand Down Expand Up @@ -91,6 +91,23 @@ if (isDebug) {
setReadonlyProperty(userlandPack, 'testTimeout', maxTimeoutInMs);
}

const useOptions: PlaywrightTestConfig['use'] = {
actionTimeout: userlandPack.testIdleTimeout,
browserName: userlandPack.browserName,
// eslint-disable-next-line @typescript-eslint/naming-convention
bypassCSP: true,
deviceScaleFactor: userlandPack.deviceScaleFactor,
hasTouch: userlandPack.enableTouchEventEmulation,
headless: isLocalRun ? userlandPack.enableHeadlessMode : true,
isMobile: userlandPack.enableMobileDeviceMode,
launchOptions: {args: [...userlandPack.browserFlags]},
navigationTimeout: userlandPack.pageRequestTimeout,
trace: 'retain-on-failure',
userAgent: userlandPack.userAgent,
viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth},
...userlandPack.overriddenConfigFields?.use,
};

const playwrightConfig = defineConfig({
expect: {timeout: userlandPack.assertionTimeout},

Expand All @@ -100,19 +117,7 @@ const playwrightConfig = defineConfig({

outputDir: join(relativePathFromInstalledE2edToRoot, INTERNAL_REPORTS_DIRECTORY_PATH),

projects: [
{
name: userlandPack.browserName,
use: {
browserName: userlandPack.browserName,
deviceScaleFactor: userlandPack.deviceScaleFactor,
hasTouch: userlandPack.enableTouchEventEmulation,
isMobile: userlandPack.enableMobileDeviceMode,
userAgent: userlandPack.userAgent,
viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth},
},
},
],
projects: [{name: userlandPack.browserName, use: useOptions}],

retries: isLocalRun ? 0 : userlandPack.maxRetriesCountInDocker - 1,

Expand All @@ -126,32 +131,7 @@ const playwrightConfig = defineConfig({

...userlandPack.overriddenConfigFields,

use: {
actionTimeout: userlandPack.testIdleTimeout,

browserName: userlandPack.browserName,

// eslint-disable-next-line @typescript-eslint/naming-convention
bypassCSP: true,

deviceScaleFactor: userlandPack.deviceScaleFactor,

hasTouch: userlandPack.enableTouchEventEmulation,

headless: isLocalRun ? userlandPack.enableHeadlessMode : true,

isMobile: userlandPack.enableMobileDeviceMode,

navigationTimeout: userlandPack.pageRequestTimeout,

trace: 'retain-on-failure',

userAgent: userlandPack.userAgent,

viewport: {height: userlandPack.viewportHeight, width: userlandPack.viewportWidth},

...userlandPack.overriddenConfigFields?.use,
},
use: useOptions,
});

const config: FullPackConfig = Object.assign(playwrightConfig, userlandPack);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export {ApiRoute} from './ApiRoute';
export {Page} from './Page';
export {PageRoute} from './PageRoute';
export {devices} from './playwright';
export {Route} from './Route';
export {getPlaywrightPage, useContext} from './useContext';

Expand Down
1 change: 1 addition & 0 deletions src/playwright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {devices} from '@playwright/test';
1 change: 1 addition & 0 deletions src/utils/fullMocks/enableFullMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const enableFullMocks = async (
requestKinds: Object.fromEntries(
Object.entries(testFullMocks).map(([key, value]) => [key, value.length]),
),
testId: fullMocksState.testId,
},
LogEventType.InternalUtil,
);
Expand Down

0 comments on commit a2c7916

Please sign in to comment.