Skip to content

Commit

Permalink
chore: migrate to the testserver.initialize (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Apr 3, 2024
1 parent a20fad9 commit 3010070
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
},
"devDependencies": {
"@babel/preset-typescript": "^7.23.2",
"@playwright/test": "1.43.0-beta-1711849714000",
"@playwright/test": "1.43.0-beta-1712173949000",
"@types/babel__core": "^7.20.3",
"@types/babel__helper-plugin-utils": "^7.10.2",
"@types/babel__traverse": "^7.20.3",
Expand Down
14 changes: 9 additions & 5 deletions src/playwrightTestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ export class PlaywrightTestServer {
return;
const address = await addressPromise;
testServer = new TestServerConnection(address);
await testServer.connect();
await testServer.setSerializer({ serializer: require.resolve('./oopReporter') });
await testServer.initialize({
serializer: require.resolve('./oopReporter'),
closeOnDisconnect: true,
});
if (token?.isCancellationRequested)
return;

Expand Down Expand Up @@ -286,9 +288,11 @@ export class PlaywrightTestServer {
if (!wsEndpoint)
return null;
const testServer = new TestServerConnection(wsEndpoint);
await testServer.connect();
await testServer.setInterceptStdio({ intercept: true });
await testServer.setSerializer({ serializer: require.resolve('./oopReporter') });
await testServer.initialize({
serializer: require.resolve('./oopReporter'),
interceptStdio: true,
closeOnDisconnect: true,
});
return testServer;
}

Expand Down
21 changes: 3 additions & 18 deletions src/upstream/testServerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,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', () => {
Expand All @@ -78,10 +75,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 });
Expand Down Expand Up @@ -112,8 +105,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']> {
Expand All @@ -132,10 +125,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);
}
Expand Down Expand Up @@ -192,10 +181,6 @@ 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);
}
Expand Down
11 changes: 6 additions & 5 deletions src/upstream/testServerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ import { 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>;

watch(params: {
fileNames: string[];
}): Promise<void>;

watchTestDir(params: {}): Promise<void>;

open(params: { location: reporterTypes.Location }): Promise<void>;

resizeTerminal(params: { cols: number, rows: number }): Promise<void>;
Expand Down Expand Up @@ -90,8 +93,6 @@ export interface TestServerInterface {

stopTests(params: {}): Promise<void>;

setInterceptStdio(params: { intercept: boolean }): Promise<void>;

closeGracefully(params: {}): Promise<void>;
}

Expand Down

0 comments on commit 3010070

Please sign in to comment.