mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 22:22:53 +03:00
feat(rpc): update BrowserServer (#3112)
- Make BrowserServer a scope. - Plumb exitCode and signal to BrowserServer.on('close'). - Use toImpl in a test.
This commit is contained in:
parent
0f0e2acfaf
commit
deccddba24
@ -274,7 +274,10 @@ export interface BrowserServerChannel extends Channel {
|
|||||||
close(params?: BrowserServerCloseParams): Promise<BrowserServerCloseResult>;
|
close(params?: BrowserServerCloseParams): Promise<BrowserServerCloseResult>;
|
||||||
kill(params?: BrowserServerKillParams): Promise<BrowserServerKillResult>;
|
kill(params?: BrowserServerKillParams): Promise<BrowserServerKillResult>;
|
||||||
}
|
}
|
||||||
export type BrowserServerCloseEvent = {};
|
export type BrowserServerCloseEvent = {
|
||||||
|
exitCode?: number,
|
||||||
|
signal?: string,
|
||||||
|
};
|
||||||
export type BrowserServerCloseParams = {};
|
export type BrowserServerCloseParams = {};
|
||||||
export type BrowserServerCloseResult = void;
|
export type BrowserServerCloseResult = void;
|
||||||
export type BrowserServerKillParams = {};
|
export type BrowserServerKillParams = {};
|
||||||
|
@ -25,8 +25,11 @@ export class BrowserServer extends ChannelOwner<BrowserServerChannel, BrowserSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserServerInitializer) {
|
constructor(parent: ChannelOwner, type: string, guid: string, initializer: BrowserServerInitializer) {
|
||||||
super(parent, type, guid, initializer);
|
super(parent, type, guid, initializer, true);
|
||||||
this._channel.on('close', () => this.emit(Events.BrowserServer.Close));
|
this._channel.on('close', ({ exitCode, signal }) => {
|
||||||
|
this.emit(Events.BrowserServer.Close, exitCode === undefined ? null : exitCode, signal === undefined ? null : signal);
|
||||||
|
this._dispose();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process(): ChildProcess {
|
process(): ChildProcess {
|
||||||
|
@ -242,7 +242,10 @@ scheme.BrowserServerInitializer = tObject({
|
|||||||
wsEndpoint: tString,
|
wsEndpoint: tString,
|
||||||
pid: tNumber,
|
pid: tNumber,
|
||||||
});
|
});
|
||||||
scheme.BrowserServerCloseEvent = tObject({});
|
scheme.BrowserServerCloseEvent = tObject({
|
||||||
|
exitCode: tOptional(tNumber),
|
||||||
|
signal: tOptional(tString),
|
||||||
|
});
|
||||||
scheme.BrowserServerCloseParams = tOptional(tObject({}));
|
scheme.BrowserServerCloseParams = tOptional(tObject({}));
|
||||||
scheme.BrowserServerCloseResult = tUndefined;
|
scheme.BrowserServerCloseResult = tUndefined;
|
||||||
scheme.BrowserServerKillParams = tOptional(tObject({}));
|
scheme.BrowserServerKillParams = tOptional(tObject({}));
|
||||||
|
@ -354,7 +354,9 @@ BrowserServer:
|
|||||||
events:
|
events:
|
||||||
|
|
||||||
close:
|
close:
|
||||||
|
parameters:
|
||||||
|
exitCode: number?
|
||||||
|
signal: string?
|
||||||
|
|
||||||
|
|
||||||
Browser:
|
Browser:
|
||||||
|
@ -24,8 +24,14 @@ export class BrowserServerDispatcher extends Dispatcher<BrowserServer, BrowserSe
|
|||||||
super(scope, browserServer, 'BrowserServer', {
|
super(scope, browserServer, 'BrowserServer', {
|
||||||
wsEndpoint: browserServer.wsEndpoint(),
|
wsEndpoint: browserServer.wsEndpoint(),
|
||||||
pid: browserServer.process().pid
|
pid: browserServer.process().pid
|
||||||
|
}, true);
|
||||||
|
browserServer.on(Events.BrowserServer.Close, (exitCode, signal) => {
|
||||||
|
this._dispatchEvent('close', {
|
||||||
|
exitCode: exitCode === null ? undefined : exitCode,
|
||||||
|
signal: signal === null ? undefined : signal,
|
||||||
|
});
|
||||||
|
this._dispose();
|
||||||
});
|
});
|
||||||
browserServer.on(Events.BrowserServer.Close, () => this._dispatchEvent('close'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async close(): Promise<void> {
|
async close(): Promise<void> {
|
||||||
|
@ -327,8 +327,8 @@ describe('launchPersistentContext()', function() {
|
|||||||
const error = await browserType.launchPersistentContext(userDataDir, options).catch(e => e);
|
const error = await browserType.launchPersistentContext(userDataDir, options).catch(e => e);
|
||||||
expect(error.message).toContain('can not specify page');
|
expect(error.message).toContain('can not specify page');
|
||||||
});
|
});
|
||||||
it('should have passed URL when launching with ignoreDefaultArgs: true', async ({browserType, defaultBrowserOptions, server, userDataDir}) => {
|
it.skip(USES_HOOKS)('should have passed URL when launching with ignoreDefaultArgs: true', async ({browserType, defaultBrowserOptions, server, userDataDir, toImpl}) => {
|
||||||
const args = require('..')[browserType.name()]._defaultArgs(defaultBrowserOptions, 'persistent', userDataDir, 0).filter(a => a !== 'about:blank');
|
const args = toImpl(browserType)._defaultArgs(defaultBrowserOptions, 'persistent', userDataDir, 0).filter(a => a !== 'about:blank');
|
||||||
const options = {
|
const options = {
|
||||||
...defaultBrowserOptions,
|
...defaultBrowserOptions,
|
||||||
args: [...args, server.EMPTY_PAGE],
|
args: [...args, server.EMPTY_PAGE],
|
||||||
|
@ -274,10 +274,12 @@ describe('browserType.launchServer', function() {
|
|||||||
});
|
});
|
||||||
it('should fire close event', async ({browserType, defaultBrowserOptions}) => {
|
it('should fire close event', async ({browserType, defaultBrowserOptions}) => {
|
||||||
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
const browserServer = await browserType.launchServer(defaultBrowserOptions);
|
||||||
await Promise.all([
|
const [result] = await Promise.all([
|
||||||
new Promise(f => browserServer.on('close', f)),
|
new Promise(f => browserServer.on('close', (exitCode, signal) => f({ exitCode, signal }))),
|
||||||
browserServer.close(),
|
browserServer.close(),
|
||||||
]);
|
]);
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.signal).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user