@wdio/utils 5.9.3 → 5.12.1

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/build/index.js CHANGED
@@ -15,9 +15,17 @@ Object.defineProperty(exports, "initialiseServices", {
15
15
  return _initialiseServices.default;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "isFunctionAsync", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _utils.isFunctionAsync;
22
+ }
23
+ });
18
24
 
19
25
  var _initialisePlugin = _interopRequireDefault(require("./initialisePlugin"));
20
26
 
21
27
  var _initialiseServices = _interopRequireDefault(require("./initialiseServices"));
22
28
 
29
+ var _utils = require("./utils");
30
+
23
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -5,53 +5,31 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = initialisePlugin;
7
7
 
8
- /**
9
- * Allows to safely require a package, it only throws if the package was found
10
- * but failed to load due to syntax errors
11
- * @param {string} name of package
12
- * @return {object} package content
13
- */
14
8
  function safeRequire(name) {
15
9
  try {
16
- return require(name);
10
+ require.resolve(name);
17
11
  } catch (e) {
18
- if (!e.message.match(`Cannot find module '${name}'`)) {
19
- throw new Error(`Couldn't initialise "${name}".\n${e.stack}`);
20
- }
21
-
22
12
  return null;
23
13
  }
24
- }
25
- /**
26
- * initialise WebdriverIO compliant plugins like reporter or services in the following way:
27
- * 1. if package name is scoped (starts with "@"), require scoped package name
28
- * 2. otherwise try to require "@wdio/<name>-<type>"
29
- * 3. otherwise try to require "wdio-<name>-<type>"
30
- */
31
14
 
15
+ try {
16
+ return require(name);
17
+ } catch (e) {
18
+ throw new Error(`Couldn't initialise "${name}".\n${e.stack}`);
19
+ }
20
+ }
32
21
 
33
22
  function initialisePlugin(name, type, target = 'default') {
34
- /**
35
- * directly import packages that are scoped
36
- */
37
23
  if (name[0] === '@') {
38
24
  const service = safeRequire(name);
39
25
  return service[target];
40
26
  }
41
- /**
42
- * check for scoped version of plugin first (e.g. @wdio/sauce-service)
43
- */
44
-
45
27
 
46
28
  const scopedPlugin = safeRequire(`@wdio/${name.toLowerCase()}-${type}`);
47
29
 
48
30
  if (scopedPlugin) {
49
31
  return scopedPlugin[target];
50
32
  }
51
- /**
52
- * check for old type of
53
- */
54
-
55
33
 
56
34
  const plugin = safeRequire(`wdio-${name.toLowerCase()}-${type}`);
57
35
 
@@ -14,13 +14,6 @@ var _initialisePlugin = _interopRequireDefault(require("./initialisePlugin"));
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  const log = (0, _logger.default)('@wdio/utils:initialiseServices');
17
- /**
18
- * initialise services based on configuration
19
- * @param {Object} config config of running session
20
- * @param {Object} caps capabilities of running session
21
- * @param {String} type define sub type of plugins (for services it could be "launcher")
22
- * @return {Object[]} list of service classes that got initialised
23
- */
24
17
 
25
18
  function initialiseServices(config, caps, type) {
26
19
  const initialisedServices = [];
@@ -31,18 +24,11 @@ function initialiseServices(config, caps, type) {
31
24
 
32
25
  for (let serviceName of config.services) {
33
26
  let serviceConfig = config;
34
- /**
35
- * allow custom services with custom options
36
- */
37
27
 
38
28
  if (Array.isArray(serviceName)) {
39
29
  serviceConfig = (0, _deepmerge.default)(config, serviceName[1] || {});
40
30
  serviceName = serviceName[0];
41
31
  }
42
- /**
43
- * allow custom services that are already initialised
44
- */
45
-
46
32
 
47
33
  if (serviceName && typeof serviceName === 'object' && !Array.isArray(serviceName)) {
48
34
  log.debug('initialise custom initiated service');
@@ -51,9 +37,6 @@ function initialiseServices(config, caps, type) {
51
37
  }
52
38
 
53
39
  try {
54
- /**
55
- * allow custom service classes
56
- */
57
40
  if (typeof serviceName === 'function') {
58
41
  log.debug(`initialise custom service "${serviceName.name}"`);
59
42
  initialisedServices.push(new serviceName(serviceConfig, caps));
@@ -62,9 +45,6 @@ function initialiseServices(config, caps, type) {
62
45
 
63
46
  log.debug(`initialise wdio service "${serviceName}"`);
64
47
  const Service = (0, _initialisePlugin.default)(serviceName, 'service', type);
65
- /**
66
- * service only contains a launcher
67
- */
68
48
 
69
49
  if (!Service) {
70
50
  continue;
package/build/utils.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isFunctionAsync = isFunctionAsync;
7
+
8
+ function isFunctionAsync(fn) {
9
+ return fn.constructor && fn.constructor.name === 'AsyncFunction' || fn.name === 'async';
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/utils",
3
- "version": "5.9.3",
3
+ "version": "5.12.1",
4
4
  "description": "A WDIO helper utility to provide several utility functions used across the project.",
5
5
  "author": "Christian Bromann <christian@saucelabs.com>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-utils",
@@ -31,11 +31,11 @@
31
31
  "url": "https://github.com/webdriverio/webdriverio/issues"
32
32
  },
33
33
  "dependencies": {
34
- "@wdio/logger": "^5.9.3",
35
- "deepmerge": "^3.2.0"
34
+ "@wdio/logger": "^5.12.1",
35
+ "deepmerge": "^4.0.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "94c7a26fd99230516d430161989e794492893e07"
40
+ "gitHead": "848151e5fdcb8b694c1a273b9b69852c22875687"
41
41
  }