UNPKG

testplane

Version:

Tests framework based on mocha and wdio

36 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const events_1 = require("./events"); const logger_1 = require("./utils/logger"); const events_2 = require("./events"); const signalHandler = new events_1.AsyncEmitter(); signalHandler.setMaxListeners(0); let callCount = 0; let lastCallTime = 0; const throttleTime = 10; function notifyAndExit(signalNo) { const exitCode = 128 + signalNo; return function (signal) { const time = Date.now(); if (time - lastCallTime < throttleTime) { lastCallTime = time; return; } lastCallTime = time; if (callCount++ > 0) { (0, logger_1.log)("Force quit."); process.exit(exitCode); } const err = new Error(`The process was terminated by a signal: ${signal}`); signalHandler.emitAndWait(events_2.MasterEvents.EXIT, err).then(() => { signalHandler.emitAndWait(events_2.MasterEvents.RUNNER_END, err).then(() => { process.exit(exitCode); }); }); }; } process.on("SIGHUP", notifyAndExit(1)); process.on("SIGINT", notifyAndExit(2)); process.on("SIGTERM", notifyAndExit(15)); exports.default = signalHandler; //# sourceMappingURL=signal-handler.js.map