1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function util() {
|
9 | const data = _interopRequireWildcard(require('util'));
|
10 |
|
11 | util = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _pEachSeries() {
|
19 | const data = _interopRequireDefault(require('p-each-series'));
|
20 |
|
21 | _pEachSeries = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _transform() {
|
29 | const data = require('@jest/transform');
|
30 |
|
31 | _transform = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _prettyFormat() {
|
39 | const data = _interopRequireDefault(require('pretty-format'));
|
40 |
|
41 | _prettyFormat = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | function _interopRequireDefault(obj) {
|
49 | return obj && obj.__esModule ? obj : {default: obj};
|
50 | }
|
51 |
|
52 | function _getRequireWildcardCache(nodeInterop) {
|
53 | if (typeof WeakMap !== 'function') return null;
|
54 | var cacheBabelInterop = new WeakMap();
|
55 | var cacheNodeInterop = new WeakMap();
|
56 | return (_getRequireWildcardCache = function (nodeInterop) {
|
57 | return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
58 | })(nodeInterop);
|
59 | }
|
60 |
|
61 | function _interopRequireWildcard(obj, nodeInterop) {
|
62 | if (!nodeInterop && obj && obj.__esModule) {
|
63 | return obj;
|
64 | }
|
65 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
66 | return {default: obj};
|
67 | }
|
68 | var cache = _getRequireWildcardCache(nodeInterop);
|
69 | if (cache && cache.has(obj)) {
|
70 | return cache.get(obj);
|
71 | }
|
72 | var newObj = {};
|
73 | var hasPropertyDescriptor =
|
74 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
75 | for (var key in obj) {
|
76 | if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
77 | var desc = hasPropertyDescriptor
|
78 | ? Object.getOwnPropertyDescriptor(obj, key)
|
79 | : null;
|
80 | if (desc && (desc.get || desc.set)) {
|
81 | Object.defineProperty(newObj, key, desc);
|
82 | } else {
|
83 | newObj[key] = obj[key];
|
84 | }
|
85 | }
|
86 | }
|
87 | newObj.default = obj;
|
88 | if (cache) {
|
89 | cache.set(obj, newObj);
|
90 | }
|
91 | return newObj;
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | var _default = async ({allTests, globalConfig, moduleName}) => {
|
101 | const globalModulePaths = new Set(
|
102 | allTests.map(test => test.context.config[moduleName])
|
103 | );
|
104 |
|
105 | if (globalConfig[moduleName]) {
|
106 | globalModulePaths.add(globalConfig[moduleName]);
|
107 | }
|
108 |
|
109 | if (globalModulePaths.size > 0) {
|
110 | await (0, _pEachSeries().default)(globalModulePaths, async modulePath => {
|
111 | if (!modulePath) {
|
112 | return;
|
113 | }
|
114 |
|
115 | const correctConfig = allTests.find(
|
116 | t => t.context.config[moduleName] === modulePath
|
117 | );
|
118 | const projectConfig = correctConfig
|
119 | ? correctConfig.context.config
|
120 | : allTests[0].context.config;
|
121 | const transformer = await (0, _transform().createScriptTransformer)(
|
122 | projectConfig
|
123 | );
|
124 |
|
125 | try {
|
126 | await transformer.requireAndTranspileModule(
|
127 | modulePath,
|
128 | async globalModule => {
|
129 | if (typeof globalModule !== 'function') {
|
130 | throw new TypeError(
|
131 | `${moduleName} file must export a function at ${modulePath}`
|
132 | );
|
133 | }
|
134 |
|
135 | await globalModule(globalConfig);
|
136 | }
|
137 | );
|
138 | } catch (error) {
|
139 | if (util().types.isNativeError(error)) {
|
140 | error.message = `Jest: Got error running ${moduleName} - ${modulePath}, reason: ${error.message}`;
|
141 | throw error;
|
142 | }
|
143 |
|
144 | throw new Error(
|
145 | `Jest: Got error running ${moduleName} - ${modulePath}, reason: ${(0,
|
146 | _prettyFormat().default)(error, {
|
147 | maxDepth: 3
|
148 | })}`
|
149 | );
|
150 | }
|
151 | });
|
152 | }
|
153 |
|
154 | return Promise.resolve();
|
155 | };
|
156 |
|
157 | exports.default = _default;
|