@lvce-editor/test-worker 1.3.0 → 1.5.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/testWorkerMain.js +196 -35
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -134,7 +134,6 @@ const getErrorConstructor = (message, type) => {
|
|
|
134
134
|
if (type) {
|
|
135
135
|
switch (type) {
|
|
136
136
|
case DomException:
|
|
137
|
-
// @ts-ignore
|
|
138
137
|
return DOMException;
|
|
139
138
|
case TypeError$1:
|
|
140
139
|
return TypeError;
|
|
@@ -159,7 +158,6 @@ const getErrorConstructor = (message, type) => {
|
|
|
159
158
|
};
|
|
160
159
|
const constructError = (message, type, name) => {
|
|
161
160
|
const ErrorConstructor = getErrorConstructor(message, type);
|
|
162
|
-
// @ts-ignore
|
|
163
161
|
if (ErrorConstructor === DOMException && name) {
|
|
164
162
|
return new ErrorConstructor(message, name);
|
|
165
163
|
}
|
|
@@ -175,6 +173,13 @@ const constructError = (message, type, name) => {
|
|
|
175
173
|
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
176
174
|
return string.indexOf(NewLine$3, startIndex);
|
|
177
175
|
};
|
|
176
|
+
const getParentStack = error => {
|
|
177
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
178
|
+
if (parentStack.startsWith(' at')) {
|
|
179
|
+
parentStack = error.message + NewLine$3 + parentStack;
|
|
180
|
+
}
|
|
181
|
+
return parentStack;
|
|
182
|
+
};
|
|
178
183
|
const joinLines$1 = lines => {
|
|
179
184
|
return lines.join(NewLine$3);
|
|
180
185
|
};
|
|
@@ -183,18 +188,11 @@ const Custom = -32001;
|
|
|
183
188
|
const splitLines$1 = lines => {
|
|
184
189
|
return lines.split(NewLine$3);
|
|
185
190
|
};
|
|
186
|
-
const getParentStack = error => {
|
|
187
|
-
let parentStack = error.stack || error.data || error.message || '';
|
|
188
|
-
if (parentStack.startsWith(' at')) {
|
|
189
|
-
parentStack = error.message + NewLine$3 + parentStack;
|
|
190
|
-
}
|
|
191
|
-
return parentStack;
|
|
192
|
-
};
|
|
193
191
|
const restoreJsonRpcError = error => {
|
|
194
192
|
if (error && error instanceof Error) {
|
|
195
193
|
return error;
|
|
196
194
|
}
|
|
197
|
-
const currentStack = joinLines$1(splitLines$1(new Error().stack).slice(1));
|
|
195
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
|
|
198
196
|
if (error && error.code && error.code === MethodNotFound) {
|
|
199
197
|
const restoredError = new JsonRpcError(error.message);
|
|
200
198
|
const parentStack = getParentStack(error);
|
|
@@ -223,7 +221,6 @@ const restoreJsonRpcError = error => {
|
|
|
223
221
|
}
|
|
224
222
|
} else {
|
|
225
223
|
if (error.stack) {
|
|
226
|
-
// TODO accessing stack might be slow
|
|
227
224
|
const lowerStack = restoredError.stack || '';
|
|
228
225
|
// @ts-ignore
|
|
229
226
|
const indexNewLine = getNewLineIndex$2(lowerStack);
|
|
@@ -305,7 +302,42 @@ const getResponse = async (message, ipc, execute, preparePrettyError, logError,
|
|
|
305
302
|
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
306
303
|
}
|
|
307
304
|
};
|
|
308
|
-
const
|
|
305
|
+
const defaultPreparePrettyError = error => {
|
|
306
|
+
return error;
|
|
307
|
+
};
|
|
308
|
+
const defaultLogError = () => {
|
|
309
|
+
// ignore
|
|
310
|
+
};
|
|
311
|
+
const defaultRequiresSocket = () => {
|
|
312
|
+
return false;
|
|
313
|
+
};
|
|
314
|
+
const defaultResolve = resolve;
|
|
315
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
316
|
+
let message;
|
|
317
|
+
let ipc;
|
|
318
|
+
let execute;
|
|
319
|
+
let preparePrettyError;
|
|
320
|
+
let logError;
|
|
321
|
+
let resolve;
|
|
322
|
+
let requiresSocket;
|
|
323
|
+
if (args.length === 1) {
|
|
324
|
+
const arg = args[0];
|
|
325
|
+
message = arg.message;
|
|
326
|
+
ipc = arg.ipc;
|
|
327
|
+
execute = arg.execute;
|
|
328
|
+
preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
|
|
329
|
+
logError = arg.logError || defaultLogError;
|
|
330
|
+
requiresSocket = arg.requiresSocket || defaultRequiresSocket;
|
|
331
|
+
resolve = arg.resolve || defaultResolve;
|
|
332
|
+
} else {
|
|
333
|
+
ipc = args[0];
|
|
334
|
+
message = args[1];
|
|
335
|
+
execute = args[2];
|
|
336
|
+
resolve = args[3];
|
|
337
|
+
preparePrettyError = args[4];
|
|
338
|
+
logError = args[5];
|
|
339
|
+
requiresSocket = args[6];
|
|
340
|
+
}
|
|
309
341
|
if ('id' in message) {
|
|
310
342
|
if ('method' in message) {
|
|
311
343
|
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
@@ -337,18 +369,40 @@ const invoke$1 = async (ipc, method, ...params) => {
|
|
|
337
369
|
return result;
|
|
338
370
|
};
|
|
339
371
|
|
|
372
|
+
// TODO deprecated old typings,
|
|
373
|
+
// always use automatic transferrable detection
|
|
374
|
+
const invokeAndTransfer$1 = async (ipc, handle, method, ...params) => {
|
|
375
|
+
if (typeof handle === 'string') {
|
|
376
|
+
params = [method, ...params];
|
|
377
|
+
method = handle;
|
|
378
|
+
}
|
|
379
|
+
const {
|
|
380
|
+
message,
|
|
381
|
+
promise
|
|
382
|
+
} = create$2(method, params);
|
|
383
|
+
ipc.sendAndTransfer(message);
|
|
384
|
+
const responseMessage = await promise;
|
|
385
|
+
const result = unwrapJsonRpcResult(responseMessage);
|
|
386
|
+
return result;
|
|
387
|
+
};
|
|
388
|
+
|
|
340
389
|
const invoke = (method, ...params) => {
|
|
341
390
|
const ipc = get$1();
|
|
342
391
|
return invoke$1(ipc, method, ...params);
|
|
343
392
|
};
|
|
344
|
-
const
|
|
393
|
+
const invokeAndTransfer = (method, ...params) => {
|
|
394
|
+
const ipc = get$1();
|
|
395
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
396
|
+
};
|
|
397
|
+
const listen$2 = ipc => {
|
|
345
398
|
set$1(ipc);
|
|
346
399
|
};
|
|
347
400
|
|
|
348
401
|
const Rpc = {
|
|
349
402
|
__proto__: null,
|
|
350
403
|
invoke,
|
|
351
|
-
|
|
404
|
+
invokeAndTransfer,
|
|
405
|
+
listen: listen$2
|
|
352
406
|
};
|
|
353
407
|
|
|
354
408
|
const Fail = 'fail';
|
|
@@ -840,13 +894,13 @@ const TestFrameWorkComponentBaseUrl = {
|
|
|
840
894
|
getBaseUrl
|
|
841
895
|
};
|
|
842
896
|
|
|
843
|
-
const execute$
|
|
897
|
+
const execute$3 = async (id, ...args) => {
|
|
844
898
|
return invoke(id, ...args);
|
|
845
899
|
};
|
|
846
900
|
|
|
847
901
|
const TestFrameWorkComponentCommand = {
|
|
848
902
|
__proto__: null,
|
|
849
|
-
execute: execute$
|
|
903
|
+
execute: execute$3
|
|
850
904
|
};
|
|
851
905
|
|
|
852
906
|
const selectItem$1 = async text => {
|
|
@@ -1405,7 +1459,62 @@ const TestFrameWorkComponentTitleBarMenuBar = {
|
|
|
1405
1459
|
toggleMenu
|
|
1406
1460
|
};
|
|
1407
1461
|
|
|
1462
|
+
const getPortTuple = () => {
|
|
1463
|
+
const {
|
|
1464
|
+
port1,
|
|
1465
|
+
port2
|
|
1466
|
+
} = new MessageChannel();
|
|
1467
|
+
return {
|
|
1468
|
+
port1,
|
|
1469
|
+
port2
|
|
1470
|
+
};
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
const sendPortToWebView = async (webviewId, port) => {
|
|
1474
|
+
await invokeAndTransfer('Transferrable.transferToRendererProcess', webviewId, port);
|
|
1475
|
+
console.log('did send port to renderer process');
|
|
1476
|
+
// TODO ask renderer process to transfer the port to the webview
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
const preparePrettyError$1 = error => {
|
|
1480
|
+
return error;
|
|
1481
|
+
};
|
|
1482
|
+
const logError$1 = () => {
|
|
1483
|
+
// ignore
|
|
1484
|
+
};
|
|
1485
|
+
const execute$2 = () => {};
|
|
1486
|
+
const requiresSocket$1 = () => {
|
|
1487
|
+
return false;
|
|
1488
|
+
};
|
|
1489
|
+
const createPortIpc = async webViewId => {
|
|
1490
|
+
const {
|
|
1491
|
+
port1,
|
|
1492
|
+
port2
|
|
1493
|
+
} = getPortTuple();
|
|
1494
|
+
const firstEventPromise = new Promise(resolve => {
|
|
1495
|
+
port1.onmessage = resolve;
|
|
1496
|
+
});
|
|
1497
|
+
await sendPortToWebView(webViewId, port2);
|
|
1498
|
+
const firstEvent = await firstEventPromise;
|
|
1499
|
+
// @ts-ignore
|
|
1500
|
+
if (firstEvent.data !== 'ready') {
|
|
1501
|
+
throw new Error('unexpected first message');
|
|
1502
|
+
}
|
|
1503
|
+
const handleOtherMessage = async event => {
|
|
1504
|
+
// @ts-ignore
|
|
1505
|
+
await handleJsonRpcMessage(ipc, event.data, resolve, preparePrettyError$1, execute$2, logError$1, requiresSocket$1);
|
|
1506
|
+
};
|
|
1507
|
+
port1.onmessage = handleOtherMessage;
|
|
1508
|
+
const ipc = {
|
|
1509
|
+
send(message) {
|
|
1510
|
+
port1.postMessage(message);
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
return ipc;
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1408
1516
|
const fromId = async webViewId => {
|
|
1517
|
+
const ipc = await createPortIpc(webViewId);
|
|
1409
1518
|
// TODO
|
|
1410
1519
|
// 1. create messagechannel
|
|
1411
1520
|
// 2. send one message port to webview
|
|
@@ -1413,7 +1522,7 @@ const fromId = async webViewId => {
|
|
|
1413
1522
|
// 4. send test commands like locator.toBeVisible to webview
|
|
1414
1523
|
const webViewRpc = {
|
|
1415
1524
|
invoke(method, ...params) {
|
|
1416
|
-
|
|
1525
|
+
return invoke$1(ipc, method, ...params);
|
|
1417
1526
|
}
|
|
1418
1527
|
};
|
|
1419
1528
|
return {
|
|
@@ -1548,14 +1657,14 @@ const handleIpc = ipc => {
|
|
|
1548
1657
|
ipc.addEventListener('message', handleMessage);
|
|
1549
1658
|
};
|
|
1550
1659
|
|
|
1551
|
-
const MessagePort = 1;
|
|
1660
|
+
const MessagePort$1 = 1;
|
|
1552
1661
|
const ModuleWorker = 2;
|
|
1553
1662
|
const ReferencePort = 3;
|
|
1554
1663
|
const ModuleWorkerAndMessagePort = 8;
|
|
1555
1664
|
const Auto = () => {
|
|
1556
1665
|
// @ts-ignore
|
|
1557
1666
|
if (globalThis.acceptPort) {
|
|
1558
|
-
return MessagePort;
|
|
1667
|
+
return MessagePort$1;
|
|
1559
1668
|
}
|
|
1560
1669
|
// @ts-ignore
|
|
1561
1670
|
if (globalThis.acceptReferencePort) {
|
|
@@ -1567,6 +1676,56 @@ const Auto = () => {
|
|
|
1567
1676
|
const getData$1 = event => {
|
|
1568
1677
|
return event.data;
|
|
1569
1678
|
};
|
|
1679
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1680
|
+
if (!value) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (isTransferrable(value)) {
|
|
1684
|
+
transferrables.push(value);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
if (Array.isArray(value)) {
|
|
1688
|
+
for (const item of value) {
|
|
1689
|
+
walkValue(item, transferrables, isTransferrable);
|
|
1690
|
+
}
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (typeof value === 'object') {
|
|
1694
|
+
for (const property of Object.values(value)) {
|
|
1695
|
+
walkValue(property, transferrables, isTransferrable);
|
|
1696
|
+
}
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
const isMessagePort = value => {
|
|
1701
|
+
return value && value instanceof MessagePort;
|
|
1702
|
+
};
|
|
1703
|
+
const isMessagePortMain = value => {
|
|
1704
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1705
|
+
};
|
|
1706
|
+
const isOffscreenCanvas = value => {
|
|
1707
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1708
|
+
};
|
|
1709
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1710
|
+
return value?.constructor?.name === constructorName;
|
|
1711
|
+
};
|
|
1712
|
+
const isSocket = value => {
|
|
1713
|
+
return isInstanceOf(value, 'Socket');
|
|
1714
|
+
};
|
|
1715
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1716
|
+
const isTransferrable = value => {
|
|
1717
|
+
for (const fn of transferrables) {
|
|
1718
|
+
if (fn(value)) {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return false;
|
|
1723
|
+
};
|
|
1724
|
+
const getTransferrables = value => {
|
|
1725
|
+
const transferrables = [];
|
|
1726
|
+
walkValue(value, transferrables, isTransferrable);
|
|
1727
|
+
return transferrables;
|
|
1728
|
+
};
|
|
1570
1729
|
const attachEvents = that => {
|
|
1571
1730
|
const handleMessage = (...args) => {
|
|
1572
1731
|
const data = that.getData(...args);
|
|
@@ -1588,14 +1747,14 @@ class Ipc extends EventTarget {
|
|
|
1588
1747
|
}
|
|
1589
1748
|
}
|
|
1590
1749
|
const readyMessage = 'ready';
|
|
1591
|
-
const listen$
|
|
1750
|
+
const listen$4 = () => {
|
|
1592
1751
|
// @ts-ignore
|
|
1593
1752
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
1594
1753
|
throw new TypeError('module is not in web worker scope');
|
|
1595
1754
|
}
|
|
1596
1755
|
return globalThis;
|
|
1597
1756
|
};
|
|
1598
|
-
const signal$
|
|
1757
|
+
const signal$3 = global => {
|
|
1599
1758
|
global.postMessage(readyMessage);
|
|
1600
1759
|
};
|
|
1601
1760
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -1606,7 +1765,8 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1606
1765
|
// @ts-ignore
|
|
1607
1766
|
this._rawIpc.postMessage(message);
|
|
1608
1767
|
}
|
|
1609
|
-
sendAndTransfer(message
|
|
1768
|
+
sendAndTransfer(message) {
|
|
1769
|
+
const transfer = getTransferrables(message);
|
|
1610
1770
|
// @ts-ignore
|
|
1611
1771
|
this._rawIpc.postMessage(message, transfer);
|
|
1612
1772
|
}
|
|
@@ -1620,14 +1780,14 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1620
1780
|
this._rawIpc.addEventListener('message', callback);
|
|
1621
1781
|
}
|
|
1622
1782
|
}
|
|
1623
|
-
const wrap$
|
|
1783
|
+
const wrap$6 = global => {
|
|
1624
1784
|
return new IpcChildWithModuleWorker(global);
|
|
1625
1785
|
};
|
|
1626
1786
|
const IpcChildWithModuleWorker$1 = {
|
|
1627
1787
|
__proto__: null,
|
|
1628
|
-
listen: listen$
|
|
1629
|
-
signal: signal$
|
|
1630
|
-
wrap: wrap$
|
|
1788
|
+
listen: listen$4,
|
|
1789
|
+
signal: signal$3,
|
|
1790
|
+
wrap: wrap$6
|
|
1631
1791
|
};
|
|
1632
1792
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1633
1793
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
@@ -1845,10 +2005,10 @@ const waitForFirstMessage = async port => {
|
|
|
1845
2005
|
// @ts-ignore
|
|
1846
2006
|
return event.data;
|
|
1847
2007
|
};
|
|
1848
|
-
const listen$
|
|
1849
|
-
const parentIpcRaw = listen$
|
|
1850
|
-
signal$
|
|
1851
|
-
const parentIpc = wrap$
|
|
2008
|
+
const listen$3 = async () => {
|
|
2009
|
+
const parentIpcRaw = listen$4();
|
|
2010
|
+
signal$3(parentIpcRaw);
|
|
2011
|
+
const parentIpc = wrap$6(parentIpcRaw);
|
|
1852
2012
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
1853
2013
|
if (firstMessage.method !== 'initialize') {
|
|
1854
2014
|
throw new IpcError('unexpected first message');
|
|
@@ -1871,7 +2031,8 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
1871
2031
|
send(message) {
|
|
1872
2032
|
this._rawIpc.postMessage(message);
|
|
1873
2033
|
}
|
|
1874
|
-
sendAndTransfer(message
|
|
2034
|
+
sendAndTransfer(message) {
|
|
2035
|
+
const transfer = getTransferrables(message);
|
|
1875
2036
|
this._rawIpc.postMessage(message, transfer);
|
|
1876
2037
|
}
|
|
1877
2038
|
dispose() {
|
|
@@ -1887,13 +2048,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
1887
2048
|
this._rawIpc.start();
|
|
1888
2049
|
}
|
|
1889
2050
|
}
|
|
1890
|
-
const wrap$
|
|
2051
|
+
const wrap$5 = port => {
|
|
1891
2052
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
1892
2053
|
};
|
|
1893
2054
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
1894
2055
|
__proto__: null,
|
|
1895
|
-
listen: listen$
|
|
1896
|
-
wrap: wrap$
|
|
2056
|
+
listen: listen$3,
|
|
2057
|
+
wrap: wrap$5
|
|
1897
2058
|
};
|
|
1898
2059
|
|
|
1899
2060
|
const getModule = method => {
|
|
@@ -1925,7 +2086,7 @@ const listen = async () => {
|
|
|
1925
2086
|
method: Auto()
|
|
1926
2087
|
});
|
|
1927
2088
|
handleIpc(ipc);
|
|
1928
|
-
listen$
|
|
2089
|
+
listen$2(ipc);
|
|
1929
2090
|
};
|
|
1930
2091
|
|
|
1931
2092
|
const main = async () => {
|