UNPKG

1.19 kBJavaScriptView Raw
1'use strict';
2
3const { requireWithFallback } = require("../commons/requireWithFallback");
4
5const { isCi } = require('./isCiRun');
6const { writeStackTrace } = require('./writeStackTrace');
7const logger = require('../commons/logger').getLogger('process-handler');
8
9function getExitCode(result) {
10 if (result instanceof Error) {
11 return 1;
12 }
13 result = result || {};
14 var failedCount = Object.keys(result).filter(function (testId) {
15 if(result[testId].runnerStatus === 'SKIPPED') {
16 return false;
17 }
18 return result[testId].success !== true;
19 }).length;
20 return failedCount === 0 ? 0 : 1;
21}
22
23function closeChromeDriverIfRunning() {
24 try {
25 const chromedriver = requireWithFallback('chromedriver');
26 chromedriver.stop();
27 } catch (err) { }
28}
29
30
31
32module.exports.onExit = async function onExit(exitValue) {
33
34 if (exitValue && exitValue.stack) {
35 if (!isCi) {
36 writeStackTrace(exitValue);
37 } else {
38 console.error(exitValue, exitValue && exitValue.stack);
39 }
40 }
41
42 closeChromeDriverIfRunning();
43
44 await logger.waitForFlush();
45
46 process.exit(getExitCode(exitValue));
47}