@applitools/execution-grid-tunnel
Version:
Allows user to run tests with exection-grid and navigate to private hosts and ips
46 lines (40 loc) • 991 B
JavaScript
/*
This function wraps action and allows to add events to the action
Params:
- preAction: () => void | Promise<void> Code that you want to execute before the action
- action: () => void | Promise<T> The action you want to execute
- postAction: () => void | Promise<T> This function is called immediately after the action called whenever the action throws error or not
- onSuccuss: (data) => Promise<void>
- onError: (error) => void // if onError === undefinded the function will throw the error from the action
*/
module.exports = async function executeActionWrapper({
preAction,
action,
postAction,
onSuccess,
onError,
}) {
let error, data
if (preAction) {
preAction()
}
try {
data = await action()
} catch (e) {
error = e
}
if (postAction) {
postAction()
}
if (data && onSuccess) {
onSuccess(data)
}
if (error) {
if (onError) {
onError(error)
} else {
throw error
}
}
return data
}