@lvce-editor/test-worker 3.19.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 +160 -56
- 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) => {
|
|
@@ -430,10 +524,10 @@ const create$4 = (method, params) => {
|
|
|
430
524
|
};
|
|
431
525
|
};
|
|
432
526
|
const callbacks = Object.create(null);
|
|
433
|
-
const set$
|
|
527
|
+
const set$2 = (id, fn) => {
|
|
434
528
|
callbacks[id] = fn;
|
|
435
529
|
};
|
|
436
|
-
const get$
|
|
530
|
+
const get$2 = id => {
|
|
437
531
|
return callbacks[id];
|
|
438
532
|
};
|
|
439
533
|
const remove = id => {
|
|
@@ -449,7 +543,7 @@ const registerPromise = () => {
|
|
|
449
543
|
resolve,
|
|
450
544
|
promise
|
|
451
545
|
} = Promise.withResolvers();
|
|
452
|
-
set$
|
|
546
|
+
set$2(id, resolve);
|
|
453
547
|
return {
|
|
454
548
|
id,
|
|
455
549
|
promise
|
|
@@ -606,7 +700,7 @@ const warn = (...args) => {
|
|
|
606
700
|
console.warn(...args);
|
|
607
701
|
};
|
|
608
702
|
const resolve = (id, response) => {
|
|
609
|
-
const fn = get$
|
|
703
|
+
const fn = get$2(id);
|
|
610
704
|
if (!fn) {
|
|
611
705
|
console.log(response);
|
|
612
706
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -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
|
}) => {
|
|
@@ -849,19 +963,19 @@ const WebWorkerRpcClient = {
|
|
|
849
963
|
const RendererWorker = 1;
|
|
850
964
|
|
|
851
965
|
const rpcs = Object.create(null);
|
|
852
|
-
const set = (id, rpc) => {
|
|
966
|
+
const set$1 = (id, rpc) => {
|
|
853
967
|
rpcs[id] = rpc;
|
|
854
968
|
};
|
|
855
|
-
const get = id => {
|
|
969
|
+
const get$1 = id => {
|
|
856
970
|
return rpcs[id];
|
|
857
971
|
};
|
|
858
972
|
|
|
859
973
|
const invoke = (method, ...params) => {
|
|
860
|
-
const rpc = get(RendererWorker);
|
|
974
|
+
const rpc = get$1(RendererWorker);
|
|
861
975
|
return rpc.invoke(method, ...params);
|
|
862
976
|
};
|
|
863
977
|
const invokeAndTransfer = (method, ...params) => {
|
|
864
|
-
const rpc = get(RendererWorker);
|
|
978
|
+
const rpc = get$1(RendererWorker);
|
|
865
979
|
return rpc.invokeAndTransfer(method, ...params);
|
|
866
980
|
};
|
|
867
981
|
|
|
@@ -959,7 +1073,20 @@ const importTest = async url => {
|
|
|
959
1073
|
}
|
|
960
1074
|
};
|
|
961
1075
|
|
|
962
|
-
|
|
1076
|
+
const webViews = Object.create(null);
|
|
1077
|
+
const set = (id, webView) => {
|
|
1078
|
+
webViews[id] = webView;
|
|
1079
|
+
};
|
|
1080
|
+
const get = id => {
|
|
1081
|
+
return webViews[id];
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
const getLocatorRpc = locator => {
|
|
1085
|
+
if (locator.webViewId) {
|
|
1086
|
+
return get(locator.webViewId);
|
|
1087
|
+
}
|
|
1088
|
+
return Rpc;
|
|
1089
|
+
};
|
|
963
1090
|
|
|
964
1091
|
const Assert = {
|
|
965
1092
|
string(value, message) {
|
|
@@ -976,10 +1103,9 @@ const Assert = {
|
|
|
976
1103
|
const expect$1 = locator => {
|
|
977
1104
|
const {
|
|
978
1105
|
invoke
|
|
979
|
-
} = locator
|
|
1106
|
+
} = getLocatorRpc(locator);
|
|
980
1107
|
return {
|
|
981
1108
|
async checkSingleElementCondition(fnName, options) {
|
|
982
|
-
Assert.string(fnName);
|
|
983
1109
|
// TODO add rpcId property to locator instead
|
|
984
1110
|
return invoke('TestFrameWork.checkSingleElementCondition', locator, fnName, options);
|
|
985
1111
|
},
|
|
@@ -1040,7 +1166,7 @@ const expect$1 = locator => {
|
|
|
1040
1166
|
});
|
|
1041
1167
|
},
|
|
1042
1168
|
async toHaveCount(count) {
|
|
1043
|
-
Assert.number(count, 'count must be of type
|
|
1169
|
+
Assert.number(count, 'count must be of type number');
|
|
1044
1170
|
return this.checkMultiElementCondition('toHaveCount', {
|
|
1045
1171
|
count
|
|
1046
1172
|
});
|
|
@@ -1121,10 +1247,8 @@ const Locator = function (selector, {
|
|
|
1121
1247
|
this._hasText = hasText;
|
|
1122
1248
|
};
|
|
1123
1249
|
const performAction = async (locator, action, options) => {
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
} = locator.webView || Rpc;
|
|
1127
|
-
return invoke('TestFrameWork.performAction', locator, action, options);
|
|
1250
|
+
const rpc = getLocatorRpc(locator);
|
|
1251
|
+
return rpc.invoke('TestFrameWork.performAction', locator, action, options);
|
|
1128
1252
|
};
|
|
1129
1253
|
Locator.prototype.click = async function ({
|
|
1130
1254
|
button = 'left'
|
|
@@ -1308,13 +1432,13 @@ const TestFrameWorkComponentBaseUrl = {
|
|
|
1308
1432
|
getBaseUrl
|
|
1309
1433
|
};
|
|
1310
1434
|
|
|
1311
|
-
const execute$
|
|
1435
|
+
const execute$1 = async (id, ...args) => {
|
|
1312
1436
|
return invoke(id, ...args);
|
|
1313
1437
|
};
|
|
1314
1438
|
|
|
1315
1439
|
const TestFrameWorkComponentCommand = {
|
|
1316
1440
|
__proto__: null,
|
|
1317
|
-
execute: execute$
|
|
1441
|
+
execute: execute$1
|
|
1318
1442
|
};
|
|
1319
1443
|
|
|
1320
1444
|
const selectItem$1 = async text => {
|
|
@@ -2234,16 +2358,6 @@ const waitForFirstEventEvent = async port => {
|
|
|
2234
2358
|
return firstEvent;
|
|
2235
2359
|
};
|
|
2236
2360
|
|
|
2237
|
-
const preparePrettyError = error => {
|
|
2238
|
-
return error;
|
|
2239
|
-
};
|
|
2240
|
-
const logError = () => {
|
|
2241
|
-
// ignore
|
|
2242
|
-
};
|
|
2243
|
-
const execute$1 = () => {};
|
|
2244
|
-
const requiresSocket = () => {
|
|
2245
|
-
return false;
|
|
2246
|
-
};
|
|
2247
2361
|
const createPortIpc = async webViewId => {
|
|
2248
2362
|
const {
|
|
2249
2363
|
port1,
|
|
@@ -2261,33 +2375,23 @@ const createPortIpc = async webViewId => {
|
|
|
2261
2375
|
if (firstEvent.data !== 'ready') {
|
|
2262
2376
|
throw new Error('unexpected first message');
|
|
2263
2377
|
}
|
|
2264
|
-
const
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
send(message) {
|
|
2271
|
-
port1.postMessage(message);
|
|
2272
|
-
}
|
|
2273
|
-
};
|
|
2274
|
-
return ipc;
|
|
2378
|
+
const rpc = await MessagePortRpcParent.create({
|
|
2379
|
+
messagePort: port1,
|
|
2380
|
+
commandMap: {},
|
|
2381
|
+
isMessagePortOpen: true
|
|
2382
|
+
});
|
|
2383
|
+
return rpc;
|
|
2275
2384
|
};
|
|
2276
2385
|
|
|
2277
2386
|
const fromId = async webViewId => {
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2280
|
-
invoke(method, ...params) {
|
|
2281
|
-
return invoke$1(ipc, method, ...params);
|
|
2282
|
-
}
|
|
2283
|
-
};
|
|
2387
|
+
const rpc = await createPortIpc(webViewId);
|
|
2388
|
+
set(webViewId, rpc);
|
|
2284
2389
|
return {
|
|
2285
2390
|
locator(selector, options) {
|
|
2286
2391
|
const baseLocator = create(selector, options);
|
|
2287
|
-
baseLocator.
|
|
2392
|
+
baseLocator.webViewId = webViewId;
|
|
2288
2393
|
return baseLocator;
|
|
2289
|
-
}
|
|
2290
|
-
expect: expect$1
|
|
2394
|
+
}
|
|
2291
2395
|
};
|
|
2292
2396
|
};
|
|
2293
2397
|
|
|
@@ -2379,7 +2483,7 @@ const listen = async () => {
|
|
|
2379
2483
|
const rpc = await WebWorkerRpcClient.create({
|
|
2380
2484
|
commandMap: commandMap
|
|
2381
2485
|
});
|
|
2382
|
-
set(RendererWorker, rpc);
|
|
2486
|
+
set$1(RendererWorker, rpc);
|
|
2383
2487
|
};
|
|
2384
2488
|
|
|
2385
2489
|
const main = async () => {
|