1 | 'use strict';
|
2 |
|
3 | const { requireWithFallback } = require("../commons/requireWithFallback");
|
4 |
|
5 | const { isCi } = require('./isCiRun');
|
6 | const { writeStackTrace } = require('./writeStackTrace');
|
7 | const logger = require('../commons/logger').getLogger('process-handler');
|
8 |
|
9 | function 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 |
|
23 | function closeChromeDriverIfRunning() {
|
24 | try {
|
25 | const chromedriver = requireWithFallback('chromedriver');
|
26 | chromedriver.stop();
|
27 | } catch (err) { }
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 | module.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 | }
|