@lvce-editor/test-with-playwright-worker 22.24.0 → 22.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coverageWorkerMain.js +930 -0
- package/dist/workerMain.js +238 -89
- package/package.json +2 -11
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
import IstanbulReport from 'istanbul-lib-report';
|
|
2
|
+
import IstanbulReports from 'istanbul-reports';
|
|
3
|
+
import { rm, mkdir, readFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import IstanbulCoverage from 'istanbul-lib-coverage';
|
|
6
|
+
import v8ToIstanbul from 'v8-to-istanbul';
|
|
7
|
+
|
|
8
|
+
const normalizeLine = line => {
|
|
9
|
+
if (line.startsWith('Error: ')) {
|
|
10
|
+
return line.slice('Error: '.length);
|
|
11
|
+
}
|
|
12
|
+
if (line.startsWith('VError: ')) {
|
|
13
|
+
return line.slice('VError: '.length);
|
|
14
|
+
}
|
|
15
|
+
return line;
|
|
16
|
+
};
|
|
17
|
+
const getCombinedMessage = (error, message) => {
|
|
18
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
19
|
+
if (message) {
|
|
20
|
+
return `${message}: ${stringifiedError}`;
|
|
21
|
+
}
|
|
22
|
+
return stringifiedError;
|
|
23
|
+
};
|
|
24
|
+
const NewLine$2 = '\n';
|
|
25
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
26
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
27
|
+
};
|
|
28
|
+
const mergeStacks = (parent, child) => {
|
|
29
|
+
if (!child) {
|
|
30
|
+
return parent;
|
|
31
|
+
}
|
|
32
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
33
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
34
|
+
if (childNewLineIndex === -1) {
|
|
35
|
+
return parent;
|
|
36
|
+
}
|
|
37
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
38
|
+
const childRest = child.slice(childNewLineIndex);
|
|
39
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
40
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
41
|
+
return parentFirstLine + childRest;
|
|
42
|
+
}
|
|
43
|
+
return child;
|
|
44
|
+
};
|
|
45
|
+
class VError extends Error {
|
|
46
|
+
constructor(error, message) {
|
|
47
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
48
|
+
super(combinedMessage);
|
|
49
|
+
this.name = 'VError';
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
52
|
+
}
|
|
53
|
+
if (error.codeFrame) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
this.codeFrame = error.codeFrame;
|
|
56
|
+
}
|
|
57
|
+
if (error.code) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
this.code = error.code;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isMessagePort = value => {
|
|
65
|
+
return value && value instanceof MessagePort;
|
|
66
|
+
};
|
|
67
|
+
const isMessagePortMain = value => {
|
|
68
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
69
|
+
};
|
|
70
|
+
const isOffscreenCanvas = value => {
|
|
71
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
72
|
+
};
|
|
73
|
+
const isInstanceOf = (value, constructorName) => {
|
|
74
|
+
return value?.constructor?.name === constructorName;
|
|
75
|
+
};
|
|
76
|
+
const isSocket = value => {
|
|
77
|
+
return isInstanceOf(value, 'Socket');
|
|
78
|
+
};
|
|
79
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
80
|
+
const isTransferrable = value => {
|
|
81
|
+
for (const fn of transferrables) {
|
|
82
|
+
if (fn(value)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
};
|
|
88
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
89
|
+
if (!value) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (isTransferrable(value)) {
|
|
93
|
+
transferrables.push(value);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
for (const item of value) {
|
|
98
|
+
walkValue(item, transferrables, isTransferrable);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (typeof value === 'object') {
|
|
103
|
+
for (const property of Object.values(value)) {
|
|
104
|
+
walkValue(property, transferrables, isTransferrable);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const getTransferrables = value => {
|
|
109
|
+
const transferrables = [];
|
|
110
|
+
walkValue(value, transferrables, isTransferrable);
|
|
111
|
+
return transferrables;
|
|
112
|
+
};
|
|
113
|
+
const attachEvents = that => {
|
|
114
|
+
const handleMessage = (...args) => {
|
|
115
|
+
const data = that.getData(...args);
|
|
116
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
117
|
+
data
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
that.onMessage(handleMessage);
|
|
121
|
+
const handleClose = event => {
|
|
122
|
+
that.dispatchEvent(new Event('close'));
|
|
123
|
+
};
|
|
124
|
+
that.onClose(handleClose);
|
|
125
|
+
};
|
|
126
|
+
class Ipc extends EventTarget {
|
|
127
|
+
constructor(rawIpc) {
|
|
128
|
+
super();
|
|
129
|
+
this._rawIpc = rawIpc;
|
|
130
|
+
attachEvents(this);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
134
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
135
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
136
|
+
const NewLine$1 = '\n';
|
|
137
|
+
const joinLines$1 = lines => {
|
|
138
|
+
return lines.join(NewLine$1);
|
|
139
|
+
};
|
|
140
|
+
const RE_AT = /^\s+at/;
|
|
141
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
142
|
+
const isNormalStackLine = line => {
|
|
143
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
144
|
+
};
|
|
145
|
+
const getDetails = lines => {
|
|
146
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
147
|
+
if (index === -1) {
|
|
148
|
+
return {
|
|
149
|
+
actualMessage: joinLines$1(lines),
|
|
150
|
+
rest: []
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
let lastIndex = index - 1;
|
|
154
|
+
while (++lastIndex < lines.length) {
|
|
155
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
actualMessage: lines[index - 1],
|
|
161
|
+
rest: lines.slice(index, lastIndex)
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const splitLines$1 = lines => {
|
|
165
|
+
return lines.split(NewLine$1);
|
|
166
|
+
};
|
|
167
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
168
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
169
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
170
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
171
|
+
};
|
|
172
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
173
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
174
|
+
};
|
|
175
|
+
const getMessageCodeBlock = stderr => {
|
|
176
|
+
const lines = splitLines$1(stderr);
|
|
177
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
178
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
179
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
180
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
181
|
+
return relevantMessage;
|
|
182
|
+
};
|
|
183
|
+
const isModuleNotFoundMessage = line => {
|
|
184
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
185
|
+
};
|
|
186
|
+
const getModuleNotFoundError = stderr => {
|
|
187
|
+
const lines = splitLines$1(stderr);
|
|
188
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
189
|
+
const message = lines[messageIndex];
|
|
190
|
+
return {
|
|
191
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
192
|
+
message
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const isModuleNotFoundError = stderr => {
|
|
196
|
+
if (!stderr) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
200
|
+
};
|
|
201
|
+
const isModulesSyntaxError = stderr => {
|
|
202
|
+
if (!stderr) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
206
|
+
};
|
|
207
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
208
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
209
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
210
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
211
|
+
};
|
|
212
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
213
|
+
const message = getMessageCodeBlock(stderr);
|
|
214
|
+
return {
|
|
215
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
216
|
+
message: `Incompatible native node module: ${message}`
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const getModuleSyntaxError = () => {
|
|
220
|
+
return {
|
|
221
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
222
|
+
message: `ES Modules are not supported in electron`
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
226
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
227
|
+
return getNativeModuleErrorMessage(stderr);
|
|
228
|
+
}
|
|
229
|
+
if (isModulesSyntaxError(stderr)) {
|
|
230
|
+
return getModuleSyntaxError();
|
|
231
|
+
}
|
|
232
|
+
if (isModuleNotFoundError(stderr)) {
|
|
233
|
+
return getModuleNotFoundError(stderr);
|
|
234
|
+
}
|
|
235
|
+
const lines = splitLines$1(stderr);
|
|
236
|
+
const {
|
|
237
|
+
actualMessage,
|
|
238
|
+
rest
|
|
239
|
+
} = getDetails(lines);
|
|
240
|
+
return {
|
|
241
|
+
code: '',
|
|
242
|
+
message: actualMessage,
|
|
243
|
+
stack: rest
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
class IpcError extends VError {
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
249
|
+
if (stdout || stderr) {
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
const {
|
|
252
|
+
code,
|
|
253
|
+
message,
|
|
254
|
+
stack
|
|
255
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
256
|
+
const cause = new Error(message);
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
cause.code = code;
|
|
259
|
+
if (stack) {
|
|
260
|
+
Object.defineProperty(cause, 'stack', {
|
|
261
|
+
configurable: true,
|
|
262
|
+
enumerable: false,
|
|
263
|
+
value: stack,
|
|
264
|
+
writable: true
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
super(cause, betterMessage);
|
|
268
|
+
} else {
|
|
269
|
+
super(betterMessage);
|
|
270
|
+
}
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
this.name = 'IpcError';
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
this.stdout = stdout;
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
this.stderr = stderr;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const readyMessage = 'ready';
|
|
280
|
+
const getTransferrablesNode = value => {
|
|
281
|
+
const transferrables = getTransferrables(value);
|
|
282
|
+
if (transferrables.length === 0) {
|
|
283
|
+
throw new Error(`no transferrables found`);
|
|
284
|
+
}
|
|
285
|
+
return transferrables[0];
|
|
286
|
+
};
|
|
287
|
+
const listen$3 = async () => {
|
|
288
|
+
const {
|
|
289
|
+
parentPort
|
|
290
|
+
} = await import('node:worker_threads');
|
|
291
|
+
if (!parentPort) {
|
|
292
|
+
throw new IpcError('parentPort is required for node worker threads ipc');
|
|
293
|
+
}
|
|
294
|
+
return parentPort;
|
|
295
|
+
};
|
|
296
|
+
const signal$5 = parentPort => {
|
|
297
|
+
parentPort.postMessage(readyMessage);
|
|
298
|
+
};
|
|
299
|
+
class IpcChildWithNodeWorker extends Ipc {
|
|
300
|
+
getData(data) {
|
|
301
|
+
return data;
|
|
302
|
+
}
|
|
303
|
+
onClose(callback) {
|
|
304
|
+
this._rawIpc.on('close', callback);
|
|
305
|
+
}
|
|
306
|
+
send(message) {
|
|
307
|
+
this._rawIpc.postMessage(message);
|
|
308
|
+
}
|
|
309
|
+
onMessage(callback) {
|
|
310
|
+
this._rawIpc.on('message', callback);
|
|
311
|
+
}
|
|
312
|
+
sendAndTransfer(message) {
|
|
313
|
+
const transfer = getTransferrablesNode(message);
|
|
314
|
+
this._rawIpc.postMessage(message, transfer);
|
|
315
|
+
}
|
|
316
|
+
dispose() {
|
|
317
|
+
this._rawIpc.close();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const wrap$b = parentPort => {
|
|
321
|
+
return new IpcChildWithNodeWorker(parentPort);
|
|
322
|
+
};
|
|
323
|
+
const IpcChildWithNodeWorker$1 = {
|
|
324
|
+
__proto__: null,
|
|
325
|
+
listen: listen$3,
|
|
326
|
+
signal: signal$5,
|
|
327
|
+
wrap: wrap$b
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
class CommandNotFoundError extends Error {
|
|
331
|
+
constructor(command) {
|
|
332
|
+
super(`Command not found ${command}`);
|
|
333
|
+
this.name = 'CommandNotFoundError';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const commands = Object.create(null);
|
|
337
|
+
const register = commandMap => {
|
|
338
|
+
Object.assign(commands, commandMap);
|
|
339
|
+
};
|
|
340
|
+
const getCommand = key => {
|
|
341
|
+
return commands[key];
|
|
342
|
+
};
|
|
343
|
+
const execute = (command, ...args) => {
|
|
344
|
+
const fn = getCommand(command);
|
|
345
|
+
if (!fn) {
|
|
346
|
+
throw new CommandNotFoundError(command);
|
|
347
|
+
}
|
|
348
|
+
return fn(...args);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const Two$1 = '2.0';
|
|
352
|
+
const callbacks = Object.create(null);
|
|
353
|
+
const get = id => {
|
|
354
|
+
return callbacks[id];
|
|
355
|
+
};
|
|
356
|
+
const remove = id => {
|
|
357
|
+
delete callbacks[id];
|
|
358
|
+
};
|
|
359
|
+
class JsonRpcError extends Error {
|
|
360
|
+
constructor(message) {
|
|
361
|
+
super(message);
|
|
362
|
+
this.name = 'JsonRpcError';
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const NewLine = '\n';
|
|
366
|
+
const DomException = 'DOMException';
|
|
367
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
368
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
369
|
+
const TypeError$1 = 'TypeError';
|
|
370
|
+
const getErrorConstructor = (message, type) => {
|
|
371
|
+
if (type) {
|
|
372
|
+
switch (type) {
|
|
373
|
+
case DomException:
|
|
374
|
+
return DOMException;
|
|
375
|
+
case ReferenceError$1:
|
|
376
|
+
return ReferenceError;
|
|
377
|
+
case SyntaxError$1:
|
|
378
|
+
return SyntaxError;
|
|
379
|
+
case TypeError$1:
|
|
380
|
+
return TypeError;
|
|
381
|
+
default:
|
|
382
|
+
return Error;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (message.startsWith('TypeError: ')) {
|
|
386
|
+
return TypeError;
|
|
387
|
+
}
|
|
388
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
389
|
+
return SyntaxError;
|
|
390
|
+
}
|
|
391
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
392
|
+
return ReferenceError;
|
|
393
|
+
}
|
|
394
|
+
return Error;
|
|
395
|
+
};
|
|
396
|
+
const constructError = (message, type, name) => {
|
|
397
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
398
|
+
if (ErrorConstructor === DOMException && name) {
|
|
399
|
+
return new ErrorConstructor(message, name);
|
|
400
|
+
}
|
|
401
|
+
if (ErrorConstructor === Error) {
|
|
402
|
+
const error = new Error(message);
|
|
403
|
+
if (name && name !== 'VError') {
|
|
404
|
+
Object.defineProperty(error, 'name', {
|
|
405
|
+
configurable: true,
|
|
406
|
+
value: name
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return error;
|
|
410
|
+
}
|
|
411
|
+
return new ErrorConstructor(message);
|
|
412
|
+
};
|
|
413
|
+
const joinLines = lines => {
|
|
414
|
+
return lines.join(NewLine);
|
|
415
|
+
};
|
|
416
|
+
const splitLines = lines => {
|
|
417
|
+
return lines.split(NewLine);
|
|
418
|
+
};
|
|
419
|
+
const getCurrentStack = () => {
|
|
420
|
+
const stackLinesToSkip = 3;
|
|
421
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
422
|
+
return currentStack;
|
|
423
|
+
};
|
|
424
|
+
const getNewLineIndex = (string, startIndex) => {
|
|
425
|
+
{
|
|
426
|
+
return string.indexOf(NewLine);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
const getParentStack = error => {
|
|
430
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
431
|
+
if (parentStack.startsWith(' at')) {
|
|
432
|
+
parentStack = error.message + NewLine + parentStack;
|
|
433
|
+
}
|
|
434
|
+
return parentStack;
|
|
435
|
+
};
|
|
436
|
+
const MethodNotFound = -32601;
|
|
437
|
+
const Custom = -32001;
|
|
438
|
+
const setStack = (error, stack) => {
|
|
439
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
440
|
+
if (descriptor) {
|
|
441
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
445
|
+
error.stack = stack;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
Object.defineProperty(error, 'stack', {
|
|
450
|
+
configurable: true,
|
|
451
|
+
value: stack,
|
|
452
|
+
writable: true
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
const restoreExistingError = (error, currentStack) => {
|
|
456
|
+
if (typeof error.stack === 'string') {
|
|
457
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
458
|
+
}
|
|
459
|
+
return error;
|
|
460
|
+
};
|
|
461
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
462
|
+
const restoredError = new JsonRpcError(error.message);
|
|
463
|
+
const parentStack = getParentStack(error);
|
|
464
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
465
|
+
return restoredError;
|
|
466
|
+
};
|
|
467
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
468
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
469
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (error.data.stack) {
|
|
473
|
+
setStack(restoredError, error.data.stack);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const applyDataProperties = (restoredError, error) => {
|
|
477
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
478
|
+
if (error.data.codeFrame) {
|
|
479
|
+
// @ts-ignore
|
|
480
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
481
|
+
}
|
|
482
|
+
if (error.data.code) {
|
|
483
|
+
// @ts-ignore
|
|
484
|
+
restoredError.code = error.data.code;
|
|
485
|
+
}
|
|
486
|
+
if (error.data.type) {
|
|
487
|
+
// @ts-ignore
|
|
488
|
+
restoredError.name = error.data.type;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
492
|
+
if (error.stack) {
|
|
493
|
+
const lowerStack = restoredError.stack || '';
|
|
494
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
495
|
+
const parentStack = getParentStack(error);
|
|
496
|
+
// @ts-ignore
|
|
497
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
498
|
+
}
|
|
499
|
+
if (error.codeFrame) {
|
|
500
|
+
// @ts-ignore
|
|
501
|
+
restoredError.codeFrame = error.codeFrame;
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
505
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
506
|
+
if (error.data) {
|
|
507
|
+
applyDataProperties(restoredError, error);
|
|
508
|
+
} else {
|
|
509
|
+
applyDirectProperties(restoredError, error);
|
|
510
|
+
}
|
|
511
|
+
return restoredError;
|
|
512
|
+
};
|
|
513
|
+
const restoreJsonRpcError = error => {
|
|
514
|
+
const currentStack = getCurrentStack();
|
|
515
|
+
if (error && error instanceof Error) {
|
|
516
|
+
return restoreExistingError(error, currentStack);
|
|
517
|
+
}
|
|
518
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
519
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
520
|
+
}
|
|
521
|
+
if (error && error.message) {
|
|
522
|
+
return restoreMessageError(error);
|
|
523
|
+
}
|
|
524
|
+
if (typeof error === 'string') {
|
|
525
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
526
|
+
}
|
|
527
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
528
|
+
};
|
|
529
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
530
|
+
if ('error' in responseMessage) {
|
|
531
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
532
|
+
throw restoredError;
|
|
533
|
+
}
|
|
534
|
+
if ('result' in responseMessage) {
|
|
535
|
+
return responseMessage.result;
|
|
536
|
+
}
|
|
537
|
+
throw new JsonRpcError('unexpected response message');
|
|
538
|
+
};
|
|
539
|
+
const warn = (...args) => {
|
|
540
|
+
console.warn(...args);
|
|
541
|
+
};
|
|
542
|
+
const resolve = (id, response) => {
|
|
543
|
+
const fn = get(id);
|
|
544
|
+
if (!fn) {
|
|
545
|
+
console.log(response);
|
|
546
|
+
warn(`callback ${id} may already be disposed`);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
fn(response);
|
|
550
|
+
remove(id);
|
|
551
|
+
};
|
|
552
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
553
|
+
const getErrorType = prettyError => {
|
|
554
|
+
if (prettyError && prettyError.type) {
|
|
555
|
+
return prettyError.type;
|
|
556
|
+
}
|
|
557
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
558
|
+
return prettyError.constructor.name;
|
|
559
|
+
}
|
|
560
|
+
return undefined;
|
|
561
|
+
};
|
|
562
|
+
const isAlreadyStack = line => {
|
|
563
|
+
return line.trim().startsWith('at ');
|
|
564
|
+
};
|
|
565
|
+
const getStack = prettyError => {
|
|
566
|
+
const stackString = prettyError.stack || '';
|
|
567
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
568
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
569
|
+
return stackString.slice(newLineIndex + 1);
|
|
570
|
+
}
|
|
571
|
+
return stackString;
|
|
572
|
+
};
|
|
573
|
+
const getErrorProperty = (error, prettyError) => {
|
|
574
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
575
|
+
return {
|
|
576
|
+
code: MethodNotFound,
|
|
577
|
+
data: error.stack,
|
|
578
|
+
message: error.message
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
code: Custom,
|
|
583
|
+
data: {
|
|
584
|
+
code: prettyError.code,
|
|
585
|
+
codeFrame: prettyError.codeFrame,
|
|
586
|
+
name: prettyError.name,
|
|
587
|
+
stack: getStack(prettyError),
|
|
588
|
+
type: getErrorType(prettyError)
|
|
589
|
+
},
|
|
590
|
+
message: prettyError.message
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
const create$1$1 = (id, error) => {
|
|
594
|
+
return {
|
|
595
|
+
error,
|
|
596
|
+
id,
|
|
597
|
+
jsonrpc: Two$1
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
601
|
+
const prettyError = preparePrettyError(error);
|
|
602
|
+
logError(error, prettyError);
|
|
603
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
604
|
+
return create$1$1(id, errorProperty);
|
|
605
|
+
};
|
|
606
|
+
const create$4 = (message, result) => {
|
|
607
|
+
return {
|
|
608
|
+
id: message.id,
|
|
609
|
+
jsonrpc: Two$1,
|
|
610
|
+
result: result ?? null
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
const getSuccessResponse = (message, result) => {
|
|
614
|
+
const resultProperty = result ?? null;
|
|
615
|
+
return create$4(message, resultProperty);
|
|
616
|
+
};
|
|
617
|
+
const getErrorResponseSimple = (id, error) => {
|
|
618
|
+
return {
|
|
619
|
+
error: {
|
|
620
|
+
code: Custom,
|
|
621
|
+
data: error,
|
|
622
|
+
// @ts-ignore
|
|
623
|
+
message: error.message
|
|
624
|
+
},
|
|
625
|
+
id,
|
|
626
|
+
jsonrpc: Two$1
|
|
627
|
+
};
|
|
628
|
+
};
|
|
629
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
630
|
+
try {
|
|
631
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
632
|
+
return getSuccessResponse(message, result);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
635
|
+
return getErrorResponseSimple(message.id, error);
|
|
636
|
+
}
|
|
637
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const defaultPreparePrettyError = error => {
|
|
641
|
+
return error;
|
|
642
|
+
};
|
|
643
|
+
const defaultLogError = () => {
|
|
644
|
+
// ignore
|
|
645
|
+
};
|
|
646
|
+
const defaultRequiresSocket = () => {
|
|
647
|
+
return false;
|
|
648
|
+
};
|
|
649
|
+
const defaultResolve = resolve;
|
|
650
|
+
|
|
651
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
652
|
+
const normalizeParams = args => {
|
|
653
|
+
if (args.length === 1) {
|
|
654
|
+
const options = args[0];
|
|
655
|
+
return {
|
|
656
|
+
execute: options.execute,
|
|
657
|
+
ipc: options.ipc,
|
|
658
|
+
logError: options.logError || defaultLogError,
|
|
659
|
+
message: options.message,
|
|
660
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
661
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
662
|
+
resolve: options.resolve || defaultResolve
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
execute: args[2],
|
|
667
|
+
ipc: args[0],
|
|
668
|
+
logError: args[5],
|
|
669
|
+
message: args[1],
|
|
670
|
+
preparePrettyError: args[4],
|
|
671
|
+
requiresSocket: args[6],
|
|
672
|
+
resolve: args[3]
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
676
|
+
const options = normalizeParams(args);
|
|
677
|
+
const {
|
|
678
|
+
execute,
|
|
679
|
+
ipc,
|
|
680
|
+
logError,
|
|
681
|
+
message,
|
|
682
|
+
preparePrettyError,
|
|
683
|
+
requiresSocket,
|
|
684
|
+
resolve
|
|
685
|
+
} = options;
|
|
686
|
+
if ('id' in message) {
|
|
687
|
+
if ('method' in message) {
|
|
688
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
689
|
+
try {
|
|
690
|
+
ipc.send(response);
|
|
691
|
+
} catch (error) {
|
|
692
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
693
|
+
ipc.send(errorResponse);
|
|
694
|
+
}
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
resolve(message.id, message);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if ('method' in message) {
|
|
701
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
throw new JsonRpcError('unexpected message');
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
const Two = '2.0';
|
|
708
|
+
|
|
709
|
+
const create$3 = (method, params) => {
|
|
710
|
+
return {
|
|
711
|
+
jsonrpc: Two,
|
|
712
|
+
method,
|
|
713
|
+
params
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
const create$2 = (id, method, params) => {
|
|
718
|
+
const message = {
|
|
719
|
+
id,
|
|
720
|
+
jsonrpc: Two,
|
|
721
|
+
method,
|
|
722
|
+
params
|
|
723
|
+
};
|
|
724
|
+
return message;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
let id = 0;
|
|
728
|
+
const create$1 = () => {
|
|
729
|
+
return ++id;
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
const registerPromise = map => {
|
|
733
|
+
const id = create$1();
|
|
734
|
+
const {
|
|
735
|
+
promise,
|
|
736
|
+
resolve
|
|
737
|
+
} = Promise.withResolvers();
|
|
738
|
+
map[id] = resolve;
|
|
739
|
+
return {
|
|
740
|
+
id,
|
|
741
|
+
promise
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
746
|
+
const {
|
|
747
|
+
id,
|
|
748
|
+
promise
|
|
749
|
+
} = registerPromise(callbacks);
|
|
750
|
+
const message = create$2(id, method, params);
|
|
751
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
752
|
+
ipc.sendAndTransfer(message);
|
|
753
|
+
} else {
|
|
754
|
+
ipc.send(message);
|
|
755
|
+
}
|
|
756
|
+
const responseMessage = await promise;
|
|
757
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
758
|
+
};
|
|
759
|
+
const createRpc = ipc => {
|
|
760
|
+
const callbacks = Object.create(null);
|
|
761
|
+
ipc._resolve = (id, response) => {
|
|
762
|
+
const fn = callbacks[id];
|
|
763
|
+
if (!fn) {
|
|
764
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
fn(response);
|
|
768
|
+
delete callbacks[id];
|
|
769
|
+
};
|
|
770
|
+
const rpc = {
|
|
771
|
+
async dispose() {
|
|
772
|
+
await ipc?.dispose();
|
|
773
|
+
},
|
|
774
|
+
invoke(method, ...params) {
|
|
775
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
776
|
+
},
|
|
777
|
+
invokeAndTransfer(method, ...params) {
|
|
778
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
779
|
+
},
|
|
780
|
+
// @ts-ignore
|
|
781
|
+
ipc,
|
|
782
|
+
/**
|
|
783
|
+
* @deprecated
|
|
784
|
+
*/
|
|
785
|
+
send(method, ...params) {
|
|
786
|
+
const message = create$3(method, params);
|
|
787
|
+
ipc.send(message);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
return rpc;
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
const requiresSocket = () => {
|
|
794
|
+
return false;
|
|
795
|
+
};
|
|
796
|
+
const preparePrettyError = error => {
|
|
797
|
+
return error;
|
|
798
|
+
};
|
|
799
|
+
const logError = () => {
|
|
800
|
+
// handled by renderer worker
|
|
801
|
+
};
|
|
802
|
+
const handleMessage = event => {
|
|
803
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
804
|
+
const actualExecute = event?.target?.execute || execute;
|
|
805
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
const handleIpc = ipc => {
|
|
809
|
+
if ('addEventListener' in ipc) {
|
|
810
|
+
ipc.addEventListener('message', handleMessage);
|
|
811
|
+
} else if ('on' in ipc) {
|
|
812
|
+
// deprecated
|
|
813
|
+
ipc.on('message', handleMessage);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
const listen = async (module, options) => {
|
|
818
|
+
const rawIpc = await module.listen(options);
|
|
819
|
+
if (module.signal) {
|
|
820
|
+
module.signal(rawIpc);
|
|
821
|
+
}
|
|
822
|
+
const ipc = module.wrap(rawIpc);
|
|
823
|
+
return ipc;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const create = async ({
|
|
827
|
+
commandMap
|
|
828
|
+
}) => {
|
|
829
|
+
// TODO create a commandMap per rpc instance
|
|
830
|
+
register(commandMap);
|
|
831
|
+
const ipc = await listen(IpcChildWithNodeWorker$1);
|
|
832
|
+
handleIpc(ipc);
|
|
833
|
+
const rpc = createRpc(ipc);
|
|
834
|
+
return rpc;
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
const WriteJavascriptCoverage = 'WriteJavascriptCoverage';
|
|
838
|
+
|
|
839
|
+
const externalSourceMapCommentRegex = /(?:\/\/[#@]\s*sourceMappingURL=(?!data:).*?$|\/\*[#@]\s*sourceMappingURL=(?!data:).*?\*\/)/gm;
|
|
840
|
+
const temporaryServerRootRegex = /^\/[a-f\d]{7,}(?=\/(?:js|packages)\/)/;
|
|
841
|
+
const normalizeCoveragePath = path => {
|
|
842
|
+
return path.replace(temporaryServerRootRegex, '');
|
|
843
|
+
};
|
|
844
|
+
const normalizeCoverageData = coverageData => {
|
|
845
|
+
const normalized = Object.create(null);
|
|
846
|
+
for (const data of Object.values(coverageData)) {
|
|
847
|
+
const path = normalizeCoveragePath(data.path);
|
|
848
|
+
normalized[path] = {
|
|
849
|
+
...data,
|
|
850
|
+
path
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
return normalized;
|
|
854
|
+
};
|
|
855
|
+
const getCoveragePath = url => {
|
|
856
|
+
try {
|
|
857
|
+
return decodeURIComponent(new URL(url).pathname);
|
|
858
|
+
} catch {
|
|
859
|
+
return url;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
const isTestScript = url => {
|
|
863
|
+
try {
|
|
864
|
+
return new URL(url).pathname.startsWith('/tests/');
|
|
865
|
+
} catch {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
const addEntryToCoverageMap = async (coverageMap, entry) => {
|
|
870
|
+
if (!entry.source || !entry.url || isTestScript(entry.url)) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const source = entry.source.replaceAll(externalSourceMapCommentRegex, '');
|
|
874
|
+
const converter = v8ToIstanbul(getCoveragePath(entry.url), 0, {
|
|
875
|
+
source
|
|
876
|
+
});
|
|
877
|
+
await converter.load();
|
|
878
|
+
converter.applyCoverage(entry.functions);
|
|
879
|
+
coverageMap.merge(normalizeCoverageData(converter.toIstanbul()));
|
|
880
|
+
};
|
|
881
|
+
const createJavascriptCoverage = async entries => {
|
|
882
|
+
const coverageMap = IstanbulCoverage.createCoverageMap();
|
|
883
|
+
for (const entry of entries) {
|
|
884
|
+
await addEntryToCoverageMap(coverageMap, entry);
|
|
885
|
+
}
|
|
886
|
+
return coverageMap;
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
const executeReport = (coverageMap, directory, name) => {
|
|
890
|
+
const context = IstanbulReport.createContext({
|
|
891
|
+
coverageMap,
|
|
892
|
+
dir: directory
|
|
893
|
+
});
|
|
894
|
+
IstanbulReports.create(name).execute(context);
|
|
895
|
+
};
|
|
896
|
+
const writeJavascriptCoverage = async (entries, directory) => {
|
|
897
|
+
const coverageMap = await createJavascriptCoverage(entries);
|
|
898
|
+
await rm(directory, {
|
|
899
|
+
force: true,
|
|
900
|
+
recursive: true
|
|
901
|
+
});
|
|
902
|
+
await mkdir(directory, {
|
|
903
|
+
recursive: true
|
|
904
|
+
});
|
|
905
|
+
executeReport(coverageMap, directory, 'json');
|
|
906
|
+
executeReport(coverageMap, directory, 'json-summary');
|
|
907
|
+
executeReport(coverageMap, directory, 'lcovonly');
|
|
908
|
+
const context = IstanbulReport.createContext({
|
|
909
|
+
coverageMap,
|
|
910
|
+
dir: directory
|
|
911
|
+
});
|
|
912
|
+
IstanbulReports.create('text', {
|
|
913
|
+
file: 'coverage.txt'
|
|
914
|
+
}).execute(context);
|
|
915
|
+
const summaryText = await readFile(join(directory, 'coverage.txt'), 'utf8');
|
|
916
|
+
const summary = summaryText.trimEnd();
|
|
917
|
+
console.info(`[test-with-playwright] JavaScript coverage written to ${directory}\n${summary}`);
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
const commandMap = {
|
|
921
|
+
[WriteJavascriptCoverage]: writeJavascriptCoverage
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
const main = async () => {
|
|
925
|
+
await create({
|
|
926
|
+
commandMap: commandMap
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
await main();
|
package/dist/workerMain.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { join, dirname, basename, extname } from 'node:path';
|
|
2
2
|
import { readFile, writeFile, readdir, rm, mkdir, access, mkdtemp } from 'node:fs/promises';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
-
import IstanbulCoverage from 'istanbul-lib-coverage';
|
|
5
|
-
import v8ToIstanbul from 'v8-to-istanbul';
|
|
6
|
-
import IstanbulReport from 'istanbul-lib-report';
|
|
7
|
-
import IstanbulReports from 'istanbul-reports';
|
|
8
4
|
import net from 'node:net';
|
|
9
5
|
import os, { tmpdir } from 'node:os';
|
|
10
6
|
import { fork } from 'node:child_process';
|
|
@@ -452,6 +448,137 @@ const IpcChildWithNodeWorker$1 = {
|
|
|
452
448
|
signal: signal$5,
|
|
453
449
|
wrap: wrap$b
|
|
454
450
|
};
|
|
451
|
+
const addListener = (emitter, type, callback) => {
|
|
452
|
+
if ('addEventListener' in emitter) {
|
|
453
|
+
emitter.addEventListener(type, callback);
|
|
454
|
+
} else {
|
|
455
|
+
emitter.on(type, callback);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
const removeListener = (emitter, type, callback) => {
|
|
459
|
+
if ('removeEventListener' in emitter) {
|
|
460
|
+
emitter.removeEventListener(type, callback);
|
|
461
|
+
} else {
|
|
462
|
+
emitter.off(type, callback);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
466
|
+
const {
|
|
467
|
+
promise,
|
|
468
|
+
resolve
|
|
469
|
+
} = Promise.withResolvers();
|
|
470
|
+
const listenerMap = Object.create(null);
|
|
471
|
+
const cleanup = value => {
|
|
472
|
+
for (const event of Object.keys(eventMap)) {
|
|
473
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
474
|
+
}
|
|
475
|
+
resolve(value);
|
|
476
|
+
};
|
|
477
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
478
|
+
const listener = event => {
|
|
479
|
+
cleanup({
|
|
480
|
+
event,
|
|
481
|
+
type
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
addListener(eventEmitter, event, listener);
|
|
485
|
+
listenerMap[event] = listener;
|
|
486
|
+
}
|
|
487
|
+
return promise;
|
|
488
|
+
};
|
|
489
|
+
const Exit = 1;
|
|
490
|
+
const Error$2 = 2;
|
|
491
|
+
const Message$1 = 3;
|
|
492
|
+
const fixNodeWorkerParameters = value => {
|
|
493
|
+
const transfer = getTransferrables(value);
|
|
494
|
+
if (transfer.length === 0) {
|
|
495
|
+
throw new IpcError('no transferrables found');
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
newValue: value,
|
|
499
|
+
transfer: transfer
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
const getFirstNodeWorkerEvent = worker => {
|
|
503
|
+
return getFirstEvent(worker, {
|
|
504
|
+
error: Error$2,
|
|
505
|
+
exit: Exit,
|
|
506
|
+
message: Message$1
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
const create$1$2 = async ({
|
|
510
|
+
argv = [],
|
|
511
|
+
env = process.env,
|
|
512
|
+
execArgv = [],
|
|
513
|
+
name,
|
|
514
|
+
path,
|
|
515
|
+
stdio
|
|
516
|
+
}) => {
|
|
517
|
+
string(path);
|
|
518
|
+
const actualArgv = ['--ipc-type=node-worker', ...argv];
|
|
519
|
+
const actualEnv = {
|
|
520
|
+
...env,
|
|
521
|
+
ELECTRON_RUN_AS_NODE: '1'
|
|
522
|
+
};
|
|
523
|
+
const ignoreStdio = stdio === 'inherit' ? undefined : true;
|
|
524
|
+
const {
|
|
525
|
+
Worker
|
|
526
|
+
} = await import('node:worker_threads');
|
|
527
|
+
const worker = new Worker(path, {
|
|
528
|
+
argv: actualArgv,
|
|
529
|
+
env: actualEnv,
|
|
530
|
+
execArgv,
|
|
531
|
+
name,
|
|
532
|
+
stderr: ignoreStdio,
|
|
533
|
+
stdout: ignoreStdio
|
|
534
|
+
});
|
|
535
|
+
const {
|
|
536
|
+
event,
|
|
537
|
+
type
|
|
538
|
+
} = await getFirstNodeWorkerEvent(worker);
|
|
539
|
+
if (type === Exit) {
|
|
540
|
+
throw new IpcError(`Worker exited before ipc connection was established`);
|
|
541
|
+
}
|
|
542
|
+
if (type === Error$2) {
|
|
543
|
+
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
544
|
+
}
|
|
545
|
+
if (event !== readyMessage) {
|
|
546
|
+
throw new IpcError('unexpected first message from worker');
|
|
547
|
+
}
|
|
548
|
+
return worker;
|
|
549
|
+
};
|
|
550
|
+
class IpcParentWithNodeWorker extends Ipc {
|
|
551
|
+
getData(message) {
|
|
552
|
+
return message;
|
|
553
|
+
}
|
|
554
|
+
send(message) {
|
|
555
|
+
this._rawIpc.postMessage(message);
|
|
556
|
+
}
|
|
557
|
+
sendAndTransfer(message) {
|
|
558
|
+
const {
|
|
559
|
+
newValue,
|
|
560
|
+
transfer
|
|
561
|
+
} = fixNodeWorkerParameters(message);
|
|
562
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
563
|
+
}
|
|
564
|
+
async dispose() {
|
|
565
|
+
await this._rawIpc.terminate();
|
|
566
|
+
}
|
|
567
|
+
onClose(callback) {
|
|
568
|
+
this._rawIpc.on('exit', callback);
|
|
569
|
+
}
|
|
570
|
+
onMessage(callback) {
|
|
571
|
+
this._rawIpc.on('message', callback);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const wrap$1 = worker => {
|
|
575
|
+
return new IpcParentWithNodeWorker(worker);
|
|
576
|
+
};
|
|
577
|
+
const IpcParentWithNodeWorker$1 = {
|
|
578
|
+
__proto__: null,
|
|
579
|
+
create: create$1$2,
|
|
580
|
+
wrap: wrap$1
|
|
581
|
+
};
|
|
455
582
|
|
|
456
583
|
class CommandNotFoundError extends Error {
|
|
457
584
|
constructor(command) {
|
|
@@ -729,7 +856,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
729
856
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
730
857
|
return create$1$1(id, errorProperty);
|
|
731
858
|
};
|
|
732
|
-
const create$
|
|
859
|
+
const create$6 = (message, result) => {
|
|
733
860
|
return {
|
|
734
861
|
id: message.id,
|
|
735
862
|
jsonrpc: Two$1,
|
|
@@ -738,7 +865,7 @@ const create$4 = (message, result) => {
|
|
|
738
865
|
};
|
|
739
866
|
const getSuccessResponse = (message, result) => {
|
|
740
867
|
const resultProperty = result ?? null;
|
|
741
|
-
return create$
|
|
868
|
+
return create$6(message, resultProperty);
|
|
742
869
|
};
|
|
743
870
|
const getErrorResponseSimple = (id, error) => {
|
|
744
871
|
return {
|
|
@@ -832,7 +959,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
832
959
|
|
|
833
960
|
const Two = '2.0';
|
|
834
961
|
|
|
835
|
-
const create$
|
|
962
|
+
const create$5 = (method, params) => {
|
|
836
963
|
return {
|
|
837
964
|
jsonrpc: Two,
|
|
838
965
|
method,
|
|
@@ -840,7 +967,7 @@ const create$3 = (method, params) => {
|
|
|
840
967
|
};
|
|
841
968
|
};
|
|
842
969
|
|
|
843
|
-
const create$
|
|
970
|
+
const create$4 = (id, method, params) => {
|
|
844
971
|
const message = {
|
|
845
972
|
id,
|
|
846
973
|
jsonrpc: Two,
|
|
@@ -851,12 +978,12 @@ const create$2 = (id, method, params) => {
|
|
|
851
978
|
};
|
|
852
979
|
|
|
853
980
|
let id = 0;
|
|
854
|
-
const create$
|
|
981
|
+
const create$3 = () => {
|
|
855
982
|
return ++id;
|
|
856
983
|
};
|
|
857
984
|
|
|
858
985
|
const registerPromise = map => {
|
|
859
|
-
const id = create$
|
|
986
|
+
const id = create$3();
|
|
860
987
|
const {
|
|
861
988
|
promise,
|
|
862
989
|
resolve
|
|
@@ -873,7 +1000,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
873
1000
|
id,
|
|
874
1001
|
promise
|
|
875
1002
|
} = registerPromise(callbacks);
|
|
876
|
-
const message = create$
|
|
1003
|
+
const message = create$4(id, method, params);
|
|
877
1004
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
878
1005
|
ipc.sendAndTransfer(message);
|
|
879
1006
|
} else {
|
|
@@ -909,7 +1036,7 @@ const createRpc = ipc => {
|
|
|
909
1036
|
* @deprecated
|
|
910
1037
|
*/
|
|
911
1038
|
send(method, ...params) {
|
|
912
|
-
const message = create$
|
|
1039
|
+
const message = create$5(method, params);
|
|
913
1040
|
ipc.send(message);
|
|
914
1041
|
}
|
|
915
1042
|
};
|
|
@@ -949,6 +1076,82 @@ const listen = async (module, options) => {
|
|
|
949
1076
|
return ipc;
|
|
950
1077
|
};
|
|
951
1078
|
|
|
1079
|
+
const create$2 = async ({
|
|
1080
|
+
argv,
|
|
1081
|
+
commandMap,
|
|
1082
|
+
env,
|
|
1083
|
+
execArgv,
|
|
1084
|
+
path,
|
|
1085
|
+
stdio
|
|
1086
|
+
}) => {
|
|
1087
|
+
// TODO create a commandMap per rpc instance
|
|
1088
|
+
register(commandMap);
|
|
1089
|
+
const rawIpc = await IpcParentWithNodeWorker$1.create({
|
|
1090
|
+
argv,
|
|
1091
|
+
env,
|
|
1092
|
+
execArgv,
|
|
1093
|
+
path,
|
|
1094
|
+
stdio
|
|
1095
|
+
});
|
|
1096
|
+
const ipc = IpcParentWithNodeWorker$1.wrap(rawIpc);
|
|
1097
|
+
handleIpc(ipc);
|
|
1098
|
+
const rpc = createRpc(ipc);
|
|
1099
|
+
// @ts-ignore
|
|
1100
|
+
rpc.stdout = ipc._rawIpc.stdout;
|
|
1101
|
+
// @ts-ignore
|
|
1102
|
+
rpc.stderr = ipc._rawIpc.stderr;
|
|
1103
|
+
// @ts-ignore
|
|
1104
|
+
return rpc;
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
const createSharedLazyRpc = factory => {
|
|
1108
|
+
let rpcPromise;
|
|
1109
|
+
const getOrCreate = () => {
|
|
1110
|
+
if (!rpcPromise) {
|
|
1111
|
+
rpcPromise = factory();
|
|
1112
|
+
}
|
|
1113
|
+
return rpcPromise;
|
|
1114
|
+
};
|
|
1115
|
+
return {
|
|
1116
|
+
async dispose() {
|
|
1117
|
+
const rpc = await getOrCreate();
|
|
1118
|
+
await rpc.dispose();
|
|
1119
|
+
},
|
|
1120
|
+
async invoke(method, ...params) {
|
|
1121
|
+
const rpc = await getOrCreate();
|
|
1122
|
+
return rpc.invoke(method, ...params);
|
|
1123
|
+
},
|
|
1124
|
+
async invokeAndTransfer(method, ...params) {
|
|
1125
|
+
const rpc = await getOrCreate();
|
|
1126
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1127
|
+
},
|
|
1128
|
+
async send(method, ...params) {
|
|
1129
|
+
const rpc = await getOrCreate();
|
|
1130
|
+
rpc.send(method, ...params);
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
const create$1 = ({
|
|
1136
|
+
argv,
|
|
1137
|
+
commandMap,
|
|
1138
|
+
env,
|
|
1139
|
+
execArgv,
|
|
1140
|
+
path,
|
|
1141
|
+
stdio
|
|
1142
|
+
}) => {
|
|
1143
|
+
return createSharedLazyRpc(() => {
|
|
1144
|
+
return create$2({
|
|
1145
|
+
argv,
|
|
1146
|
+
commandMap,
|
|
1147
|
+
env,
|
|
1148
|
+
execArgv,
|
|
1149
|
+
path,
|
|
1150
|
+
stdio
|
|
1151
|
+
});
|
|
1152
|
+
});
|
|
1153
|
+
};
|
|
1154
|
+
|
|
952
1155
|
const create = async ({
|
|
953
1156
|
commandMap
|
|
954
1157
|
}) => {
|
|
@@ -1102,7 +1305,12 @@ const captureSvgScreenshot = async ({
|
|
|
1102
1305
|
page,
|
|
1103
1306
|
test
|
|
1104
1307
|
}) => {
|
|
1105
|
-
|
|
1308
|
+
let svg;
|
|
1309
|
+
try {
|
|
1310
|
+
svg = await capture(page, options.selector);
|
|
1311
|
+
} catch (error) {
|
|
1312
|
+
throw new VError(error, 'Failed to capture SVG screenshot');
|
|
1313
|
+
}
|
|
1106
1314
|
await compareSvgScreenshot({
|
|
1107
1315
|
options,
|
|
1108
1316
|
svg,
|
|
@@ -1668,84 +1876,26 @@ const runTestsWithReusedPage = async ({
|
|
|
1668
1876
|
});
|
|
1669
1877
|
};
|
|
1670
1878
|
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
const normalizeCoverageData = coverageData => {
|
|
1677
|
-
const normalized = Object.create(null);
|
|
1678
|
-
for (const data of Object.values(coverageData)) {
|
|
1679
|
-
const path = normalizeCoveragePath(data.path);
|
|
1680
|
-
normalized[path] = {
|
|
1681
|
-
...data,
|
|
1682
|
-
path
|
|
1683
|
-
};
|
|
1684
|
-
}
|
|
1685
|
-
return normalized;
|
|
1686
|
-
};
|
|
1687
|
-
const getCoveragePath = url => {
|
|
1688
|
-
try {
|
|
1689
|
-
return decodeURIComponent(new URL(url).pathname);
|
|
1690
|
-
} catch {
|
|
1691
|
-
return url;
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
const isTestScript = url => {
|
|
1695
|
-
try {
|
|
1696
|
-
return new URL(url).pathname.startsWith('/tests/');
|
|
1697
|
-
} catch {
|
|
1698
|
-
return false;
|
|
1699
|
-
}
|
|
1700
|
-
};
|
|
1701
|
-
const addEntryToCoverageMap = async (coverageMap, entry) => {
|
|
1702
|
-
if (!entry.source || !entry.url || isTestScript(entry.url)) {
|
|
1703
|
-
return;
|
|
1704
|
-
}
|
|
1705
|
-
const source = entry.source.replaceAll(externalSourceMapCommentRegex, '');
|
|
1706
|
-
const converter = v8ToIstanbul(getCoveragePath(entry.url), 0, {
|
|
1707
|
-
source
|
|
1708
|
-
});
|
|
1709
|
-
await converter.load();
|
|
1710
|
-
converter.applyCoverage(entry.functions);
|
|
1711
|
-
coverageMap.merge(normalizeCoverageData(converter.toIstanbul()));
|
|
1712
|
-
};
|
|
1713
|
-
const createJavascriptCoverage = async entries => {
|
|
1714
|
-
const coverageMap = IstanbulCoverage.createCoverageMap();
|
|
1715
|
-
for (const entry of entries) {
|
|
1716
|
-
await addEntryToCoverageMap(coverageMap, entry);
|
|
1879
|
+
const WriteJavascriptCoverage = 'WriteJavascriptCoverage';
|
|
1880
|
+
|
|
1881
|
+
const getCoverageWorkerUrl = (moduleUrl = import.meta.url) => {
|
|
1882
|
+
if (moduleUrl.endsWith('/dist/workerMain.js')) {
|
|
1883
|
+
return new URL('coverageWorkerMain.js', moduleUrl).href;
|
|
1717
1884
|
}
|
|
1718
|
-
return
|
|
1885
|
+
return new URL('../../../../test-with-playwright-coverage-worker/src/workerMain.ts', moduleUrl).href;
|
|
1719
1886
|
};
|
|
1720
1887
|
|
|
1721
|
-
const
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
IstanbulReports.create(name).execute(context);
|
|
1727
|
-
};
|
|
1728
|
-
const writeJavascriptCoverage = async (coverageMap, directory) => {
|
|
1729
|
-
await rm(directory, {
|
|
1730
|
-
force: true,
|
|
1731
|
-
recursive: true
|
|
1732
|
-
});
|
|
1733
|
-
await mkdir(directory, {
|
|
1734
|
-
recursive: true
|
|
1735
|
-
});
|
|
1736
|
-
executeReport(coverageMap, directory, 'json');
|
|
1737
|
-
executeReport(coverageMap, directory, 'json-summary');
|
|
1738
|
-
executeReport(coverageMap, directory, 'lcovonly');
|
|
1739
|
-
const context = IstanbulReport.createContext({
|
|
1740
|
-
coverageMap,
|
|
1741
|
-
dir: directory
|
|
1888
|
+
const writeJavascriptCoverage = async (entries, directory) => {
|
|
1889
|
+
const rpc = create$1({
|
|
1890
|
+
commandMap: {},
|
|
1891
|
+
path: fileURLToPath(getCoverageWorkerUrl()),
|
|
1892
|
+
stdio: 'inherit'
|
|
1742
1893
|
});
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
console.info(`[test-with-playwright] JavaScript coverage written to ${directory}\n${summary}`);
|
|
1894
|
+
try {
|
|
1895
|
+
await rpc.invoke(WriteJavascriptCoverage, entries, directory);
|
|
1896
|
+
} finally {
|
|
1897
|
+
await rpc.dispose();
|
|
1898
|
+
}
|
|
1749
1899
|
};
|
|
1750
1900
|
|
|
1751
1901
|
const runWithJavascriptCoverage = async ({
|
|
@@ -1765,8 +1915,7 @@ const runWithJavascriptCoverage = async ({
|
|
|
1765
1915
|
await run();
|
|
1766
1916
|
} finally {
|
|
1767
1917
|
const entries = await page.coverage.stopJSCoverage();
|
|
1768
|
-
|
|
1769
|
-
await writeJavascriptCoverage(coverageMap, join(cwd, 'coverage'));
|
|
1918
|
+
await writeJavascriptCoverage(entries, join(cwd, 'coverage'));
|
|
1770
1919
|
}
|
|
1771
1920
|
};
|
|
1772
1921
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/test-with-playwright-worker",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.28.0",
|
|
4
4
|
"description": "Worker package for test-with-playwright",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,16 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@playwright/test": "1.62.1",
|
|
16
16
|
"get-port": "^7.2.0",
|
|
17
|
-
"
|
|
18
|
-
"istanbul-lib-report": "^3.0.1",
|
|
19
|
-
"istanbul-reports": "^3.2.0",
|
|
20
|
-
"playwright-core": "^1.62.1",
|
|
21
|
-
"v8-to-istanbul": "^9.3.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/istanbul-lib-coverage": "^2.0.6",
|
|
25
|
-
"@types/istanbul-lib-report": "^3.0.3",
|
|
26
|
-
"@types/istanbul-reports": "^3.0.4"
|
|
17
|
+
"playwright-core": "^1.62.1"
|
|
27
18
|
},
|
|
28
19
|
"engines": {
|
|
29
20
|
"node": ">=24"
|