Skip to content

Commit 8795d46

Browse files
aslushnikovdgozman
andauthored
cherrypick(release-1.4): do not throw when 'port' option is present (microsoft#3881)
This cherry-picks PR microsoft#3877 References microsoft#3872 Co-authored-by: Dmitry Gozman <[email protected]>
1 parent 64947f1 commit 8795d46

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/client/browserType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
6363

6464
async launch(options: LaunchOptions = {}): Promise<Browser> {
6565
const logger = options.logger;
66-
options = { ...options, logger: undefined };
6766
return this._wrapApiCall('browserType.launch', async () => {
6867
assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
6968
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
@@ -87,8 +86,8 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
8786

8887
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
8988
const logger = options.logger;
90-
options = { ...options, logger: undefined };
9189
return this._wrapApiCall('browserType.launchPersistentContext', async () => {
90+
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
9291
if (options.extraHTTPHeaders)
9392
validateHeaders(options.extraHTTPHeaders);
9493
const persistentOptions: channels.BrowserTypeLaunchPersistentContextParams = {

src/server/browserType.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { Progress, runAbortableTask } from './progress';
2828
import * as types from './types';
2929
import { TimeoutSettings } from '../utils/timeoutSettings';
3030
import { validateHostRequirements } from './validateDependencies';
31-
import { assert, isDebugMode } from '../utils/utils';
31+
import { isDebugMode } from '../utils/utils';
3232

3333
export interface BrowserType {
3434
executablePath(): string;
@@ -72,15 +72,12 @@ export abstract class BrowserTypeBase implements BrowserType {
7272
}
7373

7474
async launch(options: types.LaunchOptions = {}): Promise<Browser> {
75-
assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
76-
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
7775
options = validateLaunchOptions(options);
7876
const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, undefined), TimeoutSettings.timeout(options), 'browser').catch(e => { throw this._rewriteStartupError(e); });
7977
return browser;
8078
}
8179

8280
async launchPersistentContext(userDataDir: string, options: types.LaunchPersistentOptions = {}): Promise<BrowserContext> {
83-
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
8481
options = validateLaunchOptions(options);
8582
const persistent: types.BrowserContextOptions = options;
8683
validateBrowserContextOptions(persistent);

test/browsertype-launch-server.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ describe('lauch server', suite => {
2626
await browserServer.close();
2727
});
2828

29+
it('should work with port', async ({browserType, defaultBrowserOptions, parallelIndex}) => {
30+
const browserServer = await browserType.launchServer({ ...defaultBrowserOptions, port: 8800 + parallelIndex });
31+
expect(browserServer.wsEndpoint()).toContain(String(8800 + parallelIndex));
32+
await browserServer.close();
33+
});
34+
2935
it('should fire "close" event during kill', async ({browserType, defaultBrowserOptions}) => {
3036
const order = [];
3137
const browserServer = await browserType.launchServer(defaultBrowserOptions);

test/browsertype-launch.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,19 @@ it('should throw if userDataDir option is passed', async ({browserType, defaultB
3333
let waitError = null;
3434
const options = Object.assign({}, defaultBrowserOptions, {userDataDir: 'random-path'});
3535
await browserType.launch(options).catch(e => waitError = e);
36-
expect(waitError.message).toContain('launchPersistentContext');
36+
expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
37+
});
38+
39+
it('should throw if port option is passed', async ({browserType, defaultBrowserOptions}) => {
40+
const options = Object.assign({}, defaultBrowserOptions, {port: 1234});
41+
const error = await browserType.launch(options).catch(e => e);
42+
expect(error.message).toContain('Cannot specify a port without launching as a server.');
43+
});
44+
45+
it('should throw if port option is passed for persistent context', async ({browserType, defaultBrowserOptions}) => {
46+
const options = Object.assign({}, defaultBrowserOptions, {port: 1234});
47+
const error = await browserType.launchPersistentContext('foo', options).catch(e => e);
48+
expect(error.message).toContain('Cannot specify a port without launching as a server.');
3749
});
3850

3951
it('should throw if page argument is passed', test => {

0 commit comments

Comments
 (0)