@wdio/utils 7.20.3 → 7.20.8-alpha.504

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.
Files changed (36) hide show
  1. package/build/constants.d.ts +75 -75
  2. package/build/constants.d.ts.map +1 -1
  3. package/build/constants.js +1 -4
  4. package/build/envDetector.js +5 -13
  5. package/build/index.d.ts +11 -11
  6. package/build/index.d.ts.map +1 -1
  7. package/build/index.js +21 -39
  8. package/build/initialisePlugin.d.ts +2 -2
  9. package/build/initialisePlugin.d.ts.map +1 -1
  10. package/build/initialisePlugin.js +7 -13
  11. package/build/initialiseServices.d.ts +3 -3
  12. package/build/initialiseServices.d.ts.map +1 -1
  13. package/build/initialiseServices.js +9 -17
  14. package/build/monad.d.ts +4 -1
  15. package/build/monad.d.ts.map +1 -1
  16. package/build/monad.js +18 -17
  17. package/build/shim.d.ts +1 -27
  18. package/build/shim.d.ts.map +1 -1
  19. package/build/shim.js +18 -184
  20. package/build/test-framework/errorHandler.js +1 -5
  21. package/build/test-framework/index.d.ts +2 -2
  22. package/build/test-framework/index.d.ts.map +1 -1
  23. package/build/test-framework/index.js +3 -7
  24. package/build/test-framework/testFnWrapper.d.ts +1 -1
  25. package/build/test-framework/testFnWrapper.d.ts.map +1 -1
  26. package/build/test-framework/testFnWrapper.js +10 -27
  27. package/build/test-framework/testInterfaceWrapper.d.ts +3 -4
  28. package/build/test-framework/testInterfaceWrapper.d.ts.map +1 -1
  29. package/build/test-framework/testInterfaceWrapper.js +19 -26
  30. package/build/test-framework/types.d.ts +1 -2
  31. package/build/test-framework/types.d.ts.map +1 -1
  32. package/build/test-framework/types.js +1 -2
  33. package/build/utils.d.ts +2 -2
  34. package/build/utils.d.ts.map +1 -1
  35. package/build/utils.js +26 -48
  36. package/package.json +11 -8
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/build/utils.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare function getArgumentType(arg: any): "string" | "number" | "bigint
44
44
  * @param {string} name of package
45
45
  * @return {object} package content
46
46
  */
47
- export declare function safeRequire(name: string): Services.ServicePlugin | null;
47
+ export declare function safeImport(name: string): Promise<Services.ServicePlugin | null>;
48
48
  /**
49
49
  * is function async
50
50
  * @param {Function} fn function to check
@@ -67,7 +67,7 @@ export declare function isBase64(str: string): boolean;
67
67
  * @param {String} file file to check access for
68
68
  * @return true if file can be accessed
69
69
  */
70
- export declare const canAccess: (file: string) => boolean;
70
+ export declare const canAccess: (file?: string) => boolean;
71
71
  /**
72
72
  * sleep
73
73
  * @param {number=0} ms number in ms to sleep
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,aAAa,CAAA;AAMpD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE;IAAE,sBAAsB,CAAC,EAAE;QAAE,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,QAsCzH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UA+BrE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAE,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;EAWpF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,WA8B/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,GAAG,wGAExC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,GAAG,IAAI,CAoCxE;AAED;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B,cAAc,CAAE,IAAI,EAAE,GAAG,EAAE,SAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,WAanC;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,UAAW,MAAM,YAWtC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,mCAAoD,CAAA"}
package/build/utils.js CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sleep = exports.canAccess = exports.isBase64 = exports.filterSpecArgs = exports.isFunctionAsync = exports.safeRequire = exports.getArgumentType = exports.isValidParameter = exports.transformCommandLogResult = exports.commandCallStructure = exports.overwriteElementCommands = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
1
+ import fs from 'node:fs';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
9
5
  const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"';
10
6
  const SCRIPT_PLACEHOLDER = '"<Script[base64]>"';
11
7
  const REGEX_SCRIPT_NAME = /return \(function (\w+)/;
@@ -13,7 +9,7 @@ const REGEX_SCRIPT_NAME = /return \(function (\w+)/;
13
9
  * overwrite native element commands with user defined
14
10
  * @param {object} propertiesObject propertiesObject
15
11
  */
