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`
fix: add Playwright's browser version check
fix: add using Playwright version from `package.json`
  • Loading branch information
uid11 committed Aug 29, 2024
1 parent 25b6186 commit 0d99a3b
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 53 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM mcr.microsoft.com/playwright:v1.46.1-noble
ARG PLAYWRIGHT_VERSION

FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-noble

COPY ./build/node_modules/e2ed /node_modules/e2ed

Expand Down
18 changes: 11 additions & 7 deletions autotests/tests/e2edReportExample/browserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
test('correctly read data from browser', {meta: {testId: '14'}}, async () => {
await navigateToPage(E2edReportExample);

await waitForInterfaceStabilization(100);

await createClientFunction(() => {
console.error('error');
console.info('info');
Expand All @@ -23,10 +21,7 @@ test('correctly read data from browser', {meta: {testId: '14'}}, async () => {

setTimeout(() => {
throw new Error('foo');
}, 8);
setTimeout(() => {
throw new Error('bar');
}, 32);
}, 100);
})();

const consoleMessages = getBrowserConsoleMessages();
Expand All @@ -47,5 +42,14 @@ test('correctly read data from browser', {meta: {testId: '14'}}, async () => {

const jsErrors = getBrowserJsErrors();

await expect(jsErrors.length === 0, 'getBrowserJsErrors read JS errors').eql(true);
await expect(
jsErrors.length,
'getBrowserJsErrors read zero JS errors when there are no errors',
).eql(0);

await waitForInterfaceStabilization(100);

await expect(jsErrors.length, 'getBrowserJsErrors read all JS errors').eql(1);

await expect(String(jsErrors[0]), 'getBrowserJsErrors read all JS errors').contains('foo');
});
4 changes: 2 additions & 2 deletions bin/addPackageJsonToBuildDocker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh
set -eu

VERSION=`./bin/getVersion.sh`
E2ED_VERSION=`./bin/getE2edVersion.sh`

echo "{\n \"dependencies\": {\n \"e2ed\": \"$VERSION\"\n }\n}" > ./build/docker/package.json
echo "{\n \"dependencies\": {\n \"e2ed\": \"$E2ED_VERSION\"\n }\n}" > ./build/docker/package.json
8 changes: 6 additions & 2 deletions bin/buildDocker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env sh
set -eu

VERSION=`./bin/getVersion.sh`
E2ED_VERSION=`./bin/getE2edVersion.sh`
PLAYWRIGHT_VERSION=`./bin/getPlaywrightVersion.sh`

docker build --tag e2edhub/e2ed:$VERSION --tag e2edhub/e2ed:latest .
docker build \
--build-arg PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION \
--tag e2edhub/e2ed:$E2ED_VERSION \
--tag e2edhub/e2ed:latest .
6 changes: 6 additions & 0 deletions bin/checkPlaywrightBrowserChromiumVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -eu

PLAYWRIGHT_VERSION=`./bin/getPlaywrightVersion.sh`

grep "\"@playwright/browser-chromium\": \"$PLAYWRIGHT_VERSION\"" ./package.json
File renamed without changes.
4 changes: 4 additions & 0 deletions bin/getPlaywrightVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -eu

grep -m1 @playwright/test ./package.json | cut -d '"' -f 4
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@
"scripts": {
"asserts": "assert-modules-support-case-insensitive-fs ./autotests ./src && assert-package-lock-is-consistent",
"precheck:all": "npm run asserts && npm run clear:lint:cache && npm run build",
"check:all": "npm audit && npm run parallel check:branch lint test",
"check:all": "npm audit && npm run parallel check:branch check:playwright-version lint test",
"check:branch": "node ./build/checkBranch.js",
"check:playwright-version": "./bin/checkPlaywrightBrowserChromiumVersion.sh",
"clear:lint:cache": "rm -f ./build/tsconfig.tsbuildinfo ./node_modules/.cache/lint-*",
"lint": "npm run parallel lint:es lint:prettier lint:types",
"lint:es": "eslint --cache --cache-location=./node_modules/.cache/lint-es --cache-strategy=content --ext=.ts --max-warnings=0 --report-unused-disable-directives .",
Expand Down
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 0d99a3b

Please sign in to comment.