1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const crypto_1 = require("crypto");
|
4 | const fs_1 = require("fs");
|
5 | const path_1 = require("path");
|
6 | function randomId(prefix) {
|
7 | return `${prefix}-${crypto_1.randomBytes(16).toString('hex')}`;
|
8 | }
|
9 | exports.randomId = randomId;
|
10 | function setProcessExitListeners() {
|
11 | process.on('unhandledRejection', (reason) => {
|
12 |
|
13 | console.error(`Unhandled asynchronous exception: ${reason.stack}`);
|
14 | process.exit(1);
|
15 | });
|
16 | process.on('uncaughtException', (err) => {
|
17 |
|
18 | console.error(`Uncaught exception: ${err.stack}`);
|
19 | process.exit(1);
|
20 | });
|
21 | }
|
22 | exports.setProcessExitListeners = setProcessExitListeners;
|
23 | function applyRequires(requires) {
|
24 | const requiresList = Array.isArray(requires) ? requires : [requires];
|
25 | const output = [];
|
26 |
|
27 | const cwd = process.cwd();
|
28 | module.paths.push(cwd, path_1.join(cwd, 'node_modules'));
|
29 | for (const mod of requiresList) {
|
30 | const abs = fs_1.existsSync(mod) || fs_1.existsSync(`${mod}.js`);
|
31 | const requirePath = abs ? path_1.resolve(mod) : mod;
|
32 | require(requirePath);
|
33 | output.push(requirePath);
|
34 | }
|
35 | return output;
|
36 | }
|
37 | exports.applyRequires = applyRequires;
|
38 | function applyCompilers(compilers) {
|
39 | const compilersList = Array.isArray(compilers) ? compilers : [compilers];
|
40 | const output = {
|
41 | compilers: compilersList,
|
42 | extensions: ['js'],
|
43 | };
|
44 |
|
45 | const cwd = process.cwd();
|
46 | module.paths.push(cwd, path_1.join(cwd, 'node_modules'));
|
47 | for (const compiler of compilersList) {
|
48 | const idx = compiler.indexOf(':');
|
49 | const ext = compiler.slice(0, idx);
|
50 | let mod = compiler.slice(idx + 1);
|
51 | if (mod.startsWith('.')) {
|
52 | mod = path_1.join(process.cwd(), mod);
|
53 | }
|
54 | require(mod);
|
55 | output.extensions.push(ext);
|
56 | }
|
57 | return output;
|
58 | }
|
59 | exports.applyCompilers = applyCompilers;
|
60 | function applyDelay(mocha, delay) {
|
61 | if (delay) {
|
62 | mocha.delay();
|
63 | }
|
64 | }
|
65 | exports.applyDelay = applyDelay;
|
66 | function applyGrepPattern(mocha, stringPattern) {
|
67 | if (stringPattern) {
|
68 | mocha.grep(stringPattern);
|
69 | }
|
70 | }
|
71 | exports.applyGrepPattern = applyGrepPattern;
|
72 | function applyNoTimeouts(mocha, allowTimeouts) {
|
73 | if (allowTimeouts === false) {
|
74 | mocha.enableTimeouts(false);
|
75 | }
|
76 | }
|
77 | exports.applyNoTimeouts = applyNoTimeouts;
|
78 | function applyTimeouts(mocha, timeout) {
|
79 | if (timeout) {
|
80 | mocha.suite.timeout(timeout);
|
81 | }
|
82 | }
|
83 | exports.applyTimeouts = applyTimeouts;
|
84 |
|
\ | No newline at end of file |