Do not rely on console.log for exiting tests

This commit is contained in:
Alexandru Dima
2021-06-09 21:47:18 +02:00
parent 043b9fbeb6
commit b1bc7be9d1
3 changed files with 21 additions and 22 deletions

View File

@@ -54,23 +54,20 @@ async function runTestsInBrowser(browserType: BrowserType, endpoint: url.UrlWith
console[type](...args);
});
page.on('console', async (msg: playwright.ConsoleMessage) => {
const msgText = msg.text();
if (msgText.indexOf('vscode:exit') >= 0) {
try {
await browser.close();
} catch (error) {
console.error(`Error when closing browser: ${error}`);
}
try {
await pkill(server.pid);
} catch (error) {
console.error(`Error when killing server process tree: ${error}`);
}
process.exit(msgText === 'vscode:exit 0' ? 0 : 1);
await page.exposeFunction('codeAutomationExit', async (code: number) => {
try {
await browser.close();
} catch (error) {
console.error(`Error when closing browser: ${error}`);
}
try {
await pkill(server.pid);
} catch (error) {
console.error(`Error when killing server process tree: ${error}`);
}
process.exit(code);
});
}