playwright/test/fixtures/closeme.js
Dmitry Gozman e9060dd68a
fix(launchServer): wait for the server to start before taking its address (#4513)
This is easily triggered by launching from a cluster's worker.
2020-11-23 15:23:31 -08:00

31 lines
938 B
JavaScript

const cluster = require('cluster');
async function start() {
const { playwrightPath, browserTypeName, launchOptions, stallOnClose } = JSON.parse(process.argv[2]);
if (stallOnClose) {
launchOptions.__testHookGracefullyClose = () => {
console.log(`(stalled=>true)`);
return new Promise(() => {});
};
}
const playwright = require(require('path').join(playwrightPath, 'index'));
const browserServer = await playwright[browserTypeName].launchServer(launchOptions);
browserServer.on('close', (exitCode, signal) => {
console.log(`(exitCode=>${exitCode})`);
console.log(`(signal=>${signal})`);
});
console.log(`(pid=>${browserServer.process().pid})`);
console.log(`(wsEndpoint=>${browserServer.wsEndpoint()})`);
}
if (cluster.isWorker || !JSON.parse(process.argv[2]).inCluster) {
start();
} else {
cluster.fork();
cluster.on('exit', (worker, code, signal) => {
process.exit(0);
});
}