@wdio/sync
Advanced tools
Comparing version 5.13.2 to 5.14.0
@@ -22,3 +22,3 @@ "use strict"; | ||
if (!Array.isArray(args)) { | ||
args = [args]; | ||
args = [args].filter(hook => typeof hook === 'function'); | ||
} | ||
@@ -30,2 +30,4 @@ | ||
const execHook = () => { | ||
delete global.browser._NOT_FIBER; | ||
try { | ||
@@ -48,5 +50,5 @@ result = hook.apply(null, args); | ||
return (0, _fibers.default)(execHook).run(); | ||
return hook.constructor.name === 'AsyncFunction' ? execHook() : (0, _fibers.default)(execHook).run(); | ||
})); | ||
return Promise.all(hooks); | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.runSync = runSync; | ||
Object.defineProperty(exports, "executeHooksWithArgs", { | ||
@@ -19,8 +20,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "runFnInFiberContextWithCallback", { | ||
enumerable: true, | ||
get: function () { | ||
return _runFnInFiberContextWithCallback.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "wrapCommand", { | ||
@@ -32,10 +27,6 @@ enumerable: true, | ||
}); | ||
exports.executeAsync = exports.executeSync = exports.runTestInFiberContext = void 0; | ||
exports.executeAsync = exports.executeSync = void 0; | ||
var _fibers = _interopRequireDefault(require("./fibers")); | ||
var _logger = _interopRequireDefault(require("@wdio/logger")); | ||
var _utils = require("@wdio/utils"); | ||
var _executeHooksWithArgs = _interopRequireDefault(require("./executeHooksWithArgs")); | ||
@@ -45,4 +36,2 @@ | ||
var _runFnInFiberContextWithCallback = _interopRequireDefault(require("./runFnInFiberContextWithCallback")); | ||
var _wrapCommand = _interopRequireDefault(require("./wrapCommand")); | ||
@@ -52,9 +41,7 @@ | ||
var _utils2 = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const log = (0, _logger.default)('@wdio/sync'); | ||
const executeSync = async function (fn, repeatTest = 0, args = []) { | ||
delete global.browser._NOT_FIBER; | ||
const executeSync = async function (fn, repeatTest = 0, args = []) { | ||
try { | ||
@@ -119,63 +106,4 @@ global._HAS_FIBER_CONTEXT = true; | ||
const runHook = function (hookFn, origFn, before, after, repeatTest = 0) { | ||
const hookError = hookName => e => log.error(`Error in ${hookName}: ${e.stack}`); | ||
return origFn(function (...hookArgs) { | ||
return (0, _executeHooksWithArgs.default)(before).catch(hookError('beforeHook')).then(() => { | ||
if ((0, _utils.isFunctionAsync)(hookFn)) { | ||
return executeAsync.call(this, hookFn, repeatTest, (0, _utils2.filterSpecArgs)(hookArgs)); | ||
} | ||
return new Promise(runSync.call(this, hookFn, repeatTest, (0, _utils2.filterSpecArgs)(hookArgs))); | ||
}).then(() => { | ||
return (0, _executeHooksWithArgs.default)(after).catch(hookError('afterHook')); | ||
}); | ||
}); | ||
}; | ||
const runSpec = function (specTitle, specFn, origFn, repeatTest = 0) { | ||
if ((0, _utils.isFunctionAsync)(specFn)) { | ||
return origFn(specTitle, function async(...specArgs) { | ||
return executeAsync.call(this, specFn, repeatTest, (0, _utils2.filterSpecArgs)(specArgs)); | ||
}); | ||
} | ||
return origFn(specTitle, function (...specArgs) { | ||
return new Promise(runSync.call(this, specFn, repeatTest, (0, _utils2.filterSpecArgs)(specArgs))); | ||
}); | ||
}; | ||
function runSync(fn, repeatTest = 0, args = []) { | ||
return (resolve, reject) => (0, _fibers.default)(() => executeSync.call(this, fn, repeatTest, args).then(() => resolve(), reject)).run(); | ||
} | ||
const wrapTestFunction = function (fnName, origFn, testInterfaceFnNames, before, after) { | ||
return function (...specArguments) { | ||
let retryCnt = typeof specArguments[specArguments.length - 1] === 'number' ? specArguments.pop() : 0; | ||
const specFn = typeof specArguments[0] === 'function' ? specArguments.shift() : typeof specArguments[1] === 'function' ? specArguments.pop() : undefined; | ||
const specTitle = specArguments[0]; | ||
if (testInterfaceFnNames.indexOf(fnName) > -1) { | ||
if (specFn) return runSpec(specTitle, specFn, origFn, retryCnt); | ||
return origFn(specTitle); | ||
} | ||
return runHook(specFn, origFn, before, after, retryCnt); | ||
}; | ||
}; | ||
const runTestInFiberContext = function (testInterfaceFnNames, before, after, fnName, scope = global) { | ||
const origFn = scope[fnName]; | ||
scope[fnName] = wrapTestFunction(fnName, origFn, testInterfaceFnNames, before, after); | ||
if (typeof origFn.skip === 'function') { | ||
scope[fnName].skip = origFn.skip; | ||
} | ||
if (typeof origFn.only === 'function') { | ||
const origOnlyFn = origFn.only; | ||
scope[fnName].only = wrapTestFunction(fnName + '.only', origOnlyFn, testInterfaceFnNames, before, after); | ||
} | ||
}; | ||
exports.runTestInFiberContext = runTestInFiberContext; | ||
} |
@@ -14,2 +14,3 @@ "use strict"; | ||
return function (...args) { | ||
delete global.browser._NOT_FIBER; | ||
return new Promise((resolve, reject) => (0, _fibers.default)(() => { | ||
@@ -16,0 +17,0 @@ try { |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.sanitizeErrorMessage = sanitizeErrorMessage; | ||
exports.filterSpecArgs = filterSpecArgs; | ||
@@ -40,6 +39,2 @@ var _constants = require("./constants"); | ||
return err; | ||
} | ||
function filterSpecArgs(args) { | ||
return args.filter(arg => typeof arg !== 'function'); | ||
} |
@@ -31,3 +31,3 @@ "use strict"; | ||
this._NOT_FIBER = fn.name !== '' && fn.name !== 'debug' && commandName !== 'waitUntil'; | ||
this._NOT_FIBER = fn.name !== ''; | ||
const future = new _fibers.Future(); | ||
@@ -34,0 +34,0 @@ const result = runCommandWithHooks.apply(this, [commandName, fn, ...args]); |
{ | ||
"name": "@wdio/sync", | ||
"version": "5.13.2", | ||
"version": "5.14.0", | ||
"description": "A WebdriverIO plugin. Helper module to run WebdriverIO commands synchronously", | ||
@@ -37,5 +37,3 @@ "author": "Christian Bromann <christian@saucelabs.com>", | ||
"dependencies": { | ||
"@wdio/config": "5.13.2", | ||
"@wdio/logger": "5.13.2", | ||
"@wdio/utils": "5.13.2" | ||
"@wdio/logger": "5.13.2" | ||
}, | ||
@@ -49,3 +47,3 @@ "optionalDependencies": { | ||
}, | ||
"gitHead": "f646117fb777ab16d7614f2c8e6d896b0f2190ee" | ||
"gitHead": "5d19a114535bff2b62abff42db65eb59ffd9a1f7" | ||
} |
@@ -109,3 +109,3 @@ /// <reference types="node"/> | ||
beforeHook?(): void; | ||
beforeHook?(test: any, context: any, stepData?: any, world?: any): void; | ||
@@ -119,4 +119,4 @@ beforeSession?( | ||
beforeSuite?(suite: Suite): void; | ||
beforeTest?(test: Test): void; | ||
afterHook?(): void; | ||
beforeTest?(test: Test, context: any): void; | ||
afterHook?(test: any, context: any, result: { error?: any, result?: any, passed: boolean, duration: number }, stepData?: any, world?: any): void; | ||
@@ -143,3 +143,3 @@ after?( | ||
afterSuite?(suite: Suite): void; | ||
afterTest?(test: Test): void; | ||
afterTest?(test: Test, context: any, result: { error?: any, result?: any, passed: boolean, duration: number }): void; | ||
} | ||
@@ -146,0 +146,0 @@ type _HooksArray = { |
3
22777
11
647
- Removed@wdio/config@5.13.2
- Removed@wdio/utils@5.13.2
- Removed@wdio/config@5.13.2(transitive)
- Removed@wdio/utils@5.13.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)