Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created February 13, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xotabu4/e357a7cc907d83c6969b9482572728c7 to your computer and use it in GitHub Desktop.
Save Xotabu4/e357a7cc907d83c6969b9482572728c7 to your computer and use it in GitHub Desktop.
Trying to close protractor browser on process exit
import { browser } from 'protractor';
/**
* @experimental
*/
export function registerCloseBrowserOnProcessEndListener() {
async function exitHandler(options, exitCode) {
console.log('[registerCloseBrowserOnProcessEndListener] called!');
try {
await browser.close();
} catch (err) {
console.warn(`[registerCloseBrowserOnProcessEndListener] Cannot close browser for ${process.pid}`);
} finally {
process.exit(exitCode);
}
}
// do something when app is closing
process.on('exit', exitHandler.bind(null, { cleanup: true }));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, { exit: true }));
// catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment