testWorker.js
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.setup = setup;
exports.worker = worker;
function _exit() {
const data = _interopRequireDefault(require('exit'));
_exit = function () {
return data;
};
return data;
}
function _jestHasteMap() {
const data = _interopRequireDefault(require('jest-haste-map'));
_jestHasteMap = function () {
return data;
};
return data;
}
function _jestMessageUtil() {
const data = require('jest-message-util');
_jestMessageUtil = function () {
return data;
};
return data;
}
function _jestRuntime() {
const data = _interopRequireDefault(require('jest-runtime'));
_jestRuntime = function () {
return data;
};
return data;
}
function _jestWorker() {
const data = require('jest-worker');
_jestWorker = function () {
return data;
};
return data;
}
var _runTest = _interopRequireDefault(require('./runTest'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// Make sure uncaught errors are logged before we exit.
process.on('uncaughtException', err => {
console.error(err.stack);
(0, _exit().default)(1);
});
const formatError = error => {
if (typeof error === 'string') {
const {message, stack} = (0, _jestMessageUtil().separateMessageFromStack)(
error
);
return {
message,
stack,
type: 'Error'
};
}
return {
code: error.code || undefined,
message: error.message,
stack: error.stack,
type: 'Error'
};
};
const resolvers = new Map();
const getResolver = config => {
const resolver = resolvers.get(config.name);
if (!resolver) {
throw new Error('Cannot find resolver for: ' + config.name);
}
return resolver;
};
function setup(setupData) {
// Module maps that will be needed for the test runs are passed.
for (const {
config,
serializableModuleMap
} of setupData.serializableResolvers) {
const moduleMap = _jestHasteMap().default.ModuleMap.fromJSON(
serializableModuleMap
);
resolvers.set(
config.name,
_jestRuntime().default.createResolver(config, moduleMap)
);
}
}
const sendMessageToJest = (eventName, args) => {
(0, _jestWorker().messageParent)([eventName, args]);
};
async function worker({config, globalConfig, path, context}) {
try {
return await (0, _runTest.default)(
path,
globalConfig,
config,
getResolver(config),
context && {
...context,
changedFiles: context.changedFiles && new Set(context.changedFiles),
sourcesRelatedToTestsInChangedFiles:
context.sourcesRelatedToTestsInChangedFiles &&
new Set(context.sourcesRelatedToTestsInChangedFiles)
},
sendMessageToJest
);
} catch (error) {
throw formatError(error);
}
}