2022-04-12 22:28:33 +03:00
|
|
|
const fs = require('fs');
|
2020-11-24 02:23:31 +03:00
|
|
|
const cluster = require('cluster');
|
|
|
|
|
|
|
|
async function start() {
|
2022-04-12 22:28:33 +03:00
|
|
|
const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP, exitOnFile } = JSON.parse(process.argv[2]);
|
2020-05-21 00:58:27 +03:00
|
|
|
if (stallOnClose) {
|
|
|
|
launchOptions.__testHookGracefullyClose = () => {
|
|
|
|
console.log(`(stalled=>true)`);
|
2021-10-11 17:52:17 +03:00
|
|
|
return new Promise(() => { });
|
2020-05-21 00:58:27 +03:00
|
|
|
};
|
|
|
|
}
|
2020-07-28 04:40:21 +03:00
|
|
|
|
2021-10-11 17:52:17 +03:00
|
|
|
const playwright = require('playwright-core');
|
2020-07-28 04:40:21 +03:00
|
|
|
|
2021-05-06 19:34:06 +03:00
|
|
|
if (disconnectOnSIGHUP)
|
|
|
|
launchOptions.handleSIGHUP = false;
|
2020-07-30 20:22:28 +03:00
|
|
|
const browserServer = await playwright[browserTypeName].launchServer(launchOptions);
|
2021-05-06 19:34:06 +03:00
|
|
|
if (disconnectOnSIGHUP)
|
|
|
|
process.on('SIGHUP', () => browserServer._disconnectForTest());
|
|
|
|
|
2022-04-12 22:28:33 +03:00
|
|
|
if (exitOnFile) {
|
|
|
|
(async function waitForFileAndExit() {
|
|
|
|
while (true) {
|
|
|
|
if (fs.existsSync(exitOnFile))
|
|
|
|
break;
|
|
|
|
await new Promise(f => setTimeout(f, 100));
|
|
|
|
}
|
|
|
|
process.exit(42);
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2020-02-05 23:41:55 +03:00
|
|
|
browserServer.on('close', (exitCode, signal) => {
|
2020-05-21 00:58:27 +03:00
|
|
|
console.log(`(exitCode=>${exitCode})`);
|
|
|
|
console.log(`(signal=>${signal})`);
|
2020-01-29 00:07:53 +03:00
|
|
|
});
|
2022-04-26 11:32:58 +03:00
|
|
|
console.log(`(tempDir=>${browserServer._userDataDirForTest})`);
|
2020-05-21 00:58:27 +03:00
|
|
|
console.log(`(pid=>${browserServer.process().pid})`);
|
|
|
|
console.log(`(wsEndpoint=>${browserServer.wsEndpoint()})`);
|
2020-11-24 02:23:31 +03:00
|
|
|
}
|
|
|
|
|
2021-05-06 19:34:06 +03:00
|
|
|
process.on('uncaughtException', error => console.log(error));
|
|
|
|
process.on('unhandledRejection', reason => console.log(reason));
|
|
|
|
|
2020-11-24 02:23:31 +03:00
|
|
|
if (cluster.isWorker || !JSON.parse(process.argv[2]).inCluster) {
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
cluster.fork();
|
|
|
|
cluster.on('exit', (worker, code, signal) => {
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
}
|