1 | import treeKill from 'tree-kill';
|
2 | import { StrykerError } from '@stryker-mutator/util';
|
3 | export const objectUtils = {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | map(subject, callbackFn) {
|
12 | const results = [];
|
13 | subject.forEach((value, key) => results.push(callbackFn(value, key)));
|
14 | return results;
|
15 | },
|
16 | |
17 |
|
18 |
|
19 | getEnvironmentVariable(nameEnvironmentVariable) {
|
20 | return process.env[nameEnvironmentVariable];
|
21 | },
|
22 | undefinedEmptyString(str) {
|
23 | if (str) {
|
24 | return str;
|
25 | }
|
26 | return undefined;
|
27 | },
|
28 | getEnvironmentVariableOrThrow(name) {
|
29 | const value = this.getEnvironmentVariable(name);
|
30 | if (value === undefined) {
|
31 | throw new StrykerError(`Missing environment variable "${name}"`);
|
32 | }
|
33 | else {
|
34 | return value;
|
35 | }
|
36 | },
|
37 | isWarningEnabled(warningType, warningOptions) {
|
38 | if (typeof warningOptions === 'boolean') {
|
39 | return warningOptions;
|
40 | }
|
41 | else {
|
42 | return !!warningOptions[warningType];
|
43 | }
|
44 | },
|
45 | |
46 |
|
47 |
|
48 | setExitCode(n) {
|
49 | process.exitCode = n;
|
50 | },
|
51 | kill(pid) {
|
52 | return new Promise((res, rej) => {
|
53 | treeKill(pid, 'SIGKILL', (err) => {
|
54 | if (err && !canIgnore(err.code)) {
|
55 | rej(err);
|
56 | }
|
57 | else {
|
58 | res();
|
59 | }
|
60 | });
|
61 | function canIgnore(code) {
|
62 |
|
63 |
|
64 | return code === 255 || code === 128;
|
65 | }
|
66 | });
|
67 | },
|
68 | |
69 |
|
70 |
|
71 |
|
72 | random() {
|
73 | return Math.ceil(Math.random() * 10000000);
|
74 | },
|
75 | };
|
76 |
|
\ | No newline at end of file |