fix(connect): respect launch options when turning into connect (#20757)

This commit is contained in:
Dmitry Gozman 2023-02-08 13:06:05 -08:00 committed by GitHub
parent 7a093329fa
commit 6e5964cccd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 13 deletions

View file

@ -72,7 +72,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
if (this._defaultConnectOptions)
return await this._connectInsteadOfLaunching(this._defaultConnectOptions);
return await this._connectInsteadOfLaunching(this._defaultConnectOptions, options);
const logger = options.logger || this._defaultLaunchOptions?.logger;
options = { ...this._defaultLaunchOptions, ...options };
@ -90,11 +90,11 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
});
}
private async _connectInsteadOfLaunching(connectOptions: ConnectOptions): Promise<Browser> {
private async _connectInsteadOfLaunching(connectOptions: ConnectOptions, launchOptions: LaunchOptions): Promise<Browser> {
return this._connect({
wsEndpoint: connectOptions.wsEndpoint,
headers: {
'x-playwright-launch-options': JSON.stringify(this._defaultLaunchOptions || {}),
'x-playwright-launch-options': JSON.stringify({ ...this._defaultLaunchOptions, ...launchOptions }),
...connectOptions.headers,
},
_exposeNetwork: connectOptions._exposeNetwork,

View file

@ -35,9 +35,7 @@ it('should throw if userDataDir option is passed', async ({ browserType }) => {
expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
});
it('should throw if userDataDir is passed as an argument', async ({ mode, browserType }) => {
it.skip(mode === 'service');
it('should throw if userDataDir is passed as an argument', async ({ browserType }) => {
let waitError = null;
await browserType.launch({ args: ['--user-data-dir=random-path', '--profile=random-path'] } as any).catch(e => waitError = e);
expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
@ -53,8 +51,7 @@ it('should throw if port option is passed for persistent context', async ({ brow
expect(error.message).toContain('Cannot specify a port without launching as a server.');
});
it('should throw if page argument is passed', async ({ mode, browserType, browserName }) => {
it.skip(mode === 'service');
it('should throw if page argument is passed', async ({ browserType, browserName }) => {
it.skip(browserName === 'firefox');
let waitError = null;
@ -62,7 +59,7 @@ it('should throw if page argument is passed', async ({ mode, browserType, browse
expect(waitError.message).toContain('can not specify page');
});
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset }) => {
it('should reject if launched browser fails immediately', async ({ mode, browserType, asset }) => {
it.skip(mode === 'service');
let waitError = null;
@ -70,9 +67,7 @@ it('should reject if launched browser fails immediately', async ({ mode, browser
expect(waitError.message).toContain('== logs ==');
});
it('should reject if executable path is invalid', async ({ browserType, mode }) => {
it.skip(mode === 'service');
it('should reject if executable path is invalid', async ({ browserType }) => {
let waitError = null;
await browserType.launch({ executablePath: 'random-invalid-path' }).catch(e => waitError = e);
expect(waitError.message).toContain('Failed to launch');
@ -106,7 +101,9 @@ it('should report launch log', async ({ browserType, mode }) => {
expect(error.message).toContain('<launching>');
});
it('should accept objects as options', async ({ browserType }) => {
it('should accept objects as options', async ({ mode, browserType }) => {
it.skip(mode === 'service');
// @ts-expect-error process is not a real option.
const browser = await browserType.launch({ process });
await browser.close();