@lvce-editor/test-worker 4.14.0 → 4.16.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.
@@ -54,12 +54,12 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
- class AssertionError extends Error {
57
+ let AssertionError$1 = class AssertionError extends Error {
58
58
  constructor(message) {
59
59
  super(message);
60
60
  this.name = 'AssertionError';
61
61
  }
62
- }
62
+ };
63
63
  const getType = value => {
64
64
  switch (typeof value) {
65
65
  case 'number':
@@ -85,13 +85,13 @@ const getType = value => {
85
85
  const object = value => {
86
86
  const type = getType(value);
87
87
  if (type !== 'object') {
88
- throw new AssertionError('expected value to be of type object');
88
+ throw new AssertionError$1('expected value to be of type object');
89
89
  }
90
90
  };
91
- const string = value => {
91
+ const string$1 = value => {
92
92
  const type = getType(value);
93
93
  if (type !== 'string') {
94
- throw new AssertionError('expected value to be of type string');
94
+ throw new AssertionError$1('expected value to be of type string');
95
95
  }
96
96
  };
97
97
 
@@ -960,6 +960,10 @@ const WebWorkerRpcClient = {
960
960
  create: create$1
961
961
  };
962
962
 
963
+ const formatDuration = duration => {
964
+ return duration.toFixed(2) + 'ms';
965
+ };
966
+
963
967
  const RendererWorker = 1;
964
968
 
965
969
  const rpcs = Object.create(null);
@@ -985,13 +989,6 @@ const Rpc = {
985
989
  invokeAndTransfer
986
990
  };
987
991
 
988
- const Fail = 'fail';
989
- const Pass = 'pass';
990
-
991
- const now = () => {
992
- return performance.now();
993
- };
994
-
995
992
  const printError = error => {
996
993
  if (error && error.constructor.name === 'AssertionError') {
997
994
  console.error(error.message);
@@ -999,6 +996,7 @@ const printError = error => {
999
996
  console.error(error);
1000
997
  }
1001
998
  };
999
+
1002
1000
  const stringifyError = error => {
1003
1001
  if (!error) {
1004
1002
  return `${error}`;
@@ -1008,9 +1006,14 @@ const stringifyError = error => {
1008
1006
  }
1009
1007
  return `${error.message}`;
1010
1008
  };
1011
- const formatDuration = duration => {
1012
- return duration.toFixed(2) + 'ms';
1009
+
1010
+ const Fail = 'fail';
1011
+ const Pass = 'pass';
1012
+
1013
+ const now = () => {
1014
+ return performance.now();
1013
1015
  };
1016
+
1014
1017
  const executeTest = async (name, fn, globals = {}) => {
1015
1018
  let _error;
1016
1019
  let _start;
@@ -1031,12 +1034,10 @@ const executeTest = async (name, fn, globals = {}) => {
1031
1034
  console.error(error);
1032
1035
  return;
1033
1036
  }
1034
- // @ts-ignore
1035
1037
  _error = stringifyError(error);
1036
1038
  if (!(error instanceof VError)) {
1037
1039
  error = new VError(error, `Test failed: ${name}`);
1038
1040
  }
1039
- // @ts-ignore
1040
1041
  printError(error);
1041
1042
  }
1042
1043
  let state;
@@ -1073,6 +1074,13 @@ const importTest = async url => {
1073
1074
  }
1074
1075
  };
1075
1076
 
1077
+ class AssertionError extends Error {
1078
+ constructor(message) {
1079
+ super(message);
1080
+ this.name = 'AssertionError';
1081
+ }
1082
+ }
1083
+
1076
1084
  const webViews = Object.create(null);
1077
1085
  const set = (id, webView) => {
1078
1086
  webViews[id] = webView;
@@ -1088,29 +1096,181 @@ const getLocatorRpc = locator => {
1088
1096
  return Rpc;
1089
1097
  };
1090
1098
 
1091
- const Assert = {
1092
- string(value, message) {
1093
- if (typeof value !== 'string') {
1094
- throw new TypeError(message);
1095
- }
1096
- },
1097
- number(value, message) {
1098
- if (typeof value !== 'number' || Number.isNaN(value)) {
1099
- throw new TypeError(message);
1100
- }
1101
- }
1102
- };
1103
- const expect$1 = locator => {
1099
+ const locatorInvoke = (locator, method, ...params) => {
1100
+ object(locator);
1101
+ string$1(method);
1104
1102
  const {
1105
1103
  invoke
1106
1104
  } = getLocatorRpc(locator);
1105
+ return invoke(method, ...params);
1106
+ };
1107
+
1108
+ const printLocator = locator => {
1109
+ if (locator._nth !== -1) {
1110
+ return `${locator._selector}:nth(${locator._nth})`;
1111
+ }
1112
+ if (locator._hasText) {
1113
+ return `${locator._selector} "${locator._hasText}"`;
1114
+ }
1115
+ return `${locator._selector}`;
1116
+ };
1117
+
1118
+ const toBeVisible = locator => {
1119
+ return `expected selector to be visible ${locator._selector}`;
1120
+ };
1121
+ const toHaveValue = (locator, {
1122
+ value
1123
+ }) => {
1124
+ return `expected selector ${locator._selector} to have value ${value}`;
1125
+ };
1126
+ const toHaveText = async (locator, options) => {
1127
+ const locatorString = printLocator(locator);
1128
+ const {
1129
+ wasFound,
1130
+ actual
1131
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveText', locator, options);
1132
+ const {
1133
+ text
1134
+ } = options;
1135
+ if (!wasFound) {
1136
+ return `expected selector ${locatorString} to have text "${text}" element was not found`;
1137
+ }
1138
+ return `expected selector ${locatorString} to have text "${text}" but was "${actual}"`;
1139
+ };
1140
+ const toHaveAttribute = async (locator, options) => {
1141
+ const locatorString = printLocator(locator);
1142
+ const {
1143
+ wasFound,
1144
+ actual
1145
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveAttribute', locator, options);
1146
+ const {
1147
+ key,
1148
+ value
1149
+ } = options;
1150
+ if (!wasFound) {
1151
+ return `expected ${locatorString} to have attribute ${key} ${value} but element was not found`;
1152
+ }
1153
+ return `expected ${locatorString} to have attribute ${key} ${value} but was ${actual}`;
1154
+ };
1155
+ const toHaveCount = async (locator, {
1156
+ count
1157
+ }) => {
1158
+ const locatorString = printLocator(locator);
1159
+ const {
1160
+ actual
1161
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveCount', locator);
1162
+ return `expected ${locatorString} to have count ${count} but was ${actual}`;
1163
+ };
1164
+ const toBeFocused = async locator => {
1165
+ const locatorString = printLocator(locator);
1166
+ const {
1167
+ actual
1168
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toBeFocused', locator);
1169
+ return `expected ${locatorString} to be focused but active element is ${actual}`;
1170
+ };
1171
+ const toHaveClass = async (locator, options) => {
1172
+ const locatorString = printLocator(locator);
1173
+ const {
1174
+ wasFound
1175
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveClass', locator, options);
1176
+ const {
1177
+ className
1178
+ } = options;
1179
+ if (!wasFound) {
1180
+ return `expected ${locatorString} to have class ${className} but element was not found`;
1181
+ }
1182
+ return `expected ${locatorString} to have class ${className}`;
1183
+ };
1184
+ const toHaveId = async (locator, options) => {
1185
+ const {
1186
+ wasFound,
1187
+ actual
1188
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveId', locator, options);
1189
+ const locatorString = printLocator(locator);
1190
+ const {
1191
+ id
1192
+ } = options;
1193
+ if (!wasFound) {
1194
+ return `expected ${locatorString} to have id ${id} but element was not found`;
1195
+ }
1196
+ return `expected ${locatorString} to have id ${id} but was ${actual}`;
1197
+ };
1198
+ const toBeHidden = locator => {
1199
+ const locatorString = printLocator(locator);
1200
+ return `expected ${locatorString} to be hidden`;
1201
+ };
1202
+ const toHaveCss = async (locator, options) => {
1203
+ const {
1204
+ wasFound,
1205
+ actual
1206
+ } = await locatorInvoke(locator, 'TestFrameWork.checkConditionError', 'toHaveCss', locator, options);
1207
+ const locatorString = printLocator(locator);
1208
+ const {
1209
+ key,
1210
+ value
1211
+ } = options;
1212
+ if (!wasFound) {
1213
+ return `expected ${locatorString} to have css ${key} ${value} but element was not found`;
1214
+ }
1215
+ return `expected ${locatorString} to have css ${key} ${value} but was ${actual}`;
1216
+ };
1217
+
1218
+ const getFunction = fnName => {
1219
+ switch (fnName) {
1220
+ case 'toBeVisible':
1221
+ return toBeVisible;
1222
+ case 'toHaveValue':
1223
+ return toHaveValue;
1224
+ case 'toHaveText':
1225
+ return toHaveText;
1226
+ case 'toHaveAttribute':
1227
+ return toHaveAttribute;
1228
+ case 'toHaveCount':
1229
+ return toHaveCount;
1230
+ case 'toBeFocused':
1231
+ return toBeFocused;
1232
+ case 'toHaveId':
1233
+ return toHaveId;
1234
+ case 'toBeHidden':
1235
+ return toBeHidden;
1236
+ case 'toHaveCss':
1237
+ return toHaveCss;
1238
+ case 'toHaveClass':
1239
+ return toHaveClass;
1240
+ default:
1241
+ throw new Error(`unexpected function name ${fnName}`);
1242
+ }
1243
+ };
1244
+
1245
+ const string = (value, message) => {
1246
+ if (typeof value !== 'string') {
1247
+ throw new TypeError(message);
1248
+ }
1249
+ };
1250
+ const number = (value, message) => {
1251
+ if (typeof value !== 'number' || Number.isNaN(value)) {
1252
+ throw new TypeError(message);
1253
+ }
1254
+ };
1255
+
1256
+ const expect$1 = locator => {
1107
1257
  return {
1108
1258
  async checkSingleElementCondition(fnName, options) {
1109
1259
  // TODO add rpcId property to locator instead
1110
- return invoke('TestFrameWork.checkSingleElementCondition', locator, fnName, options);
1260
+ const result = await locatorInvoke(locator, 'TestFrameWork.checkSingleElementCondition', locator, fnName, options);
1261
+ if (result && result.error) {
1262
+ const fn = getFunction(fnName);
1263
+ const errorInfo = await fn(locator, options);
1264
+ throw new AssertionError(errorInfo);
1265
+ }
1111
1266
  },
1112
1267
  async checkMultiElementCondition(fnName, options) {
1113
- return invoke('TestFrameWork.checkMultiElementCondition', locator, fnName, options);
1268
+ const result = await locatorInvoke(locator, 'TestFrameWork.checkMultiElementCondition', locator, fnName, options);
1269
+ if (result && result.error) {
1270
+ const fn = getFunction(fnName);
1271
+ const errorInfo = await fn(locator, options);
1272
+ throw new AssertionError(errorInfo);
1273
+ }
1114
1274
  },
1115
1275
  async toBeVisible() {
1116
1276
  if (this.negated) {
@@ -1119,19 +1279,19 @@ const expect$1 = locator => {
1119
1279
  return this.checkSingleElementCondition('toBeVisible', {});
1120
1280
  },
1121
1281
  async toHaveText(text) {
1122
- Assert.string(text, 'text must be of type string');
1282
+ string(text, 'text must be of type string');
1123
1283
  return this.checkSingleElementCondition('toHaveText', {
1124
1284
  text
1125
1285
  });
1126
1286
  },
1127
1287
  async toContainText(text) {
1128
- Assert.string(text, 'text must be of type string');
1288
+ string(text, 'text must be of type string');
1129
1289
  return this.checkSingleElementCondition('toContainText', {
1130
1290
  text
1131
1291
  });
1132
1292
  },
1133
1293
  async toHaveValue(value) {
1134
- Assert.string(value, 'value must be of type string');
1294
+ string(value, 'value must be of type string');
1135
1295
  return this.checkSingleElementCondition('toHaveValue', {
1136
1296
  value
1137
1297
  });
@@ -1146,7 +1306,7 @@ const expect$1 = locator => {
1146
1306
  });
1147
1307
  },
1148
1308
  async toHaveAttribute(key, value) {
1149
- Assert.string(key, 'key must be of type string');
1309
+ string(key, 'key must be of type string');
1150
1310
  // Assert.string(value, 'value must be of type string')
1151
1311
  return this.checkSingleElementCondition('toHaveAttribute', {
1152
1312
  key,
@@ -1154,19 +1314,19 @@ const expect$1 = locator => {
1154
1314
  });
1155
1315
  },
1156
1316
  async toHaveClass(className) {
1157
- Assert.string(className, 'className must be of type string');
1317
+ string(className, 'className must be of type string');
1158
1318
  return this.checkSingleElementCondition('toHaveClass', {
1159
1319
  className
1160
1320
  });
1161
1321
  },
1162
1322
  async toHaveId(id) {
1163
- Assert.string(id, 'id must be of type string');
1323
+ string(id, 'id must be of type string');
1164
1324
  return this.checkSingleElementCondition('toHaveId', {
1165
1325
  id
1166
1326
  });
1167
1327
  },
1168
1328
  async toHaveCount(count) {
1169
- Assert.number(count, 'count must be of type number');
1329
+ number(count, 'count must be of type number');
1170
1330
  return this.checkMultiElementCondition('toHaveCount', {
1171
1331
  count
1172
1332
  });
@@ -1214,7 +1374,7 @@ const getTests = () => {
1214
1374
  };
1215
1375
  const setMockRpc = mockRpc => {
1216
1376
  object(mockRpc);
1217
- string(mockRpc.name);
1377
+ string$1(mockRpc.name);
1218
1378
  state.mockRpcs[mockRpc.name] = mockRpc;
1219
1379
  };
1220
1380
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "4.14.0",
3
+ "version": "4.16.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",