chore: remove GridClient, run only page tests in service mode (#13566)
This commit is contained in:
parent
634f40e850
commit
aee6ba299a
5
.github/workflows/tests_secondary.yml
vendored
5
.github/workflows/tests_secondary.yml
vendored
|
|
@ -185,7 +185,12 @@ jobs:
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npx playwright install --with-deps chromium
|
- run: npx playwright install --with-deps chromium
|
||||||
|
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project='Chromium page tests'
|
||||||
|
if: matrix.mode == 'service'
|
||||||
|
env:
|
||||||
|
PWTEST_MODE: ${{ matrix.mode }}
|
||||||
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run ctest
|
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run ctest
|
||||||
|
if: matrix.mode != 'service'
|
||||||
env:
|
env:
|
||||||
PWTEST_MODE: ${{ matrix.mode }}
|
PWTEST_MODE: ${{ matrix.mode }}
|
||||||
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
|
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) Microsoft Corporation.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import WebSocket from 'ws';
|
|
||||||
import { Connection } from '../client/connection';
|
|
||||||
import type { Playwright } from '../client/playwright';
|
|
||||||
import { getPlaywrightVersion } from '../common/userAgent';
|
|
||||||
|
|
||||||
export class GridClient {
|
|
||||||
private _ws: WebSocket;
|
|
||||||
private _playwright: Playwright;
|
|
||||||
|
|
||||||
static async connect(gridURL: string) {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.set('pwVersion', getPlaywrightVersion(true /* majorMinorOnly */));
|
|
||||||
const ws = new WebSocket(`${gridURL}/claimWorker?` + params.toString());
|
|
||||||
const errorText = await Promise.race([
|
|
||||||
new Promise(f => ws.once('open', () => f(undefined))),
|
|
||||||
new Promise(f => ws.once('close', (code, reason) => f(reason))),
|
|
||||||
]);
|
|
||||||
if (errorText)
|
|
||||||
throw errorText;
|
|
||||||
const connection = new Connection();
|
|
||||||
connection.markAsRemote();
|
|
||||||
connection.onmessage = (message: Object) => ws.send(JSON.stringify(message));
|
|
||||||
ws.on('message', message => connection.dispatch(JSON.parse(message.toString())));
|
|
||||||
ws.on('close', (code, reason) => connection.close(reason.toString()));
|
|
||||||
const playwright = await connection.initializePlaywright();
|
|
||||||
playwright._enablePortForwarding();
|
|
||||||
return new GridClient(ws, playwright);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(ws: WebSocket, playwright: Playwright) {
|
|
||||||
this._ws = ws;
|
|
||||||
this._playwright = playwright;
|
|
||||||
}
|
|
||||||
|
|
||||||
playwright(): Playwright {
|
|
||||||
return this._playwright;
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
this._ws.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -263,6 +263,7 @@ export class GridServer {
|
||||||
// shouldHandle claims it accepts promise, except it doesn't.
|
// shouldHandle claims it accepts promise, except it doesn't.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
this._log('rejecting websocket request');
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,6 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {
|
||||||
const { error } = await gridServer.createAgent();
|
const { error } = await gridServer.createAgent();
|
||||||
if (error)
|
if (error)
|
||||||
throw error;
|
throw error;
|
||||||
process.env.PW_GRID = gridServer.gridURL();
|
|
||||||
return async () => await gridServer.stop();
|
return async () => await gridServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWor
|
||||||
import { rootTestType } from './testType';
|
import { rootTestType } from './testType';
|
||||||
import { createGuid, debugMode } from 'playwright-core/lib/utils';
|
import { createGuid, debugMode } from 'playwright-core/lib/utils';
|
||||||
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
|
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
|
||||||
import { GridClient } from 'playwright-core/lib/grid/gridClient';
|
|
||||||
export { expect } from './expect';
|
export { expect } from './expect';
|
||||||
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
||||||
import * as outOfProcess from 'playwright-core/lib/outofprocess';
|
import * as outOfProcess from 'playwright-core/lib/outofprocess';
|
||||||
|
|
@ -53,12 +52,8 @@ type WorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions & {
|
||||||
export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
defaultBrowserType: [ 'chromium', { scope: 'worker', option: true } ],
|
defaultBrowserType: [ 'chromium', { scope: 'worker', option: true } ],
|
||||||
browserName: [ ({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: 'worker', option: true } ],
|
browserName: [ ({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: 'worker', option: true } ],
|
||||||
playwright: [async ({}, use, workerInfo) => {
|
playwright: [async ({ }, use) => {
|
||||||
if (process.env.PW_GRID) {
|
if (process.env.PW_OUT_OF_PROCESS_DRIVER) {
|
||||||
const gridClient = await GridClient.connect(process.env.PW_GRID);
|
|
||||||
await use(gridClient.playwright() as any);
|
|
||||||
gridClient.close();
|
|
||||||
} else if (process.env.PW_OUT_OF_PROCESS_DRIVER) {
|
|
||||||
const impl = await outOfProcess.start({
|
const impl = await outOfProcess.start({
|
||||||
NODE_OPTIONS: undefined // Hide driver process while debugging.
|
NODE_OPTIONS: undefined // Hide driver process while debugging.
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { GridClient } from '../../packages/playwright-core/lib/grid/gridClient';
|
|
||||||
import { start } from '../../packages/playwright-core/lib/outofprocess';
|
import { start } from '../../packages/playwright-core/lib/outofprocess';
|
||||||
import type { Playwright } from '../../packages/playwright-core/lib/client/playwright';
|
import type { Playwright } from '../../packages/playwright-core/lib/client/playwright';
|
||||||
|
|
||||||
|
|
@ -41,19 +40,6 @@ export class DriverTestMode implements TestMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ServiceTestMode implements TestMode {
|
|
||||||
private _gridClient: GridClient;
|
|
||||||
|
|
||||||
async setup() {
|
|
||||||
this._gridClient = await GridClient.connect('ws://localhost:3333');
|
|
||||||
return this._gridClient.playwright();
|
|
||||||
}
|
|
||||||
|
|
||||||
async teardown() {
|
|
||||||
this._gridClient.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DefaultTestMode implements TestMode {
|
export class DefaultTestMode implements TestMode {
|
||||||
async setup() {
|
async setup() {
|
||||||
return require('playwright-core');
|
return require('playwright-core');
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
import type { TestModeName } from './testMode';
|
import type { TestModeName } from './testMode';
|
||||||
import { DefaultTestMode, DriverTestMode, ServiceTestMode } from './testMode';
|
import { DefaultTestMode, DriverTestMode } from './testMode';
|
||||||
|
|
||||||
export type TestModeWorkerOptions = {
|
export type TestModeWorkerOptions = {
|
||||||
mode: TestModeName;
|
mode: TestModeName;
|
||||||
|
|
@ -32,7 +32,7 @@ export const testModeTest = test.extend<{}, TestModeWorkerOptions & TestModeWork
|
||||||
playwright: [ async ({ mode }, run) => {
|
playwright: [ async ({ mode }, run) => {
|
||||||
const testMode = {
|
const testMode = {
|
||||||
default: new DefaultTestMode(),
|
default: new DefaultTestMode(),
|
||||||
service: new ServiceTestMode(),
|
service: new DefaultTestMode(),
|
||||||
driver: new DriverTestMode(),
|
driver: new DriverTestMode(),
|
||||||
service2: new DefaultTestMode(),
|
service2: new DefaultTestMode(),
|
||||||
}[mode];
|
}[mode];
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,26 @@ const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & Playwrigh
|
||||||
|
|
||||||
if (mode === 'service') {
|
if (mode === 'service') {
|
||||||
config.webServer = {
|
config.webServer = {
|
||||||
command: 'npx playwright experimental-grid-server',
|
command: 'npx playwright experimental-grid-server --auth-token=mysecret --address=http://localhost:3333 --port=3333',
|
||||||
port: 3333,
|
port: 3333,
|
||||||
reuseExistingServer: true,
|
reuseExistingServer: true,
|
||||||
env: {
|
env: {
|
||||||
|
PWTEST_UNSAFE_GRID_VERSION: '1',
|
||||||
PLAYWRIGHT_EXPERIMENTAL_FEATURES: '1',
|
PLAYWRIGHT_EXPERIMENTAL_FEATURES: '1',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
config.use.connectOptions = {
|
||||||
|
wsEndpoint: 'ws://localhost:3333/mysecret/claimWorker?os=linux',
|
||||||
|
};
|
||||||
|
config.projects = [{
|
||||||
|
name: 'Chromium page tests',
|
||||||
|
testMatch: /page\/.*spec.ts$/,
|
||||||
|
testIgnore: 'screenshot',
|
||||||
|
use: {
|
||||||
|
browserName: 'chromium',
|
||||||
|
mode
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode === 'service2') {
|
if (mode === 'service2') {
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,6 @@ async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], b
|
||||||
// END: Reserved CI
|
// END: Reserved CI
|
||||||
PW_TEST_HTML_REPORT_OPEN: undefined,
|
PW_TEST_HTML_REPORT_OPEN: undefined,
|
||||||
PLAYWRIGHT_DOCKER: undefined,
|
PLAYWRIGHT_DOCKER: undefined,
|
||||||
PW_GRID: undefined,
|
|
||||||
PW_TEST_REPORTER: undefined,
|
PW_TEST_REPORTER: undefined,
|
||||||
PW_TEST_REPORTER_WS_ENDPOINT: undefined,
|
PW_TEST_REPORTER_WS_ENDPOINT: undefined,
|
||||||
PW_TEST_SOURCE_TRANSFORM: undefined,
|
PW_TEST_SOURCE_TRANSFORM: undefined,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue