How to use hookType method in Playwright Internal

Best JavaScript code snippet using playwright-internal

hooks.js

Source:hooks.js Github

copy

Full Screen

1'use strict';2const _ = require('lodash');3const Utils = require('./utils');4const Promise = require('./promise');5const debug = Utils.getLogger().debugContext('hooks');6const hookTypes = {7 beforeValidate: {params: 2},8 afterValidate: {params: 2},9 validationFailed: {params: 3},10 beforeCreate: {params: 2},11 afterCreate: {params: 2},12 beforeDestroy: {params: 2},13 afterDestroy: {params: 2},14 beforeRestore: {params: 2},15 afterRestore: {params: 2},16 beforeUpdate: {params: 2},17 afterUpdate: {params: 2},18 beforeSave: {params: 2, proxies: ['beforeUpdate', 'beforeCreate']},19 afterSave: {params: 2, proxies: ['afterUpdate', 'afterCreate']},20 beforeUpsert: {params: 2},21 afterUpsert: {params: 2},22 beforeBulkCreate: {params: 2},23 afterBulkCreate: {params: 2},24 beforeBulkDestroy: {params: 1},25 afterBulkDestroy: {params: 1},26 beforeBulkRestore: {params: 1},27 afterBulkRestore: {params: 1},28 beforeBulkUpdate: {params: 1},29 afterBulkUpdate: {params: 1},30 beforeFind: {params: 1},31 beforeFindAfterExpandIncludeAll: {params: 1},32 beforeFindAfterOptions: {params: 1},33 afterFind: {params: 2},34 beforeCount: {params: 1},35 beforeDefine: {params: 2, sync: true},36 afterDefine: {params: 1, sync: true},37 beforeInit: {params: 2, sync: true},38 afterInit: {params: 1, sync: true},39 beforeConnect: {params: 1},40 afterConnect: {params: 2},41 beforeSync: {params: 1},42 afterSync: {params: 1},43 beforeBulkSync: {params: 1},44 afterBulkSync: {params: 1}45};46exports.hooks = hookTypes;47const hookAliases = {48 beforeDelete: 'beforeDestroy',49 afterDelete: 'afterDestroy',50 beforeBulkDelete: 'beforeBulkDestroy',51 afterBulkDelete: 'afterBulkDestroy',52 beforeConnection: 'beforeConnect'53};54exports.hookAliases = hookAliases;55/**56 * get array of current hook and its proxied hooks combined57 * @private58 */59const getProxiedHooks = hookType =>60 hookTypes[hookType].proxies61 ? hookTypes[hookType].proxies.concat(hookType)62 : [hookType]63;64function getHooks(hookType) {65 return (this.options.hooks || {})[hookType] || [];66};67const Hooks = {68 /**69 * Process user supplied hooks definition70 *71 * @param {Object} hooks72 *73 * @private74 * @memberOf Sequelize75 * @memberOf Sequelize.Model76 */77 _setupHooks(hooks) {78 this.options.hooks = {};79 _.map(hooks || {}, (hooksArray, hookName) => {80 if (!_.isArray(hooksArray)) hooksArray = [hooksArray];81 hooksArray.forEach(hookFn => this.addHook(hookName, hookFn));82 });83 },84 runHooks(hooks) {85 if (!hooks) throw new Error('runHooks requires at least 1 argument');86 const hookArgs = Utils.sliceArgs(arguments, 1);87 let hookType;88 if (typeof hooks === 'string') {89 hookType = hooks;90 hooks = getHooks.call(this, hookType);91 if (this.sequelize) {92 hooks = hooks.concat(getHooks.call(this.sequelize, hookType));93 }94 }95 if (!Array.isArray(hooks)) {96 hooks = [hooks];97 }98 // synchronous hooks99 if (hookTypes[hookType] && hookTypes[hookType].sync) {100 for (let hook of hooks) {101 if (typeof hook === 'object') {102 hook = hook.fn;103 }104 debug(`running hook(sync) ${hookType}`);105 hook.apply(this, hookArgs);106 }107 return;108 }109 // asynchronous hooks (default)110 return Promise.each(hooks, hook => {111 if (typeof hook === 'object') {112 hook = hook.fn;113 }114 debug(`running hook ${hookType}`);115 return Promise.resolve(hook.apply(this, hookArgs));116 }).return();117 },118 hook() {119 Utils.deprecate('hook() method has been deprecated, please use addHook() method instead');120 return Hooks.addHook.apply(this, arguments);121 },122 /**123 * Add a hook to the model124 *125 * @param {String} hookType126 * @param {String} [name] Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.127 * @param {Function} fn The hook function128 *129 * @memberOf Sequelize130 * @memberOf Sequelize.Model131 */132 addHook(hookType, name, fn) {133 if (typeof name === 'function') {134 fn = name;135 name = null;136 }137 debug(`adding hook ${hookType}`);138 const originalHookType = hookType;139 hookType = hookAliases[hookType] || hookType;140 if (hookAliases[originalHookType]) {141 Utils.deprecate(`${originalHookType} hook has been deprecated, please use ${hookType} hook instead`);142 }143 // check for proxies, add them too144 hookType = getProxiedHooks(hookType);145 _.each(hookType, type => {146 this.options.hooks[type] = getHooks.call(this, type);147 this.options.hooks[type].push(name ? {name, fn} : fn);148 });149 return this;150 },151 /**152 * Remove hook from the model153 *154 * @param {String} hookType155 * @param {String|Function} name156 *157 * @memberOf Sequelize158 * @memberOf Sequelize.Model159 */160 removeHook(hookType, name) {161 hookType = hookAliases[hookType] || hookType;162 const isReference = typeof name === 'function' ? true : false;163 if (!this.hasHook(hookType)) {164 return this;165 }166 Utils.debug(`removing hook ${hookType}`);167 // check for proxies, add them too168 hookType = getProxiedHooks(hookType);169 for (const type of hookType) {170 this.options.hooks[type] = this.options.hooks[type].filter(hook => {171 if (isReference && typeof hook === 'function') {172 return hook !== name; // check if same method173 } else if (!isReference && typeof hook === 'object') {174 return hook.name !== name;175 }176 return true;177 });178 }179 return this;180 },181 /**182 * Check whether the mode has any hooks of this type183 *184 * @param {String} hookType185 *186 * @alias hasHooks187 * @memberOf Sequelize188 * @memberOf Sequelize.Model189 */190 hasHook(hookType) {191 return this.options.hooks[hookType] && !!this.options.hooks[hookType].length;192 }193};194Hooks.hasHooks = Hooks.hasHook;195function applyTo(target) {196 _.mixin(target, Hooks);197 const allHooks = Object.keys(hookTypes).concat(Object.keys(hookAliases));198 for (const hook of allHooks) {199 target[hook] = function(name, callback) {200 return this.addHook(hook, name, callback);201 };202 }203}204exports.applyTo = applyTo;205/**206 * A hook that is run before validation207 * @param {String} name208 * @param {Function} fn A callback function that is called with instance, options209 * @name beforeValidate210 * @memberOf Sequelize.Model211 */212/**213 * A hook that is run after validation214 * @param {String} name215 * @param {Function} fn A callback function that is called with instance, options216 * @name afterValidate217 * @memberOf Sequelize.Model218 */219/**220 * A hook that is run when validation fails221 * @param {String} name222 * @param {Function} fn A callback function that is called with instance, options, error. Error is the223 * SequelizeValidationError. If the callback throws an error, it will replace the original validation error.224 * @name validationFailed225 * @memberOf Sequelize.Model226 */227/**228 * A hook that is run before creating a single instance229 * @param {String} name230 * @param {Function} fn A callback function that is called with attributes, options231 * @name beforeCreate232 * @memberOf Sequelize.Model233 */234/**235 * A hook that is run after creating a single instance236 * @param {String} name237 * @param {Function} fn A callback function that is called with attributes, options238 * @name afterCreate239 * @memberOf Sequelize.Model240 */241/**242 * A hook that is run before creating or updating a single instance, It proxies `beforeCreate` and `beforeUpdate`243 * @param {String} name244 * @param {Function} fn A callback function that is called with attributes, options245 * @name beforeSave246 * @memberOf Sequelize.Model247 */248/**249 * A hook that is run before upserting250 * @param {String} name251 * @param {Function} fn A callback function that is called with attributes, options252 * @name beforeUpsert253 * @memberOf Sequelize.Model254 */255/**256 * A hook that is run after upserting257 * @param {String} name258 * @param {Function} fn A callback function that is called with attributes, options259 * @name afterUpsert260 * @memberOf Sequelize.Model261 */262/**263 * A hook that is run after creating or updating a single instance, It proxies `afterCreate` and `afterUpdate`264 * @param {String} name265 * @param {Function} fn A callback function that is called with attributes, options266 * @name afterSave267 * @memberOf Sequelize.Model268 */269/**270 * A hook that is run before destroying a single instance271 * @param {String} name272 * @param {Function} fn A callback function that is called with instance, options273 *274 * @name beforeDestroy275 * @alias beforeDelete276 * @memberOf Sequelize.Model277 */278/**279 * A hook that is run after destroying a single instance280 * @param {String} name281 * @param {Function} fn A callback function that is called with instance, options282 *283 * @name afterDestroy284 * @alias afterDelete285 * @memberOf Sequelize.Model286 */287/**288 * A hook that is run before restoring a single instance289 * @param {String} name290 * @param {Function} fn A callback function that is called with instance, options291 *292 * @name beforeRestore293 * @memberOf Sequelize.Model294 */295/**296 * A hook that is run after restoring a single instance297 * @param {String} name298 * @param {Function} fn A callback function that is called with instance, options299 *300 * @name afterRestore301 * @memberOf Sequelize.Model302 */303/**304 * A hook that is run before updating a single instance305 * @param {String} name306 * @param {Function} fn A callback function that is called with instance, options307 * @name beforeUpdate308 * @memberOf Sequelize.Model309 */310/**311 * A hook that is run after updating a single instance312 * @param {String} name313 * @param {Function} fn A callback function that is called with instance, options314 * @name afterUpdate315 * @memberOf Sequelize.Model316 */317/**318 * A hook that is run before creating instances in bulk319 * @param {String} name320 * @param {Function} fn A callback function that is called with instances, options321 * @name beforeBulkCreate322 * @memberOf Sequelize.Model323 */324/**325 * A hook that is run after creating instances in bulk326 * @param {String} name327 * @param {Function} fn A callback function that is called with instances, options328 * @name afterBulkCreate329 * @memberOf Sequelize.Model330 */331/**332 * A hook that is run before destroying instances in bulk333 * @param {String} name334 * @param {Function} fn A callback function that is called with options335 *336 * @name beforeBulkDestroy337 * @alias beforeBulkDelete338 * @memberOf Sequelize.Model339 */340/**341 * A hook that is run after destroying instances in bulk342 * @param {String} name343 * @param {Function} fn A callback function that is called with options344 *345 * @name afterBulkDestroy346 * @alias afterBulkDelete347 * @memberOf Sequelize.Model348 */349/**350 * A hook that is run before restoring instances in bulk351 * @param {String} name352 * @param {Function} fn A callback function that is called with options353 *354 * @name beforeBulkRestore355 * @memberOf Sequelize.Model356 */357/**358 * A hook that is run after restoring instances in bulk359 * @param {String} name360 * @param {Function} fn A callback function that is called with options361 *362 * @name afterBulkRestore363 * @memberOf Sequelize.Model364 */365/**366 * A hook that is run before updating instances in bulk367 * @param {String} name368 * @param {Function} fn A callback function that is called with options369 * @name beforeBulkUpdate370 * @memberOf Sequelize.Model371 */372/**373 * A hook that is run after updating instances in bulk374 * @param {String} name375 * @param {Function} fn A callback function that is called with options376 * @name afterBulkUpdate377 * @memberOf Sequelize.Model378 */379/**380 * A hook that is run before a find (select) query381 * @param {String} name382 * @param {Function} fn A callback function that is called with options383 * @name beforeFind384 * @memberOf Sequelize.Model385 */386/**387 * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded388 * @param {String} name389 * @param {Function} fn A callback function that is called with options390 * @name beforeFindAfterExpandIncludeAll391 * @memberOf Sequelize.Model392 */393/**394 * A hook that is run before a find (select) query, after all option parsing is complete395 * @param {String} name396 * @param {Function} fn A callback function that is called with options397 * @name beforeFindAfterOptions398 * @memberOf Sequelize.Model399 */400/**401 * A hook that is run after a find (select) query402 * @param {String} name403 * @param {Function} fn A callback function that is called with instance(s), options404 * @name afterFind405 * @memberOf Sequelize.Model406 */407/**408 * A hook that is run before a count query409 * @param {String} name410 * @param {Function} fn A callback function that is called with options411 * @name beforeCount412 * @memberOf Sequelize.Model413 */414/**415 * A hook that is run before a define call416 * @param {String} name417 * @param {Function} fn A callback function that is called with attributes, options418 * @name beforeDefine419 * @memberOf Sequelize420 */421/**422 * A hook that is run after a define call423 * @param {String} name424 * @param {Function} fn A callback function that is called with factory425 * @name afterDefine426 * @memberOf Sequelize427 */428/**429 * A hook that is run before Sequelize() call430 * @param {String} name431 * @param {Function} fn A callback function that is called with config, options432 * @name beforeInit433 * @memberOf Sequelize434 */435/**436 * A hook that is run after Sequelize() call437 * @param {String} name438 * @param {Function} fn A callback function that is called with sequelize439 * @name afterInit440 * @memberOf Sequelize441 */442/**443 * A hook that is run before a connection is created444 * @param {String} name445 * @param {Function} fn A callback function that is called with config passed to connection446 * @name beforeConnect447 * @memberOf Sequelize448 */449/**450 * A hook that is run after a connection is created451 * @param {String} name452 * @param {Function} fn A callback function that is called with the connection object and thye config passed to connection453 * @name afterConnect454 * @memberOf Sequelize455 */456/**457 * A hook that is run before Model.sync call458 * @param {String} name459 * @param {Function} fn A callback function that is called with options passed to Model.sync460 * @name beforeSync461 * @memberOf Sequelize462 */463/**464 * A hook that is run after Model.sync call465 * @param {String} name466 * @param {Function} fn A callback function that is called with options passed to Model.sync467 * @name afterSync468 * @memberOf Sequelize469 */470/**471 * A hook that is run before sequelize.sync call472 * @param {String} name473 * @param {Function} fn A callback function that is called with options passed to sequelize.sync474 * @name beforeBulkSync475 * @memberOf Sequelize476 */477/**478 * A hook that is run after sequelize.sync call479 * @param {String} name480 * @param {Function} fn A callback function that is called with options passed to sequelize.sync481 * @name afterBulkSync482 * @memberOf Sequelize...

Full Screen

Full Screen

LogicHookUtils.js

Source:LogicHookUtils.js Github

copy

Full Screen

1const util = require('util')2const { NodeVM } = require('vm2')3const path = require('path')4const fs = require('fs')5const isClass = require('is-class')6const debug = require('debug')('botium-core-asserterUtils')7const { BotiumError } = require('../BotiumError')8const { DEFAULT_ASSERTERS, DEFAULT_LOGIC_HOOKS, DEFAULT_USER_INPUTS } = require('./LogicHookConsts')9DEFAULT_ASSERTERS.forEach((asserter) => {10 asserter.Class = require(`./asserter/${asserter.className}`)11})12DEFAULT_LOGIC_HOOKS.forEach((logicHook) => {13 logicHook.Class = require(`./logichooks/${logicHook.className}`)14})15DEFAULT_USER_INPUTS.forEach((userInput) => {16 userInput.Class = require(`./userinput/${userInput.className}`)17})18const Capabilities = require('../../Capabilities')19const _ = require('lodash')20module.exports = class LogicHookUtils {21 constructor ({ buildScriptContext, caps }) {22 this.asserters = {}23 this.globalAsserters = []24 this.logicHooks = {}25 this.globalLogicHooks = []26 this.userInputs = {}27 this.buildScriptContext = buildScriptContext28 this.caps = caps29 this._setDefaultAsserters()30 this._setDefaultLogicHooks()31 this._setDefaultUserInputs()32 this._fetchAsserters()33 this._fetchLogicHooks()34 this._fetchUserInputs()35 }36 _setDefaultAsserters () {37 DEFAULT_ASSERTERS.forEach((asserter) => {38 this.asserters[asserter.name] = new (asserter.Class)(this.buildScriptContext, this.caps)39 })40 debug(`Loaded Default asserter - ${util.inspect(Object.keys(this.asserters))}`)41 }42 _setDefaultLogicHooks () {43 DEFAULT_LOGIC_HOOKS.forEach((lh) => {44 this.logicHooks[lh.name] = new (lh.Class)(this.buildScriptContext, this.caps)45 })46 debug(`Loaded Default logic hook - ${util.inspect(Object.keys(this.logicHooks))}`)47 }48 _setDefaultUserInputs () {49 DEFAULT_USER_INPUTS.forEach((ui) => {50 this.userInputs[ui.name] = new (ui.Class)(this.buildScriptContext, this.caps)51 })52 debug(`Loaded Default user input - ${util.inspect(Object.keys(this.userInputs))}`)53 }54 _fetchAsserters () {55 this.caps[Capabilities.ASSERTERS]56 .map(asserter => {57 if (this.asserters[asserter.ref]) {58 debug(`${asserter.ref} asserter already exists, overwriting.`)59 }60 this.asserters[asserter.ref] = this._loadClass(asserter, 'asserter')61 if (asserter.global) {62 this.globalAsserters.push(asserter.ref)63 debug(`global asserter: ${asserter.ref} was set and will be executed in every convo`)64 }65 })66 }67 _fetchLogicHooks () {68 this.caps[Capabilities.LOGIC_HOOKS]69 .map(logicHook => {70 if (this.logicHooks[logicHook.ref]) {71 debug(`${logicHook.ref} logic hook already exists, overwriting.`)72 }73 this.logicHooks[logicHook.ref] = this._loadClass(logicHook, 'logichook')74 debug(`Loaded ${logicHook.ref} SUCCESSFULLY`)75 if (logicHook.global) {76 this.globalLogicHooks.push(logicHook.ref)77 debug(`global logic hook: ${logicHook.ref} was set and will be executed in every convo`)78 }79 })80 }81 _fetchUserInputs () {82 this.caps[Capabilities.USER_INPUTS]83 .map(userInput => {84 if (this.userInputs[userInput.ref]) {85 debug(`${userInput.ref} userinput already exists, overwriting.`)86 }87 this.userInputs[userInput.ref] = this._loadClass(userInput, 'userinput')88 debug(`Loaded ${userInput.ref} SUCCESSFULLY`)89 })90 }91 getGlobalAsserter () {92 return this.globalAsserters93 .map(name => this.asserters[name])94 }95 getGlobalLogicHook () {96 return this.globalLogicHooks97 .map(name => this.logicHooks[name])98 }99 _loadClass ({ src, ref, args }, hookType) {100 if (hookType !== 'asserter' && hookType !== 'logichook' && hookType !== 'userinput') {101 throw Error(`Unknown hookType ${hookType}`)102 }103 // 1 gives possibility to use default asserter as global asserter104 if (hookType === 'asserter') {105 const asserter = DEFAULT_ASSERTERS.find(asserter => src === asserter.className)106 if (asserter) {107 debug(`Loading ${ref} ${hookType}. Using default asserter ${asserter.className} as global asserter`)108 return new (asserter.Class)(this.buildScriptContext, this.caps, args)109 }110 }111 if (hookType === 'logichook') {112 const lh = DEFAULT_LOGIC_HOOKS.find(lh => src === lh.className)113 if (lh) {114 debug(`Loading ${ref} ${hookType}. Using default logichook ${lh.className} as global logichook`)115 return new (lh.Class)(this.buildScriptContext, this.caps, args)116 }117 }118 if (hookType === 'userinput') {119 const ui = DEFAULT_USER_INPUTS.find(ui => src === ui.className)120 if (ui) {121 debug(`Loading ${ref} ${hookType}. Using default userinput ${ui.className} as global userinput`)122 return new (ui.Class)(this.buildScriptContext, this.caps, args)123 }124 }125 const _checkUnsafe = () => {126 if (!this.caps[Capabilities.SECURITY_ALLOW_UNSAFE]) {127 throw new BotiumError(128 'Security Error. Using unsafe component is not allowed',129 {130 type: 'security',131 subtype: 'allow unsafe',132 source: path.basename(__filename),133 cause: { src: !!src, ref, args, hookType }134 }135 )136 }137 }138 if (!src) {139 const packageName = `botium-${hookType}-${ref}`140 try {141 const CheckClass = require(packageName)142 if (isClass(CheckClass)) {143 debug(`Loading ${ref} ${hookType}. Loading from ${packageName} as class. Guessed package name.`)144 return new CheckClass(this.buildScriptContext, this.caps, args)145 } else if (_.isFunction(CheckClass)) {146 debug(`Loading ${ref} ${hookType}. Loading from ${packageName} as function. Guessed package name.`)147 return CheckClass(this.buildScriptContext, this.caps, args)148 } else if (isClass(CheckClass.PluginClass)) {149 debug(`Loading ${ref} ${hookType}. Loading from ${packageName} as class using PluginClass. Guessed package name.`)150 return new CheckClass.PluginClass(this.buildScriptContext, this.caps, args)151 } else {152 throw new Error(`${packageName} class or function or PluginClass field expected`)153 }154 } catch (err) {155 throw new Error(`Failed to fetch package ${packageName} - ${util.inspect(err)}`)156 }157 }158 if (isClass(src)) {159 _checkUnsafe()160 try {161 const CheckClass = src162 debug(`Loading ${ref} ${hookType}. Using src as class.`)163 return new CheckClass(this.buildScriptContext, this.caps, args)164 } catch (err) {165 throw new Error(`Failed to load package ${ref} from provided class - ${util.inspect(err)}`)166 }167 }168 if (_.isFunction(src)) {169 _checkUnsafe()170 try {171 debug(`Loading ${ref} ${hookType}. Using src as function.`)172 return src(this.buildScriptContext, this.caps, args)173 } catch (err) {174 throw new Error(`Failed to load package ${ref} from provided function - ${util.inspect(err)}`)175 }176 }177 if (_.isObject(src) && !_.isString(src)) {178 try {179 const hookObject = Object.keys(src).reduce((result, key) => {180 result[key] = (args) => {181 const script = src[key]182 if (_.isFunction(script)) {183 _checkUnsafe()184 return script(args)185 } else if (_.isString(script)) {186 try {187 const vm = new NodeVM({188 eval: false,189 require: false,190 sandbox: args191 })192 return vm.run(script)193 } catch (err) {194 throw new Error(`Script "${key}" is not valid - ${util.inspect(err)}`)195 }196 } else {197 throw new Error(`Script "${key}" is not valid - only functions and javascript code accepted`)198 }199 }200 return result201 }, {})202 debug(`Loading ${ref} ${hookType}. Using src as function code.`)203 return hookObject204 } catch (err) {205 throw new Error(`Failed to load package ${ref} from provided function - ${util.inspect(err)}`)206 }207 }208 const loadErr = []209 const tryLoadPackage = src210 try {211 let CheckClass = require(tryLoadPackage)212 if (CheckClass.default) {213 CheckClass = CheckClass.default214 }215 if (isClass(CheckClass)) {216 debug(`Loading ${ref} ${hookType}. Using src for require. Loading from ${tryLoadPackage} as class`)217 return new CheckClass(this.buildScriptContext, this.caps, args)218 } else if (_.isFunction(CheckClass)) {219 debug(`Loading ${ref} ${hookType}. Using src for require. Loading from ${tryLoadPackage} as class`)220 return CheckClass(this.buildScriptContext, this.caps, args)221 } else if (isClass(CheckClass.PluginClass)) {222 debug(`Loading ${ref} ${hookType}. Using src for require. Loading from ${tryLoadPackage} as class using PluginClass.`)223 return new CheckClass.PluginClass(this.buildScriptContext, this.caps, args)224 } else {225 throw new Error(`${tryLoadPackage} class or function expected`)226 }227 } catch (err) {228 loadErr.push(`Failed to fetch ${ref} ${hookType} from ${tryLoadPackage} - ${util.inspect(err)}`)229 }230 const tryLoadFile = path.resolve(process.cwd(), src)231 if (fs.existsSync(tryLoadFile)) {232 _checkUnsafe()233 try {234 let CheckClass = require(tryLoadFile)235 if (CheckClass.default) {236 CheckClass = CheckClass.default237 }238 if (isClass(CheckClass)) {239 debug(`Loading ${ref} ${hookType}. Using src as relative path to module with a class. Loading from ${tryLoadFile} as class`)240 return new CheckClass(this.buildScriptContext, this.caps, args)241 } else if (_.isFunction(CheckClass)) {242 debug(`Loading ${ref} ${hookType}. Using src as relative path to module with a function. Loading from ${tryLoadFile} as class`)243 return CheckClass(this.buildScriptContext, this.caps, args)244 } else if (isClass(CheckClass.PluginClass)) {245 debug(`Loading ${ref} ${hookType}. Using src as relative path to module with a class. Loading from ${tryLoadFile} as class using PluginClass`)246 return new CheckClass.PluginClass(this.buildScriptContext, this.caps, args)247 } else {248 throw new Error(`${tryLoadFile} class or function expected`)249 }250 } catch (err) {251 loadErr.push(`Failed to fetch ${ref} ${hookType} from ${tryLoadFile} - ${util.inspect(err)} `)252 }253 }254 loadErr.forEach(debug)255 throw new Error(`Failed to fetch ${ref} ${hookType}, no idea how to load ...`)256 }...

Full Screen

Full Screen

product.js

Source:product.js Github

copy

Full Screen

1/*!2 impleCode Product Scripts v1.0.0 - 2014-02-113 Manages product related scripts4 (c) 2014 Norbert Dreszer - https://implecode.com5 */67jQuery( document ).ready( function ( $ ) {8 reponsive_product_catalog();9 setTimeout( "modern_grid_font_size()", 0 );10 $( window ).resize( function () {11 reponsive_product_catalog();12 setTimeout( "modern_grid_font_size()", 0 );13 } );14 if ( typeof colorbox == 'object' && $( ".a-product-image" ).length ) {15 $( ".a-product-image" ).colorbox( product_object.lightbox_settings );16 }1718 jQuery( ".product_order_selector" ).change( function () {19 jQuery(this).parent(".product_order" ).submit();20 } );21 22 jQuery(".dismiss-empty-bar").click(function(e) {23 e.preventDefault();24 var data = {25 'action': 'hide_empty_bar_message'26 };27 jQuery.post( product_object.ajaxurl, data, function () {28 jQuery("div.product-sort-bar").hide('slow');29 } );30 });3132 $.ic = {33 /**34 * Implement a WordPress-link Hook System for Javascript 35 * TODO: Change 'tag' to 'args', allow number (priority), string (tag), object (priority+tag)36 */37 hooks: { action: { }, filter: { } },38 addAction: function ( action, callable, tag ) {39 jQuery.ic.addHook( 'action', action, callable, tag );40 },41 addFilter: function ( action, callable, tag ) {42 jQuery.ic.addHook( 'filter', action, callable, tag );43 },44 doAction: function ( action, args ) {45 jQuery.ic.doHook( 'action', action, null, args );46 },47 applyFilters: function ( action, value, args ) {48 return jQuery.ic.doHook( 'filter', action, value, args );49 },50 removeAction: function ( action, tag ) {51 jQuery.ic.removeHook( 'action', action, tag );52 },53 removeFilter: function ( action, tag ) {54 jQuery.ic.removeHook( 'filter', action, tag );55 },56 addHook: function ( hookType, action, callable, tag ) {57 if ( undefined == jQuery.ic.hooks[hookType][action] ) {58 jQuery.ic.hooks[hookType][action] = [ ];59 }60 var hooks = jQuery.ic.hooks[hookType][action];61 if ( undefined == tag ) {62 tag = action + '_' + hooks.length;63 }64 jQuery.ic.hooks[hookType][action].push( { tag: tag, callable: callable } );65 },66 doHook: function ( hookType, action, value, args ) {67 if ( undefined != jQuery.ic.hooks[hookType][action] ) {68 var hooks = jQuery.ic.hooks[hookType][action];69 for ( var i = 0; i < hooks.length; i++ ) {70 if ( 'action' == hookType ) {71 hooks[i].callable( args );72 } else {73 value = hooks[i].callable( value, args );74 }75 }76 }77 if ( 'filter' == hookType ) {78 return value;79 }80 },81 removeHook: function ( hookType, action, tag ) {82 if ( undefined != jQuery.ic.hooks[hookType][action] ) {83 var hooks = jQuery.ic.hooks[hookType][action];84 for ( var i = hooks.length - 1; i >= 0; i-- ) {85 if ( undefined == tag || tag == hooks[i].tag )86 hooks.splice( i, 1 );87 }88 }89 }90 }91} );9293function reponsive_product_catalog() {94 var list_width = jQuery( ".product-list" ).width();95 var product_page_width = jQuery( "article.al_product" ).width();96 if ( list_width < 600 ) {97 jQuery( ".product-list" ).addClass( "responsive" );98 }99 else {100 jQuery( ".product-list" ).removeClass( "responsive" );101 }102 if ( product_page_width < 600 ) {103 jQuery( "article.al_product" ).addClass( "responsive" );104 }105 else {106 jQuery( "article.al_product" ).removeClass( "responsive" );107 }108}109110function modern_grid_font_size() {111 var fontSize = jQuery( ".modern-grid-element" ).width() * 0.08;112 if ( fontSize < 16 ) {113 jQuery( ".modern-grid-element h3" ).css( 'font-size', fontSize );114 jQuery( ".modern-grid-element .product-price" ).css( 'font-size', fontSize );115 fontSize = fontSize * 0.8;116 jQuery( ".modern-grid-element .product-attributes table" ).css( 'font-size', fontSize );117 } ...

Full Screen

Full Screen

donate.js

Source:donate.js Github

copy

Full Screen

1;2(function ($) {3 // global4 window.TP_Donate_Global = {5 hooks: {action: {}, filter: {}},6 addAction: function (action, callback, priority, context) {7 this.addHook('action', action, callback, priority, context);8 },9 addFilter: function (action, callback, priority, context) {10 this.addHook('filter', action, callback, priority, context);11 },12 doAction: function (action) {13 this.doHook('action', action, arguments);14 },15 applyFilters: function (action) {16 return this.doHook('filter', action, arguments);17 },18 removeAction: function (action, callback, priority, context) {19 this.removeHook('action', action, callback, priority, context);20 },21 removeFilter: function (action, callback, context) {22 this.removeHook('filter', action, callback, context);23 },24 addHook: function (hookType, action, callback, priority, context) {25 priority = parseInt(( priority || 10 ), 10);26 if (undefined == this.hooks[hookType][action]) {27 this.hooks[hookType][action] = [];28 }29 var hooks = this.hooks[hookType][action];30 if (undefined == context) {31 context = action + '_' + hooks.length;32 }33 this.hooks[hookType][action].push({callback: callback, priority: priority, context: context});34 },35 doHook: function (hookType, action, args) {36 args = Array.prototype.slice.call(args, 1);37 var value = args[0];38 if (undefined != this.hooks[hookType][action]) {39 var hooks = this.hooks[hookType][action];40 hooks.sort(function (a, b) {41 return a['priority'] - b['priority'];42 });43 for (var i = 0; i < hooks.length; i++) {44 var hook = hooks[i];45 if (typeof hook.callback == 'string') {46 hook.callback = window[hook.callback];47 }48 if ('action' == hookType) {49 hook.callback.apply(hook.context, args);50 } else {51 args.unshift(value);52 value = hook.callback.apply(hook.context, args);53 }54 }55 }56 if ('filter' == hookType) {57 return value;58 }59 },60 removeHook: function (hookType, action, callback, priority, context) {61 if (undefined != this.hooks[hookType][action]) {62 var hooks = this.hooks[hookType][action];63 for (var i = hooks.length - 1; i >= 0; i--) {64 var hook = hooks[i];65 if (hook.priority == priority && context == hook.context) {66 hooks.splice(i, 1);67 }68 }69 this.hooks[hookType][action] = hooks;70 }71 },72 beforeAjax: function () {73 $('.donate_ajax_overflow').addClass('active');74 },75 afterAjax: function () {76 $('.donate_ajax_overflow').removeClass('active');77 },78 processing: function () {79 $('.donate_submit').text(thimpress_donate.i18n['processing']);80 },81 complete: function () {82 $('.donate_submit').text(thimpress_donate.i18n['complete']);83 }84 };...

Full Screen

Full Screen

globals.js

Source:globals.js Github

copy

Full Screen

1;2( function ( $ ) {3 // global4 window.TP_Donate_Global = {5 hooks: {action: {}, filter: {}},6 addAction: function ( action, callback, priority, context ) {7 this.addHook( 'action', action, callback, priority, context );8 },9 addFilter: function ( action, callback, priority, context ) {10 this.addHook( 'filter', action, callback, priority, context );11 },12 doAction: function ( action ) {13 this.doHook( 'action', action, arguments );14 },15 applyFilters: function ( action ) {16 return this.doHook( 'filter', action, arguments );17 },18 removeAction: function ( action, callback, priority, context ) {19 this.removeHook( 'action', action, callback, priority, context );20 },21 removeFilter: function ( action, callback, context ) {22 this.removeHook( 'filter', action, callback, context );23 },24 addHook: function ( hookType, action, callback, priority, context ) {25 priority = parseInt( ( priority || 10 ), 10 );26 if ( undefined == this.hooks[hookType][action] ) {27 this.hooks[hookType][action] = [ ];28 }29 var hooks = this.hooks[hookType][action];30 if ( undefined == context ) {31 context = action + '_' + hooks.length;32 }33 this.hooks[hookType][action].push( {callback: callback, priority: priority, context: context} );34 },35 doHook: function ( hookType, action, args ) {36 args = Array.prototype.slice.call( args, 1 );37 var value = args[0];38 if ( undefined != this.hooks[hookType][action] ) {39 var hooks = this.hooks[hookType][action];40 hooks.sort( function ( a, b ) {41 return a['priority'] - b['priority'];42 } );43 for ( var i = 0; i < hooks.length; i++ ) {44 var hook = hooks[i];45 if ( typeof hook.callback == 'string' ) {46 hook.callback = window[hook.callback];47 }48 if ( 'action' == hookType ) {49 hook.callback.apply( hook.context, args );50 } else {51 args.unshift( value );52 value = hook.callback.apply( hook.context, args );53 }54 }55 }56 if ( 'filter' == hookType ) {57 return value;58 }59 },60 removeHook: function ( hookType, action, callback, priority, context ) {61 if ( undefined != this.hooks[hookType][action] ) {62 var hooks = this.hooks[hookType][action];63 for ( var i = hooks.length - 1; i >= 0; i-- ) {64 var hook = hooks[i];65 if ( hook.priority == priority && context == hook.context ) {66 hooks.splice( i, 1 );67 }68 }69 this.hooks[hookType][action] = hooks;70 }71 },72 beforeAjax: function () {73 $( '.donate_ajax_overflow' ).addClass( 'active' );74 },75 afterAjax: function () {76 $( '.donate_ajax_overflow' ).removeClass( 'active' );77 }78 };...

Full Screen

Full Screen

gforms_hooks.js

Source:gforms_hooks.js Github

copy

Full Screen

1//----------------------------------------------------------2//------ JAVASCRIPT HOOK FUNCTIONS FOR GRAVITY FORMS -------3//----------------------------------------------------------4if ( ! gform ) {5 document.addEventListener( 'gform_main_scripts_loaded', function() { gform.scriptsLoaded = true; } );6 window.addEventListener( 'DOMContentLoaded', function() { gform.domLoaded = true; } );7 var gform = {8 domLoaded: false,9 scriptsLoaded: false,10 initializeOnLoaded: function( fn ) {11 if ( gform.domLoaded && gform.scriptsLoaded ) {12 fn();13 } else if( ! gform.domLoaded && gform.scriptsLoaded ) {14 window.addEventListener( 'DOMContentLoaded', fn );15 } else {16 document.addEventListener( 'gform_main_scripts_loaded', fn );17 }18 },19 hooks: { action: {}, filter: {} },20 addAction: function( action, callable, priority, tag ) {21 gform.addHook( 'action', action, callable, priority, tag );22 },23 addFilter: function( action, callable, priority, tag ) {24 gform.addHook( 'filter', action, callable, priority, tag );25 },26 doAction: function( action ) {27 gform.doHook( 'action', action, arguments );28 },29 applyFilters: function( action ) {30 return gform.doHook( 'filter', action, arguments );31 },32 removeAction: function( action, tag ) {33 gform.removeHook( 'action', action, tag );34 },35 removeFilter: function( action, priority, tag ) {36 gform.removeHook( 'filter', action, priority, tag );37 },38 addHook: function( hookType, action, callable, priority, tag ) {39 if ( undefined == gform.hooks[hookType][action] ) {40 gform.hooks[hookType][action] = [];41 }42 var hooks = gform.hooks[hookType][action];43 if ( undefined == tag ) {44 tag = action + '_' + hooks.length;45 }46 if( priority == undefined ){47 priority = 10;48 }49 gform.hooks[hookType][action].push( { tag:tag, callable:callable, priority:priority } );50 },51 doHook: function( hookType, action, args ) {52 // splice args from object into array and remove first index which is the hook name53 args = Array.prototype.slice.call(args, 1);54 if ( undefined != gform.hooks[hookType][action] ) {55 var hooks = gform.hooks[hookType][action], hook;56 //sort by priority57 hooks.sort(function(a,b){return a["priority"]-b["priority"]});58 hooks.forEach( function( hookItem ) {59 hook = hookItem.callable;60 if(typeof hook != 'function')61 hook = window[hook];62 if ( 'action' == hookType ) {63 hook.apply(null, args);64 } else {65 args[0] = hook.apply(null, args);66 }67 } );68 }69 if ( 'filter'==hookType ) {70 return args[0];71 }72 },73 removeHook: function( hookType, action, priority, tag ) {74 if ( undefined != gform.hooks[hookType][action] ) {75 var hooks = gform.hooks[hookType][action];76 hooks = hooks.filter( function(hook, index, arr) {77 var removeHook = (undefined==tag||tag==hook.tag) && (undefined==priority||priority==hook.priority);78 return !removeHook;79 } );80 gform.hooks[hookType][action] = hooks;81 }82 }83 };...

Full Screen

Full Screen

hook.js

Source:hook.js Github

copy

Full Screen

1const Hook = {2 hooks: {action: {}, filter: {}},3 addAction: function (action, callable, priority, tag) {4 this.addHook('action', action, callable, priority, tag);5 return this;6 },7 addFilter: function (action, callable, priority, tag) {8 this.addHook('filter', action, callable, priority, tag);9 return this;10 },11 doAction: function (action) {12 this.doHook('action', action, arguments);13 return this;14 },15 applyFilters: function (action) {16 return this.doHook('filter', action, arguments);17 },18 removeAction: function (action, tag) {19 this.removeHook('action', action, tag);20 return this;21 },22 removeFilter: function (action, priority, tag) {23 this.removeHook('filter', action, priority, tag);24 return this;25 },26 addHook: function (hookType, action, callable, priority, tag) {27 if (undefined === this.hooks[hookType][action]) {28 this.hooks[hookType][action] = [];29 }30 var hooks = this.hooks[hookType][action];31 if (undefined === tag) {32 tag = action + '_' + hooks.length;33 }34 this.hooks[hookType][action].push({tag: tag, callable: callable, priority: priority});35 return this;36 },37 doHook: function (hookType, action, args) {38 // splice args from object into array and remove first index which is the hook name39 args = Array.prototype.slice.call(args, 1);40 if (undefined !== this.hooks[hookType][action]) {41 var hooks = this.hooks[hookType][action], hook;42 //sort by priority43 hooks.sort(function (a, b) {44 return a["priority"] - b["priority"];45 });46 for (var i = 0; i < hooks.length; i++) {47 hook = hooks[i].callable;48 if (typeof hook !== 'function')49 hook = window[hook];50 if ('action' === hookType) {51 hook.apply(null, args);52 } else {53 args[0] = hook.apply(null, args);54 }55 }56 }57 if ('filter' === hookType) {58 return args[0];59 }60 return this;61 },62 removeHook: function (hookType, action, priority, tag) {63 if (undefined !== this.hooks[hookType][action]) {64 var hooks = this.hooks[hookType][action];65 for (var i = hooks.length - 1; i >= 0; i--) {66 if ((undefined === tag || tag === hooks[i].tag) && (undefined === priority || priority === hooks[i].priority)) {67 hooks.splice(i, 1);68 }69 }70 }71 return this;72 }73};...

Full Screen

Full Screen

process-actions.js

Source:process-actions.js Github

copy

Full Screen

1import ErrorStackParser from "error-stack-parser";23export function begin(data){4 process.send({5 message : "BEGIN",6 data : data7 });8}910export function suiteEnd(suite){11 process.send({12 message : "SUITE_END",13 data : {14 id : suite.id15 }16 })17}1819export function startTest(test){20 process.send({21 message : "START_TEST",22 data : {23 id : test.id24 }25 });26}2728export function passTest(test){29 process.send({30 message : "END_TEST",31 data : {32 id : test.id,33 state : test.state34 }35 });36}373839export function failTest(test, error){40 if(test.type === "hook"){41 //TODO find a better way to check hook type42 var hookType;43 if(test.title === "\"after all\" hook"){44 hookType = "AFTER_ALL";45 }else if(test.title === "\"before all\" hook"){46 hookType = "BEFORE_ALL";47 }else if(test.title.indexOf("\"after each\"") > -1){48 hookType = "AFTER_EACH";49 }else if(test.title.indexOf("\"before each\"") > -1){50 hookType = "BEFORE_EACH";51 }52 process.send({53 message : hookType,54 data : {55 hookType : hookType,56 suiteId : test.parent.id,57 state : test.state,58 title : test.title,59 error : {60 message : error.message,61 stack : ErrorStackParser.parse(error)62 }63 }64 });65 }else{66 process.send({67 message : "END_TEST",68 data : {69 id : test.id,70 state : test.state,71 error : {72 message : error.message,73 stack : ErrorStackParser.parse(error)74 }75 }76 });77 }78}7980export function done(data){81 process.send({82 message : "END",83 data : {84 stats : data.stats85 }86 }); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { hookType } = require('playwright/lib/utils/utils');2const { hookType } = require('playwright/lib/utils/utils');3const { hookType } = require('playwright/lib/utils/utils');4const { hookType } = require('playwright/lib/utils/utils');5const { hookType } = require('playwright/lib/utils/utils');6const { hookType } = require('playwright/lib/utils/utils');7const { hookType } = require('playwright/lib/utils/utils');8const { hookType } = require('playwright-internal-api');9const { hookType } = require('playwright-interna

Full Screen

Using AI Code Generation

copy

Full Screen

1const { hookType } = require('@playwright/test/lib/runner');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const title = await page.title();5 console.log(title);6});7test.beforeEach(async ({ page }) => {8 const hook = hookType();9 console.log(hook);10});11test.afterEach(async ({ page }) => {12 const hook = hookType();13 console.log(hook);14});15- [Playwright GitHub](

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful