@wdio/utils
Advanced tools
Comparing version 5.12.1 to 5.13.0-alpha.0
@@ -18,2 +18,32 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "webdriverMonad", { | ||
enumerable: true, | ||
get: function () { | ||
return _monad.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "commandCallStructure", { | ||
enumerable: true, | ||
get: function () { | ||
return _utils.commandCallStructure; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isValidParameter", { | ||
enumerable: true, | ||
get: function () { | ||
return _utils.isValidParameter; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getArgumentType", { | ||
enumerable: true, | ||
get: function () { | ||
return _utils.getArgumentType; | ||
} | ||
}); | ||
Object.defineProperty(exports, "safeRequire", { | ||
enumerable: true, | ||
get: function () { | ||
return _utils.safeRequire; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isFunctionAsync", { | ||
@@ -30,4 +60,6 @@ enumerable: true, | ||
var _monad = _interopRequireDefault(require("./monad")); | ||
var _utils = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -8,23 +8,11 @@ "use strict"; | ||
function safeRequire(name) { | ||
try { | ||
require.resolve(name); | ||
} catch (e) { | ||
return null; | ||
} | ||
var _utils = require("./utils"); | ||
try { | ||
return require(name); | ||
} catch (e) { | ||
throw new Error(`Couldn't initialise "${name}".\n${e.stack}`); | ||
} | ||
} | ||
function initialisePlugin(name, type, target = 'default') { | ||
if (name[0] === '@') { | ||
const service = safeRequire(name); | ||
const service = (0, _utils.safeRequire)(name); | ||
return service[target]; | ||
} | ||
const scopedPlugin = safeRequire(`@wdio/${name.toLowerCase()}-${type}`); | ||
const scopedPlugin = (0, _utils.safeRequire)(`@wdio/${name.toLowerCase()}-${type}`); | ||
@@ -35,3 +23,3 @@ if (scopedPlugin) { | ||
const plugin = safeRequire(`wdio-${name.toLowerCase()}-${type}`); | ||
const plugin = (0, _utils.safeRequire)(`wdio-${name.toLowerCase()}-${type}`); | ||
@@ -38,0 +26,0 @@ if (plugin) { |
@@ -6,6 +6,114 @@ "use strict"; | ||
}); | ||
exports.overwriteElementCommands = overwriteElementCommands; | ||
exports.commandCallStructure = commandCallStructure; | ||
exports.isValidParameter = isValidParameter; | ||
exports.getArgumentType = getArgumentType; | ||
exports.safeRequire = safeRequire; | ||
exports.isFunctionAsync = isFunctionAsync; | ||
function overwriteElementCommands(propertiesObject) { | ||
const elementOverrides = propertiesObject['__elementOverrides__'] ? propertiesObject['__elementOverrides__'].value : {}; | ||
for (const [commandName, userDefinedCommand] of Object.entries(elementOverrides)) { | ||
if (typeof userDefinedCommand !== 'function') { | ||
throw new Error('overwriteCommand: commands be overwritten only with functions, command: ' + commandName); | ||
} | ||
if (!propertiesObject[commandName]) { | ||
throw new Error('overwriteCommand: no command to be overwritten: ' + commandName); | ||
} | ||
if (typeof propertiesObject[commandName].value !== 'function') { | ||
throw new Error('overwriteCommand: only functions can be overwritten, command: ' + commandName); | ||
} | ||
const origCommand = propertiesObject[commandName].value; | ||
delete propertiesObject[commandName]; | ||
const newCommand = function (...args) { | ||
const element = this; | ||
return userDefinedCommand.apply(element, [function origCommandFunction() { | ||
const context = this || element; | ||
return origCommand.apply(context, arguments); | ||
}, ...args]); | ||
}; | ||
propertiesObject[commandName] = { | ||
value: newCommand, | ||
configurable: true | ||
}; | ||
} | ||
delete propertiesObject['__elementOverrides__']; | ||
propertiesObject['__elementOverrides__'] = { | ||
value: {} | ||
}; | ||
} | ||
function commandCallStructure(commandName, args) { | ||
const callArgs = args.map(arg => { | ||
if (typeof arg === 'string') { | ||
arg = `"${arg}"`; | ||
} else if (typeof arg === 'function') { | ||
arg = '<fn>'; | ||
} else if (arg === null) { | ||
arg = 'null'; | ||
} else if (typeof arg === 'object') { | ||
arg = '<object>'; | ||
} else if (typeof arg === 'undefined') { | ||
arg = typeof arg; | ||
} | ||
return arg; | ||
}).join(', '); | ||
return `${commandName}(${callArgs})`; | ||
} | ||
function isValidParameter(arg, expectedType) { | ||
let shouldBeArray = false; | ||
if (expectedType.slice(-2) === '[]') { | ||
expectedType = expectedType.slice(0, -2); | ||
shouldBeArray = true; | ||
} | ||
if (shouldBeArray) { | ||
if (!Array.isArray(arg)) { | ||
return false; | ||
} | ||
} else { | ||
arg = [arg]; | ||
} | ||
for (const argEntity of arg) { | ||
const argEntityType = getArgumentType(argEntity); | ||
if (!argEntityType.match(expectedType)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getArgumentType(arg) { | ||
return arg === null ? 'null' : typeof arg; | ||
} | ||
function safeRequire(name) { | ||
try { | ||
require.resolve(name); | ||
} catch (e) { | ||
return null; | ||
} | ||
try { | ||
return require(name); | ||
} catch (e) { | ||
throw new Error(`Couldn't initialise "${name}".\n${e.stack}`); | ||
} | ||
} | ||
function isFunctionAsync(fn) { | ||
return fn.constructor && fn.constructor.name === 'AsyncFunction' || fn.name === 'async'; | ||
} |
{ | ||
"name": "@wdio/utils", | ||
"version": "5.12.1", | ||
"version": "5.13.0-alpha.0", | ||
"description": "A WDIO helper utility to provide several utility functions used across the project.", | ||
@@ -40,3 +40,3 @@ "author": "Christian Bromann <christian@saucelabs.com>", | ||
}, | ||
"gitHead": "848151e5fdcb8b694c1a273b9b69852c22875687" | ||
"gitHead": "0ea6b850fdca956b31f92f6b57ae3b8c8883aeee" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12433
7
327
1
1