2020-08-05 01:57:25 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-09-27 02:05:58 +03:00
|
|
|
import { it, expect, describe } from './fixtures';
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-09-27 02:05:58 +03:00
|
|
|
describe('lauch server', (suite, { wire }) => {
|
|
|
|
suite.skip(wire);
|
2020-08-29 01:45:09 +03:00
|
|
|
}, () => {
|
2020-10-13 23:18:36 +03:00
|
|
|
it('should work', async ({browserType, browserOptions}) => {
|
|
|
|
const browserServer = await browserType.launchServer(browserOptions);
|
2020-08-28 23:53:47 +03:00
|
|
|
expect(browserServer.wsEndpoint()).not.toBe(null);
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-10-13 23:18:36 +03:00
|
|
|
it('should work with port', async ({browserType, browserOptions, testWorkerIndex}) => {
|
|
|
|
const browserServer = await browserType.launchServer({ ...browserOptions, port: 8800 + testWorkerIndex });
|
2020-09-24 00:52:06 +03:00
|
|
|
expect(browserServer.wsEndpoint()).toContain(String(8800 + testWorkerIndex));
|
2020-09-15 00:43:39 +03:00
|
|
|
await browserServer.close();
|
|
|
|
});
|
|
|
|
|
2020-10-13 23:18:36 +03:00
|
|
|
it('should fire "close" event during kill', async ({browserType, browserOptions}) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
const order = [];
|
2020-10-13 23:18:36 +03:00
|
|
|
const browserServer = await browserType.launchServer(browserOptions);
|
2020-08-28 23:53:47 +03:00
|
|
|
const closedPromise = new Promise(f => browserServer.on('close', () => {
|
|
|
|
order.push('closed');
|
|
|
|
f();
|
|
|
|
}));
|
|
|
|
await Promise.all([
|
|
|
|
browserServer.kill().then(() => order.push('killed')),
|
|
|
|
closedPromise,
|
|
|
|
]);
|
|
|
|
expect(order).toEqual(['closed', 'killed']);
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-10-13 23:18:36 +03:00
|
|
|
it('should return child_process instance', async ({browserType, browserOptions}) => {
|
|
|
|
const browserServer = await browserType.launchServer(browserOptions);
|
2020-08-28 23:53:47 +03:00
|
|
|
expect(browserServer.process().pid).toBeGreaterThan(0);
|
|
|
|
await browserServer.close();
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
|
2020-10-13 23:18:36 +03:00
|
|
|
it('should fire close event', async ({browserType, browserOptions}) => {
|
|
|
|
const browserServer = await browserType.launchServer(browserOptions);
|
2020-08-28 23:53:47 +03:00
|
|
|
const [result] = await Promise.all([
|
2020-09-09 13:06:52 +03:00
|
|
|
// @ts-expect-error The signal parameter is not documented.
|
|
|
|
new Promise(f => browserServer.on('close', (exitCode, signal) => f({ exitCode, signal }))),
|
2020-08-28 23:53:47 +03:00
|
|
|
browserServer.close(),
|
|
|
|
]);
|
|
|
|
expect(result['exitCode']).toBe(0);
|
|
|
|
expect(result['signal']).toBe(null);
|
|
|
|
});
|
2020-08-05 01:57:25 +03:00
|
|
|
});
|