mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: migrate to the testserver.initialize (#30226)
This commit is contained in:
parent
5c5f0d77e4
commit
8ee286b366
@ -216,7 +216,7 @@ class StdinServer implements Transport {
|
||||
}
|
||||
|
||||
async dispatch(method: string, params: any) {
|
||||
if (method === 'ready') {
|
||||
if (method === 'initialize') {
|
||||
if (this._traceUrl)
|
||||
this._loadTrace(this._traceUrl);
|
||||
}
|
||||
|
@ -64,10 +64,7 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
|
||||
});
|
||||
const pingInterval = setInterval(() => this._sendMessage('ping').catch(() => {}), 30000);
|
||||
this._connectedPromise = new Promise<void>((f, r) => {
|
||||
this._ws.addEventListener('open', () => {
|
||||
f();
|
||||
this._ws.send(JSON.stringify({ id: -1, method: 'ready' }));
|
||||
});
|
||||
this._ws.addEventListener('open', () => f());
|
||||
this._ws.addEventListener('error', r);
|
||||
});
|
||||
this._ws.addEventListener('close', () => {
|
||||
@ -76,10 +73,6 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
|
||||
});
|
||||
}
|
||||
|
||||
connect() {
|
||||
return this._connectedPromise;
|
||||
}
|
||||
|
||||
private async _sendMessage(method: string, params?: any): Promise<any> {
|
||||
const logForTest = (globalThis as any).__logForTest;
|
||||
logForTest?.({ method, params });
|
||||
@ -110,8 +103,8 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
|
||||
this._onLoadTraceRequestedEmitter.fire(params);
|
||||
}
|
||||
|
||||
async setSerializer(params: { serializer: string; }): Promise<void> {
|
||||
await this._sendMessage('setSerializer', params);
|
||||
async initialize(params: Parameters<TestServerInterface['initialize']>[0]): ReturnType<TestServerInterface['initialize']> {
|
||||
await this._sendMessage('initialize', params);
|
||||
}
|
||||
|
||||
async ping(params: Parameters<TestServerInterface['ping']>[0]): ReturnType<TestServerInterface['ping']> {
|
||||
@ -130,10 +123,6 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
|
||||
this._sendMessageNoReply('watch', params);
|
||||
}
|
||||
|
||||
async watchTestDir(params: Parameters<TestServerInterface['watchTestDir']>[0]): ReturnType<TestServerInterface['watchTestDir']> {
|
||||
await this._sendMessage('watchTestDir', params);
|
||||
}
|
||||
|
||||
async open(params: Parameters<TestServerInterface['open']>[0]): ReturnType<TestServerInterface['open']> {
|
||||
await this._sendMessage('open', params);
|
||||
}
|
||||
@ -190,11 +179,14 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
|
||||
this._sendMessageNoReply('stopTests', params);
|
||||
}
|
||||
|
||||
async setInterceptStdio(params: Parameters<TestServerInterface['setInterceptStdio']>[0]): ReturnType<TestServerInterface['setInterceptStdio']> {
|
||||
await this._sendMessage('setInterceptStdio', params);
|
||||
}
|
||||
|
||||
async closeGracefully(params: Parameters<TestServerInterface['closeGracefully']>[0]): ReturnType<TestServerInterface['closeGracefully']> {
|
||||
await this._sendMessage('closeGracefully', params);
|
||||
}
|
||||
|
||||
close() {
|
||||
try {
|
||||
this._ws.close();
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,12 @@ import type { JsonEvent } from './teleReceiver';
|
||||
export type ReportEntry = JsonEvent;
|
||||
|
||||
export interface TestServerInterface {
|
||||
setSerializer(params: { serializer: string }): Promise<void>;
|
||||
initialize(params: {
|
||||
serializer?: string,
|
||||
closeOnDisconnect?: boolean,
|
||||
interceptStdio?: boolean,
|
||||
watchTestDirs?: boolean,
|
||||
}): Promise<void>;
|
||||
|
||||
ping(params: {}): Promise<void>;
|
||||
|
||||
@ -29,8 +34,6 @@ export interface TestServerInterface {
|
||||
fileNames: string[];
|
||||
}): Promise<void>;
|
||||
|
||||
watchTestDir(params: {}): Promise<void>;
|
||||
|
||||
open(params: { location: reporterTypes.Location }): Promise<void>;
|
||||
|
||||
resizeTerminal(params: { cols: number, rows: number }): Promise<void>;
|
||||
@ -90,8 +93,6 @@ export interface TestServerInterface {
|
||||
|
||||
stopTests(params: {}): Promise<void>;
|
||||
|
||||
setInterceptStdio(params: { intercept: boolean }): Promise<void>;
|
||||
|
||||
closeGracefully(params: {}): Promise<void>;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class TestServer {
|
||||
}
|
||||
|
||||
async stop() {
|
||||
await this._dispatcher?.setInterceptStdio({ intercept: false });
|
||||
await this._dispatcher?._setInterceptStdio(false);
|
||||
await this._dispatcher?.runGlobalTeardown();
|
||||
}
|
||||
}
|
||||
@ -72,13 +72,17 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
readonly _dispatchEvent: TestServerInterfaceEventEmitters['dispatchEvent'];
|
||||
private _plugins: TestRunnerPluginRegistration[] | undefined;
|
||||
private _serializer = require.resolve('./uiModeReporter');
|
||||
private _watchTestDir = false;
|
||||
private _watchTestDirs = false;
|
||||
private _closeOnDisconnect = false;
|
||||
|
||||
constructor(configFile: string | undefined) {
|
||||
this._configFile = configFile;
|
||||
this.transport = {
|
||||
dispatch: (method, params) => (this as any)[method](params),
|
||||
onclose: () => {},
|
||||
onclose: () => {
|
||||
if (this._closeOnDisconnect)
|
||||
gracefullyProcessExitDoNotHang(0);
|
||||
},
|
||||
};
|
||||
this._globalWatcher = new Watcher('deep', () => this._dispatchEvent('listChanged', {}));
|
||||
this._testWatcher = new Watcher('flat', events => {
|
||||
@ -89,10 +93,6 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
this._dispatchEvent = (method, params) => this.transport.sendEvent?.(method, params);
|
||||
}
|
||||
|
||||
async setSerializer(params: { serializer: string; }): Promise<void> {
|
||||
this._serializer = params.serializer;
|
||||
}
|
||||
|
||||
private async _wireReporter(messageSink: (message: any) => void) {
|
||||
return await createReporterForTestServer(this._serializer, messageSink);
|
||||
}
|
||||
@ -104,7 +104,16 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
return { reporter, report };
|
||||
}
|
||||
|
||||
async ready() {}
|
||||
async initialize(params: Parameters<TestServerInterface['initialize']>[0]): ReturnType<TestServerInterface['initialize']> {
|
||||
if (params.serializer)
|
||||
this._serializer = params.serializer;
|
||||
if (params.closeOnDisconnect)
|
||||
this._closeOnDisconnect = true;
|
||||
if (params.interceptStdio)
|
||||
await this._setInterceptStdio(true);
|
||||
if (params.watchTestDirs)
|
||||
this._watchTestDirs = true;
|
||||
}
|
||||
|
||||
async ping() {}
|
||||
|
||||
@ -226,7 +235,7 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
projectOutputs.add(result.outDir);
|
||||
}
|
||||
|
||||
if (this._watchTestDir)
|
||||
if (this._watchTestDirs)
|
||||
this._globalWatcher.update([...projectDirs], [...projectOutputs], false);
|
||||
return { report, status };
|
||||
}
|
||||
@ -295,10 +304,6 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
return { status: await run };
|
||||
}
|
||||
|
||||
async watchTestDir() {
|
||||
this._watchTestDir = true;
|
||||
}
|
||||
|
||||
async watch(params: { fileNames: string[]; }) {
|
||||
const files = new Set<string>();
|
||||
for (const fileName of params.fileNames) {
|
||||
@ -321,10 +326,10 @@ class TestServerDispatcher implements TestServerInterface {
|
||||
await this._testRun?.run;
|
||||
}
|
||||
|
||||
async setInterceptStdio(params: Parameters<TestServerInterface['setInterceptStdio']>[0]): ReturnType<TestServerInterface['setInterceptStdio']> {
|
||||
async _setInterceptStdio(intercept: boolean) {
|
||||
if (process.env.PWTEST_DEBUG)
|
||||
return;
|
||||
if (params.intercept) {
|
||||
if (intercept) {
|
||||
process.stdout.write = (chunk: string | Buffer) => {
|
||||
this._dispatchEvent('stdio', chunkToPayload('stdout', chunk));
|
||||
return true;
|
||||
|
@ -172,8 +172,10 @@ export const UIModeView: React.FC<{}> = ({
|
||||
setIsLoading(true);
|
||||
setWatchedTreeIds({ value: new Set() });
|
||||
(async () => {
|
||||
await testServerConnection.setInterceptStdio({ intercept: true });
|
||||
await testServerConnection.watchTestDir({});
|
||||
await testServerConnection.initialize({
|
||||
interceptStdio: true,
|
||||
watchTestDirs: true
|
||||
});
|
||||
const { status } = await testServerConnection.runGlobalSetup({});
|
||||
if (status !== 'passed')
|
||||
return;
|
||||
|
@ -93,6 +93,7 @@ export const WorkbenchLoader: React.FunctionComponent<{
|
||||
setDragOver(false);
|
||||
setProcessingErrorMessage(null);
|
||||
});
|
||||
testServerConnection.initialize({}).catch(() => {});
|
||||
} else if (!newTraceURLs.some(url => url.startsWith('blob:'))) {
|
||||
// Don't re-use blob file URLs on page load (results in Fetch error)
|
||||
setTraceURLs(newTraceURLs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user