@lvce-editor/test-worker 3.18.0 → 3.20.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.
@@ -430,10 +430,10 @@ const create$4 = (method, params) => {
430
430
  };
431
431
  };
432
432
  const callbacks = Object.create(null);
433
- const set$1 = (id, fn) => {
433
+ const set$2 = (id, fn) => {
434
434
  callbacks[id] = fn;
435
435
  };
436
- const get$1 = id => {
436
+ const get$2 = id => {
437
437
  return callbacks[id];
438
438
  };
439
439
  const remove = id => {
@@ -449,7 +449,7 @@ const registerPromise = () => {
449
449
  resolve,
450
450
  promise
451
451
  } = Promise.withResolvers();
452
- set$1(id, resolve);
452
+ set$2(id, resolve);
453
453
  return {
454
454
  id,
455
455
  promise
@@ -606,7 +606,7 @@ const warn = (...args) => {
606
606
  console.warn(...args);
607
607
  };
608
608
  const resolve = (id, response) => {
609
- const fn = get$1(id);
609
+ const fn = get$2(id);
610
610
  if (!fn) {
611
611
  console.log(response);
612
612
  warn(`callback ${id} may already be disposed`);
@@ -849,19 +849,19 @@ const WebWorkerRpcClient = {
849
849
  const RendererWorker = 1;
850
850
 
851
851
  const rpcs = Object.create(null);
852
- const set = (id, rpc) => {
852
+ const set$1 = (id, rpc) => {
853
853
  rpcs[id] = rpc;
854
854
  };
855
- const get = id => {
855
+ const get$1 = id => {
856
856
  return rpcs[id];
857
857
  };
858
858
 
859
859
  const invoke = (method, ...params) => {
860
- const rpc = get(RendererWorker);
860
+ const rpc = get$1(RendererWorker);
861
861
  return rpc.invoke(method, ...params);
862
862
  };
863
863
  const invokeAndTransfer = (method, ...params) => {
864
- const rpc = get(RendererWorker);
864
+ const rpc = get$1(RendererWorker);
865
865
  return rpc.invokeAndTransfer(method, ...params);
866
866
  };
867
867
 
@@ -959,6 +959,21 @@ const importTest = async url => {
959
959
  }
960
960
  };
961
961
 
962
+ const webViews = Object.create(null);
963
+ const set = (id, webView) => {
964
+ webViews[id] = webView;
965
+ };
966
+ const get = id => {
967
+ return webViews[id];
968
+ };
969
+
970
+ const getLocatorRpc = locator => {
971
+ if (locator.webViewId) {
972
+ return get(locator.webViewId);
973
+ }
974
+ return Rpc;
975
+ };
976
+
962
977
  // @ts-nocheck
963
978
 
964
979
  const Assert = {
@@ -976,7 +991,7 @@ const Assert = {
976
991
  const expect$1 = locator => {
977
992
  const {
978
993
  invoke
979
- } = locator.webView || Rpc;
994
+ } = getLocatorRpc(locator);
980
995
  return {
981
996
  async checkSingleElementCondition(fnName, options) {
982
997
  Assert.string(fnName);
@@ -1092,36 +1107,37 @@ const setMockRpc = mockRpc => {
1092
1107
  state.mockRpcs[mockRpc.name] = mockRpc;
1093
1108
  };
1094
1109
 
1095
- // @ts-nocheck
1110
+ const toButtonNumber = buttonType => {
1111
+ switch (buttonType) {
1112
+ case 'left':
1113
+ return 0;
1114
+ case 'middle':
1115
+ return 1;
1116
+ case 'right':
1117
+ return 2;
1118
+ default:
1119
+ throw new Error(`unsupported button type: ${buttonType}`);
1120
+ }
1121
+ };
1096
1122
 
1097
1123
  const create = (selector, options = {}) => {
1124
+ // @ts-ignore
1098
1125
  return new Locator(selector, options);
1099
1126
  };
1100
1127
  const Locator = function (selector, {
1101
1128
  nth = -1,
1102
1129
  hasText = ''
1103
1130
  } = {}) {
1131
+ // @ts-ignore
1104
1132
  this._selector = selector;
1133
+ // @ts-ignore
1105
1134
  this._nth = nth;
1135
+ // @ts-ignore
1106
1136
  this._hasText = hasText;
1107
1137
  };
1108
1138
  const performAction = async (locator, action, options) => {
1109
- const {
1110
- invoke
1111
- } = locator.webView || Rpc;
1112
- return invoke('TestFrameWork.performAction', locator, action, options);
1113
- };
1114
- const toButtonNumber = buttonType => {
1115
- switch (buttonType) {
1116
- case 'left':
1117
- return 0;
1118
- case 'middle':
1119
- return 1;
1120
- case 'right':
1121
- return 2;
1122
- default:
1123
- throw new Error(`unsupported button type: ${buttonType}`);
1124
- }
1139
+ const rpc = getLocatorRpc(locator);
1140
+ return rpc.invoke('TestFrameWork.performAction', locator, action, options);
1125
1141
  };
1126
1142
  Locator.prototype.click = async function ({
1127
1143
  button = 'left'
@@ -2278,13 +2294,13 @@ const fromId = async webViewId => {
2278
2294
  return invoke$1(ipc, method, ...params);
2279
2295
  }
2280
2296
  };
2297
+ set(webViewId, webViewRpc);
2281
2298
  return {
2282
2299
  locator(selector, options) {
2283
2300
  const baseLocator = create(selector, options);
2284
- baseLocator.webView = webViewRpc;
2301
+ baseLocator.webViewId = webViewId;
2285
2302
  return baseLocator;
2286
- },
2287
- expect: expect$1
2303
+ }
2288
2304
  };
2289
2305
  };
2290
2306
 
@@ -2376,7 +2392,7 @@ const listen = async () => {
2376
2392
  const rpc = await WebWorkerRpcClient.create({
2377
2393
  commandMap: commandMap
2378
2394
  });
2379
- set(RendererWorker, rpc);
2395
+ set$1(RendererWorker, rpc);
2380
2396
  };
2381
2397
 
2382
2398
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "3.18.0",
3
+ "version": "3.20.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "",