UNPKG

suitest-js-api

Version:

Suitest is a test automation and device manipulation tool for living room devices and web browsers.

53 lines (40 loc) 1.11 kB
#!/usr/bin/env node /* istanbul ignore file */ const {killChildProcesses} = require('./processReaper'); const {buildYargs, addCommandsAndHelp} = require('./buildArgs'); const suitest = require('../../index'); const {getOwnArgs} = require('./processArgs'); const yargs = buildYargs(); const ownArgs = getOwnArgs(); addCommandsAndHelp(yargs); yargs.config({}).parse(ownArgs); const killChildrenAndDie = error => { // Gracefully terminate websocket connection, if any suitest.webSockets.disconnect(); // Kill all children processes killChildProcesses(); if (error instanceof Error) { // Dump error to console and exit with error code console.error(error); process.exit(1); } else { // Do not update exit code process.exit(); } }; [ // When event loop ends or process.exit() called 'exit', // Ctrl+C in terminal 'SIGINT', 'SIGQUIT', // Ctrl+/ in terminal 'SIGTERM', // Console is closed on Windows 'SIGHUP', // Ctrl+Break on Windows 'SIGBREAK', // Unhandled exception 'uncaughtException', 'unhandledRejection', ].forEach(term => process.once(term, killChildrenAndDie));