16
- function overwriteElementCommands(propertiesObject) {
12
+ export function overwriteElementCommands(propertiesObject) {
17
13
  const elementOverrides = propertiesObject['__elementOverrides__'] ? propertiesObject['__elementOverrides__'].value : {};
18
14
  for (const [commandName, userDefinedCommand] of Object.entries(elementOverrides)) {
19
15
  if (typeof userDefinedCommand !== 'function') {
@@ -45,12 +41,11 @@ function overwriteElementCommands(propertiesObject) {
45
41
  delete propertiesObject['__elementOverrides__'];
46
42
  propertiesObject['__elementOverrides__'] = { value: {} };
47
43
  }
48
- exports.overwriteElementCommands = overwriteElementCommands;
49
44
  /**
50
45
  * get command call structure
51
46
  * (for logging purposes)
52
47
  */
53
- function commandCallStructure(commandName, args) {
48
+ export function commandCallStructure(commandName, args) {
54
49
  const callArgs = args.map((arg) => {
55
50
  if (typeof arg === 'string' && (arg.startsWith('!function(') || arg.startsWith('return (function'))) {
56
51
  arg = '<fn>';
@@ -84,13 +79,12 @@ function commandCallStructure(commandName, args) {
84
79
  }).join(', ');
85
80
  return `${commandName}(${callArgs})`;
86
81
  }
87
- exports.commandCallStructure = commandCallStructure;
88
82
  /**
89
83
  * transforms WebDriver result for log stream to avoid unnecessary long
90
84
  * result strings e.g. if it contains a screenshot
91
85
  * @param {Object} result WebDriver response body
92
86
  */
93
- function transformCommandLogResult(result) {
87
+ export function transformCommandLogResult(result) {
94
88
  if (typeof result.file === 'string' && isBase64(result.file)) {
95
89
  return SCREENSHOT_REPLACEMENT;
96
90
  }
@@ -101,9 +95,11 @@ function transformCommandLogResult(result) {
101
95
  const newScript = result.script.match(REGEX_SCRIPT_NAME)[1];
102
96
  return { ...result, script: `${newScript}(...) [${Buffer.byteLength(result.script, 'utf-8')} bytes]` };
103
97
  }
98
+ else if (typeof result.script === 'string' && result.script.startsWith('!function(')) {
99
+ return { ...result, script: `<minified function> [${Buffer.byteLength(result.script, 'utf-8')} bytes]` };
100
+ }
104
101
  return result;
105
102
  }
106
- exports.transformCommandLogResult = transformCommandLogResult;
107
103
  /**
108
104
  * checks if command argument is valid according to specificiation
109
105
  *
@@ -111,7 +107,7 @@ exports.transformCommandLogResult = transformCommandLogResult;
111
107
  * @param {Object} expectedType parameter type (e.g. `number`, `string[]` or `(number|string)`)
112
108
  * @return {Boolean} true if argument is valid
113
109
  */
114
- function isValidParameter(arg, expectedType) {
110
+ export function isValidParameter(arg, expectedType) {
115
111
  let shouldBeArray = false;
116
112
  if (expectedType.slice(-2) === '[]') {
117
113
  expectedType = expectedType.slice(0, -2);
@@ -139,23 +135,20 @@ function isValidParameter(arg, expectedType) {
139
135
  }
140
136
  return true;
141
137
  }
142
- exports.isValidParameter = isValidParameter;
143
138
  /**
144
139
  * get type of command argument
145
140
  */
146
- function getArgumentType(arg) {
141
+ export function getArgumentType(arg) {
147
142
  return arg === null ? 'null' : typeof arg;
148
143
  }
149
- exports.getArgumentType = getArgumentType;
150
144
  /**
151
145
  * Allows to safely require a package, it only throws if the package was found
152
146
  * but failed to load due to syntax errors
153
147
  * @param {string} name of package
154
148
  * @return {object} package content
155
149
  */
156
- function safeRequire(name) {
157
- var _a, _b, _c;
158
- let requirePath;
150
+ export async function safeImport(name) {
151
+ let requirePath = name;
159
152
  try {
160
153
  /**
161
154
  * Check if cli command was called from local directory, if not require
@@ -165,57 +158,45 @@ function safeRequire(name) {
165
158
  * also allows to link the package to a random place and have plugins
166
159
  * imported correctly (for dev purposes).
167
160
  */
168
- const localNodeModules = path_1.default.join(process.cwd(), '/node_modules');
169
161
  /* istanbul ignore if */
170
- if (!((_a = require === null || require === void 0 ? void 0 : require.main) === null || _a === void 0 ? void 0 : _a.paths.includes(localNodeModules))) {
171
- (_b = require === null || require === void 0 ? void 0 : require.main) === null || _b === void 0 ? void 0 : _b.paths.push(localNodeModules);
172
- /**
173
- * don't set requireOpts when running unit tests as it
174
- * confuses Jest require magic
175
- */
176
- const requireOpts = process.env.JEST_WORKER_ID
177
- ? {}
178
- : { paths: (_c = require === null || require === void 0 ? void 0 : require.main) === null || _c === void 0 ? void 0 : _c.paths };
179
- requirePath = require.resolve(name, requireOpts);
180
- }
181
- else {
182
- requirePath = require.resolve(name);
162
+ if (require.resolve) {
163
+ requirePath = await require.resolve(name);
164
+ if (!requirePath.startsWith('file://')) {
165
+ requirePath = pathToFileURL(requirePath).href;
166
+ }
183
167
  }
184
168
  }
185
169
  catch (err) {
186
170
  return null;
187
171
  }
188
172
  try {
189
- return require(requirePath);
173
+ return await import(requirePath);
190
174
  }
191
175
  catch (e) {
192
176
  throw new Error(`Couldn't initialise "${name}".\n${e.stack}`);
193
177
  }
194
178
  }
195
- exports.safeRequire = safeRequire;
196
179
  /**
197
180
  * is function async
198
181
  * @param {Function} fn function to check
199
182
  * @return {Boolean} true provided function is async
200
183
  */
201
- function isFunctionAsync(fn) {
184
+ export function isFunctionAsync(fn) {
202
185
  return (fn.constructor && fn.constructor.name === 'AsyncFunction') || fn.name === 'async';
203
186
  }
204
- exports.isFunctionAsync = isFunctionAsync;
205
187
  /**
206
188
  * filter out arguments passed to specFn & hookFn, don't allow callbacks
207
189
  * as there is no need for user to call e.g. `done()`
208
190
  */
209
- function filterSpecArgs(args) {
191
+ export function filterSpecArgs(args) {
210
192
  return args.filter((arg) => typeof arg !== 'function');
211
193
  }
212
- exports.filterSpecArgs = filterSpecArgs;
213
194
  /**
214
195
  * checks if provided string is Base64
215
196
  * @param {String} str string in base64 to check
216
197
  * @return {Boolean} true if the provided string is Base64
217
198
  */
218
- function isBase64(str) {
199
+ export function isBase64(str) {
219
200
  var notBase64 = new RegExp('[^A-Z0-9+\\/=]', 'i');
220
201
  if (typeof str !== 'string') {
221
202
  throw new Error('Expected string but received invalid type.');
@@ -229,28 +210,25 @@ function isBase64(str) {
229
210
  firstPaddingChar === len - 1 ||
230
211
  (firstPaddingChar === len - 2 && str[len - 1] === '=');
231
212
  }
232
- exports.isBase64 = isBase64;
233
213
  /**
234
214
  * Helper utility to check file access
235
215
  * @param {String} file file to check access for
236
216
  * @return true if file can be accessed
237
217
  */
238
- const canAccess = (file) => {
218
+ export const canAccess = (file) => {
239
219
  if (!file) {
240
220
  return false;
241
221
  }
242
222
  try {
243
- fs_1.default.accessSync(file);
223
+ fs.accessSync(file);
244
224
  return true;
245
225
  }
246
226
  catch (err) {
247
227
  return false;
248
228
  }
249
229
  };
250
- exports.canAccess = canAccess;
251
230
  /**
252
231
  * sleep
253
232
  * @param {number=0} ms number in ms to sleep
254
233
  */
255
- const sleep = (ms = 0) => new Promise((r) => setTimeout(r, ms));
256
- exports.sleep = sleep;
234
+ export const sleep = (ms = 0) => new Promise((r) => setTimeout(r, ms));
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@wdio/utils",
3
- "version": "7.20.3",
3
+ "version": "7.20.8-alpha.504+428a9d729",
4
4
  "description": "A WDIO helper utility to provide several utility functions used across the project.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-utils",
7
7
  "license": "MIT",
8
- "main": "./build/index",
8
+ "type": "module",
9
+ "exports": "./build/index.js",
10
+ "types": "./build/index.d.ts",
11
+ "typeScriptVersion": "3.8.3",
9
12
  "engines": {
10
- "node": ">=12.0.0"
13
+ "node": "^16.13 || >=18"
11
14
  },
12
15
  "repository": {
13
16
  "type": "git",
14
- "url": "git://github.com/webdriverio/webdriverio.git"
17
+ "url": "git://github.com/webdriverio/webdriverio.git",
18
+ "directory": "packages/wdio-utils"
15
19
  },
16
20
  "keywords": [
17
21
  "webdriverio",
@@ -23,13 +27,12 @@
23
27
  "url": "https://github.com/webdriverio/webdriverio/issues"
24
28
  },
25
29
  "dependencies": {
26
- "@wdio/logger": "7.19.0",
27
- "@wdio/types": "7.20.3",
30
+ "@wdio/logger": "7.20.8-alpha.504+428a9d729",
31
+ "@wdio/types": "7.20.8-alpha.504+428a9d729",
28
32
  "p-iteration": "^1.1.8"
29
33
  },
30
34
  "publishConfig": {
31
35
  "access": "public"
32
36
  },
33
- "types": "./build/index.d.ts",
34
- "gitHead": "df5cbf4f557ddc04f49ebc25b9a74231fdd44f2b"
37
+ "gitHead": "428a9d729ae6231968a60908732fa3f607d195e9"
35
38
  }