Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wdio/utils

Package Overview
Dependencies
Maintainers
4
Versions
298
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wdio/utils - npm Package Compare versions

Comparing version 5.12.1 to 5.13.0-alpha.0

build/monad.js

32

build/index.js

@@ -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 }; }

20

build/initialisePlugin.js

@@ -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';
}

4

package.json
{
"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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc