@lvce-editor/test-worker 3.20.0 → 3.21.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 +132 -41
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -420,6 +420,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
420
420
|
listen: listen$6,
|
|
421
421
|
wrap: wrap$e
|
|
422
422
|
};
|
|
423
|
+
const addListener = (emitter, type, callback) => {
|
|
424
|
+
if ('addEventListener' in emitter) {
|
|
425
|
+
emitter.addEventListener(type, callback);
|
|
426
|
+
} else {
|
|
427
|
+
emitter.on(type, callback);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
const removeListener = (emitter, type, callback) => {
|
|
431
|
+
if ('removeEventListener' in emitter) {
|
|
432
|
+
emitter.removeEventListener(type, callback);
|
|
433
|
+
} else {
|
|
434
|
+
emitter.off(type, callback);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
438
|
+
const {
|
|
439
|
+
resolve,
|
|
440
|
+
promise
|
|
441
|
+
} = withResolvers();
|
|
442
|
+
const listenerMap = Object.create(null);
|
|
443
|
+
const cleanup = value => {
|
|
444
|
+
for (const event of Object.keys(eventMap)) {
|
|
445
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
446
|
+
}
|
|
447
|
+
resolve(value);
|
|
448
|
+
};
|
|
449
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
450
|
+
const listener = event => {
|
|
451
|
+
cleanup({
|
|
452
|
+
type,
|
|
453
|
+
event
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
addListener(eventEmitter, event, listener);
|
|
457
|
+
listenerMap[event] = listener;
|
|
458
|
+
}
|
|
459
|
+
return promise;
|
|
460
|
+
};
|
|
461
|
+
const Message$1 = 3;
|
|
462
|
+
const create$5$1 = async ({
|
|
463
|
+
messagePort,
|
|
464
|
+
isMessagePortOpen
|
|
465
|
+
}) => {
|
|
466
|
+
if (!isMessagePort(messagePort)) {
|
|
467
|
+
throw new IpcError('port must be of type MessagePort');
|
|
468
|
+
}
|
|
469
|
+
if (isMessagePortOpen) {
|
|
470
|
+
return messagePort;
|
|
471
|
+
}
|
|
472
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
473
|
+
message: Message$1
|
|
474
|
+
});
|
|
475
|
+
messagePort.start();
|
|
476
|
+
const {
|
|
477
|
+
type,
|
|
478
|
+
event
|
|
479
|
+
} = await eventPromise;
|
|
480
|
+
if (type !== Message$1) {
|
|
481
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
482
|
+
}
|
|
483
|
+
if (event.data !== readyMessage) {
|
|
484
|
+
throw new IpcError('unexpected first message');
|
|
485
|
+
}
|
|
486
|
+
return messagePort;
|
|
487
|
+
};
|
|
488
|
+
const signal$1 = messagePort => {
|
|
489
|
+
messagePort.start();
|
|
490
|
+
};
|
|
491
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
492
|
+
getData = getData$2;
|
|
493
|
+
send(message) {
|
|
494
|
+
this._rawIpc.postMessage(message);
|
|
495
|
+
}
|
|
496
|
+
sendAndTransfer(message) {
|
|
497
|
+
const transfer = getTransferrables(message);
|
|
498
|
+
this._rawIpc.postMessage(message, transfer);
|
|
499
|
+
}
|
|
500
|
+
dispose() {
|
|
501
|
+
this._rawIpc.close();
|
|
502
|
+
}
|
|
503
|
+
onMessage(callback) {
|
|
504
|
+
this._rawIpc.addEventListener('message', callback);
|
|
505
|
+
}
|
|
506
|
+
onClose(callback) {}
|
|
507
|
+
}
|
|
508
|
+
const wrap$5 = messagePort => {
|
|
509
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
510
|
+
};
|
|
511
|
+
const IpcParentWithMessagePort$1 = {
|
|
512
|
+
__proto__: null,
|
|
513
|
+
create: create$5$1,
|
|
514
|
+
signal: signal$1,
|
|
515
|
+
wrap: wrap$5
|
|
516
|
+
};
|
|
423
517
|
|
|
424
518
|
const Two = '2.0';
|
|
425
519
|
const create$4 = (method, params) => {
|
|
@@ -774,7 +868,7 @@ const register = commandMap => {
|
|
|
774
868
|
const getCommand = key => {
|
|
775
869
|
return commands[key];
|
|
776
870
|
};
|
|
777
|
-
const execute$
|
|
871
|
+
const execute$2 = (command, ...args) => {
|
|
778
872
|
const fn = getCommand(command);
|
|
779
873
|
if (!fn) {
|
|
780
874
|
throw new Error(`command not found ${command}`);
|
|
@@ -801,19 +895,19 @@ const createRpc = ipc => {
|
|
|
801
895
|
};
|
|
802
896
|
return rpc;
|
|
803
897
|
};
|
|
804
|
-
const requiresSocket
|
|
898
|
+
const requiresSocket = () => {
|
|
805
899
|
return false;
|
|
806
900
|
};
|
|
807
|
-
const preparePrettyError
|
|
901
|
+
const preparePrettyError = error => {
|
|
808
902
|
return error;
|
|
809
903
|
};
|
|
810
|
-
const logError
|
|
904
|
+
const logError = () => {
|
|
811
905
|
// handled by renderer worker
|
|
812
906
|
};
|
|
813
907
|
const handleMessage = event => {
|
|
814
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket
|
|
815
|
-
const actualExecute = event?.target?.execute || execute$
|
|
816
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError
|
|
908
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
909
|
+
const actualExecute = event?.target?.execute || execute$2;
|
|
910
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
817
911
|
};
|
|
818
912
|
const handleIpc = ipc => {
|
|
819
913
|
if ('addEventListener' in ipc) {
|
|
@@ -831,6 +925,26 @@ const listen$1 = async (module, options) => {
|
|
|
831
925
|
const ipc = module.wrap(rawIpc);
|
|
832
926
|
return ipc;
|
|
833
927
|
};
|
|
928
|
+
const create$6 = async ({
|
|
929
|
+
commandMap,
|
|
930
|
+
messagePort,
|
|
931
|
+
isMessagePortOpen
|
|
932
|
+
}) => {
|
|
933
|
+
// TODO create a commandMap per rpc instance
|
|
934
|
+
register(commandMap);
|
|
935
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
936
|
+
messagePort,
|
|
937
|
+
isMessagePortOpen
|
|
938
|
+
});
|
|
939
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
940
|
+
handleIpc(ipc);
|
|
941
|
+
const rpc = createRpc(ipc);
|
|
942
|
+
return rpc;
|
|
943
|
+
};
|
|
944
|
+
const MessagePortRpcParent = {
|
|
945
|
+
__proto__: null,
|
|
946
|
+
create: create$6
|
|
947
|
+
};
|
|
834
948
|
const create$1 = async ({
|
|
835
949
|
commandMap
|
|
836
950
|
}) => {
|
|
@@ -974,8 +1088,6 @@ const getLocatorRpc = locator => {
|
|
|
974
1088
|
return Rpc;
|
|
975
1089
|
};
|
|
976
1090
|
|
|
977
|
-
// @ts-nocheck
|
|
978
|
-
|
|
979
1091
|
const Assert = {
|
|
980
1092
|
string(value, message) {
|
|
981
1093
|
if (typeof value !== 'string') {
|
|
@@ -994,7 +1106,6 @@ const expect$1 = locator => {
|
|
|
994
1106
|
} = getLocatorRpc(locator);
|
|
995
1107
|
return {
|
|
996
1108
|
async checkSingleElementCondition(fnName, options) {
|
|
997
|
-
Assert.string(fnName);
|
|
998
1109
|
// TODO add rpcId property to locator instead
|
|
999
1110
|
return invoke('TestFrameWork.checkSingleElementCondition', locator, fnName, options);
|
|
1000
1111
|
},
|
|
@@ -1055,7 +1166,7 @@ const expect$1 = locator => {
|
|
|
1055
1166
|
});
|
|
1056
1167
|
},
|
|
1057
1168
|
async toHaveCount(count) {
|
|
1058
|
-
Assert.number(count, 'count must be of type
|
|
1169
|
+
Assert.number(count, 'count must be of type number');
|
|
1059
1170
|
return this.checkMultiElementCondition('toHaveCount', {
|
|
1060
1171
|
count
|
|
1061
1172
|
});
|
|
@@ -1321,13 +1432,13 @@ const TestFrameWorkComponentBaseUrl = {
|
|
|
1321
1432
|
getBaseUrl
|
|
1322
1433
|
};
|
|
1323
1434
|
|
|
1324
|
-
const execute$
|
|
1435
|
+
const execute$1 = async (id, ...args) => {
|
|
1325
1436
|
return invoke(id, ...args);
|
|
1326
1437
|
};
|
|
1327
1438
|
|
|
1328
1439
|
const TestFrameWorkComponentCommand = {
|
|
1329
1440
|
__proto__: null,
|
|
1330
|
-
execute: execute$
|
|
1441
|
+
execute: execute$1
|
|
1331
1442
|
};
|
|
1332
1443
|
|
|
1333
1444
|
const selectItem$1 = async text => {
|
|
@@ -2247,16 +2358,6 @@ const waitForFirstEventEvent = async port => {
|
|
|
2247
2358
|
return firstEvent;
|
|
2248
2359
|
};
|
|
2249
2360
|
|
|
2250
|
-
const preparePrettyError = error => {
|
|
2251
|
-
return error;
|
|
2252
|
-
};
|
|
2253
|
-
const logError = () => {
|
|
2254
|
-
// ignore
|
|
2255
|
-
};
|
|
2256
|
-
const execute$1 = () => {};
|
|
2257
|
-
const requiresSocket = () => {
|
|
2258
|
-
return false;
|
|
2259
|
-
};
|
|
2260
2361
|
const createPortIpc = async webViewId => {
|
|
2261
2362
|
const {
|
|
2262
2363
|
port1,
|
|
@@ -2274,27 +2375,17 @@ const createPortIpc = async webViewId => {
|
|
|
2274
2375
|
if (firstEvent.data !== 'ready') {
|
|
2275
2376
|
throw new Error('unexpected first message');
|
|
2276
2377
|
}
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
send(message) {
|
|
2284
|
-
port1.postMessage(message);
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
return ipc;
|
|
2378
|
+
const rpc = await MessagePortRpcParent.create({
|
|
2379
|
+
messagePort: port1,
|
|
2380
|
+
commandMap: {},
|
|
2381
|
+
isMessagePortOpen: true
|
|
2382
|
+
});
|
|
2383
|
+
return rpc;
|
|
2288
2384
|
};
|
|
2289
2385
|
|
|
2290
2386
|
const fromId = async webViewId => {
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2293
|
-
invoke(method, ...params) {
|
|
2294
|
-
return invoke$1(ipc, method, ...params);
|
|
2295
|
-
}
|
|
2296
|
-
};
|
|
2297
|
-
set(webViewId, webViewRpc);
|
|
2387
|
+
const rpc = await createPortIpc(webViewId);
|
|
2388
|
+
set(webViewId, rpc);
|
|
2298
2389
|
return {
|
|
2299
2390
|
locator(selector, options) {
|
|
2300
2391
|
const baseLocator = create(selector, options);
|