How to use callHook method in Playwright Internal

Best JavaScript code snippet using playwright-internal

init.js

Source:init.js Github

copy

Full Screen

...251 * @param {String} hookName252 * @param {Object} event253 * @param {Boolean} force254 */255 function callHook(hookName, event, force) {256 var hook = hooks[hookName],257 i;258 if (hook === undefined) {259 return;260 }261 if (hookName === 'command') {262 i = getHookIndex($.getCommandScript(event.getCommand()), hookName);263 try {264 hook.handlers[i].handler(event);265 } catch (ex) {266 $.log.error('(hook.call, ' + hookName + ', ' + hook.handlers[i].scriptName + ') ' + ex);267 }268 } else {269 for (i in hook.handlers) {270 if (isModuleEnabled(hook.handlers[i].scriptName) || force) {271 try {272 hook.handlers[i].handler(event);273 } catch (ex) {274 $.log.error('(hook.call, ' + hookName + ', ' + hook.handlers[i].scriptName + ') ' + ex);275 }276 }277 }278 }279 }280 /*281 * @function init - Loads everything for the scripts.282 */283 function init() {284 // Generate JavaScript trampolines for Java functions.285 generateJavaTrampolines();286 // Register events.287 events();288 // Load all core modules.289 loadScript('./core/misc.js');290 loadScript('./core/jsTimers.js');291 loadScript('./core/updates.js');292 loadScript('./core/chatModerator.js');293 loadScript('./core/fileSystem.js');294 loadScript('./core/lang.js');295 loadScript('./core/commandPause.js');296 loadScript('./core/logging.js');297 loadScript('./core/commandRegister.js');298 loadScript('./core/whisper.js');299 loadScript('./core/commandCoolDown.js');300 loadScript('./core/keywordCoolDown.js');301 loadScript('./core/gameMessages.js');302 loadScript('./core/patternDetector.js');303 loadScript('./core/permissions.js');304 loadScript('./core/streamInfo.js');305 loadScript('./core/timeSystem.js');306 loadScript('./core/initCommands.js');307 loadScript('./core/panelCommands.js');308 // Load all the other modules.309 loadScriptRecursive('.');310 // Load Discord modules if need be.311 if (!$.hasDiscordToken) {312 loadScript('./discord/core/misc.js');313 loadScript('./discord/core/accountLink.js');314 loadScript('./discord/core/patternDetector.js');315 loadScript('./discord/core/moderation.js');316 loadScript('./discord/core/registerCommand.js');317 loadScript('./discord/core/accountLink.js');318 loadScript('./discord/core/commandCooldown.js');319 loadScript('./discord/core/roleManager.js');320 // Load the other discord modules321 loadScriptRecursive('./discord');322 // Mark that we are using Discord.323 // This is used by the new panel.324 $.inidb.set('panelData', 'hasDiscord', 'true');325 } else {326 $.inidb.set('panelData', 'hasDiscord', 'false');327 }328 // Load new panel handler.329 loadScript('./core/panelHandler.js', false, true);330 $.log.event('Bot modules loaded. Initializing main functions...');331 // Register custom commands.332 $.addComRegisterCommands();333 $.addComRegisterAliases();334 consoleLn('');335 if ($.isNightly) {336 consoleLn('PhantomBot Nightly Build - No Support is Provided');337 consoleLn('Please report bugs including the date of the Nightly Build and Repo Version to:');338 consoleLn('https://community.phantombot.tv/c/support/bug-reports');339 } else if ($.isPrerelease) {340 consoleLn('PhantomBot Pre-Release Build - Please Report Bugs and Issues Found');341 consoleLn('When reporting bugs or issues, please remember to indicate that this is a pre-release build.');342 } else {343 consoleLn('For support please visit: https://community.phantombot.tv');344 }345 consoleLn('');346 }347 /*348 * @function events - registers all events with the core.349 */350 function events() {351 // Load all API events.352 /*353 * @event ircModeration354 */355 $api.on($script, 'ircModeration', function(event) {356 $.performModeration(event);357 });358 /*359 * @event ircChannelMessage360 */361 $api.on($script, 'ircChannelMessage', function(event) {362 callHook('ircChannelMessage', event, false);363 if (isModuleEnabled('./handlers/panelHandler.js')) {364 $.panelDB.updateChatLinesDB(event.getSender());365 }366 });367 /*368 * @event ircChannelUserMode369 */370 $api.on($script, 'ircChannelUserMode', function(event) {371 callHook('ircChannelUserMode', event, false);372 if (event.getUser().equalsIgnoreCase($.botName) && event.getMode().equalsIgnoreCase('O')) {373 if (event.getAdd().toString().equals('true')) {374 if (isReady === false) {375 // Bot is now ready.376 consoleLn($.botName + ' ready!');377 // Call the initReady event.378 callHook('initReady', null, false);379 }380 isReady = true;381 }382 }383 });384 /*385 * @event command386 */387 $api.on($script, 'command', function(event) {388 var sender = event.getSender(),389 command = event.getCommand(),390 args = event.getArgs(),391 subCommand = $.getSubCommandFromArguments(command, args),392 isMod = $.isModv3(sender, event.getTags());393 // Check if the command exists or if the module is disabled.394 if (!$.commandExists(command) || !isModuleEnabled($.getCommandScript(command))) {395 return;396 } else397 // Check if the command has an alias.398 if ($.aliasExists(command)) {399 var alias = $.getIniDbString('aliases', command),400 aliasArguments = '';401 if (alias.indexOf(';') === -1) {402 var parts = alias.split(' ', 2);403 $.command.run(sender, parts[0], ((parts[1] !== undefined ? parts[1] : '') + ' ' + args.join(' ')), event.getTags());404 } else {405 var parts = alias.split(';');406 for (var i = 0; i < parts.length; i++) {407 command = parts[i].split(' ');408 $.command.run(sender, command[0], ((command[1] !== undefined ? command[1] : '') + ' ' + args.join(' ')), event.getTags());409 }410 }411 return;412 } else413 // Check the command permission.414 if ($.permCom(sender, command, subCommand) !== 0) {415 $.sayWithTimeout($.whisperPrefix(sender) + $.lang.get('cmd.perm.404', (!$.subCommandExists(command, subCommand) ? $.getCommandGroupName(command) : $.getSubCommandGroupName(command, subCommand))), $.getIniDbBoolean('settings', 'permComMsgEnabled', false));416 consoleDebug('Command !' + command + ' was not sent due to the user not having permission for it.');417 return;418 } else419 // Check the command cooldown.420 if ($.coolDown.get(command, sender, isMod) !== 0) {421 $.sayWithTimeout($.whisperPrefix(sender) + $.lang.get('init.cooldown.msg', command, $.coolDown.getSecs(sender, command)), $.getIniDbBoolean('settings', 'coolDownMsgEnabled', false));422 consoleDebug('Command !' + command + ' was not sent due to it being on cooldown.');423 return;424 } else425 // Check the command cost.426 if ($.priceCom(sender, command, subCommand, isMod) === 1) {427 $.sayWithTimeout($.whisperPrefix(sender) + $.lang.get('cmd.needpoints', $.getPointsString($.getCommandPrice(command, subCommand, ''))), $.getIniDbBoolean('settings', 'priceComMsgEnabled', false));428 consoleDebug('Command !' + command + ' was not sent due to the user not having enough points.');429 return;430 }431 // Call the command function.432 callHook('command', event, false);433 // Decrease or add points after the command is sent to not slow anything down.434 if ($.priceCom(sender, command, subCommand, isMod) === 0) {435 $.inidb.decr('points', sender, $.getCommandPrice(command, subCommand, ''));436 } else if ($.payCom(command) === 0) {437 $.inidb.incr('points', sender, $.getCommandPay(command));438 }439 });440 /*441 * @event discordChannelCommand442 */443 $api.on($script, 'discordChannelCommand', function(event) {444 var username = event.getUsername(),445 command = event.getCommand(),446 channel = event.getChannel(),447 isAdmin = event.isAdmin(),448 senderId = event.getSenderId(),449 args = event.getArgs();450 if ($.discord.commandExists(command) === false && ($.discord.aliasExists(command) === false || $.discord.aliasExists(command) === true && $.discord.commandExists($.discord.getCommandAlias(command)) === false)) {451 return;452 }453 if ($.discord.aliasExists(command) === true) {454 command = event.setCommand($.discord.getCommandAlias(command));455 }456 if (isAdmin == false && $.discord.permCom(command, (args[0] !== undefined && $.discord.subCommandExists(command, args[0].toLowerCase()) ? args[0].toLowerCase() : '')) !== 0) {457 return;458 }459 if (isAdmin == false && $.discord.cooldown.get(command, senderId) !== 0) {460 return;461 }462 if ($.discord.getCommandCost(command) > 0 && $.discord.getUserPoints(senderId) < $.discord.getCommandCost(command)) {463 return;464 }465 if ($.discord.getCommandChannel(command, channel) === undefined && $.discord.getCommandChannel(command, '_default_global_') === undefined) {466 return;467 } else {468 if (($.discord.getCommandChannel(command, channel) !== undefined && !$.discord.getCommandChannel(command, channel).equalsIgnoreCase(channel)) && $.discord.getCommandChannel(command, '_default_global_') != '') {469 return;470 }471 }472 callHook('discordChannelCommand', event, false);473 // Do this last to not slow down the command hook.474 if ($.discord.getCommandCost(command) > 0) {475 $.discord.decrUserPoints(senderId, $.discord.getCommandCost(command));476 }477 });478 /*479 * @event consoleInput480 */481 $api.on($script, 'consoleInput', function(event) {482 callHook('consoleInput', event, false);483 });484 /*485 * @event twitchFollow486 */487 $api.on($script, 'twitchFollow', function(event) {488 callHook('twitchFollow', event, false);489 });490 /*491 * @event twitchUnFollow492 */493 $api.on($script, 'twitchUnfollow', function(event) {494 callHook('twitchUnfollow', event, false);495 });496 /*497 * @event twitchFollowsInitialized498 */499 $api.on($script, 'twitchFollowsInitialized', function(event) {500 callHook('twitchFollowsInitialized', event, false);501 });502 /*503 * @event twitchHosted504 */505 $api.on($script, 'twitchHosted', function(event) {506 callHook('twitchHosted', event, false);507 });508 /*509 * @event twitchAutoHosted510 */511 $api.on($script, 'twitchAutoHosted', function(event) {512 callHook('twitchAutoHosted', event, false);513 });514 /*515 * @event twitchHostsInitialized516 */517 $api.on($script, 'twitchHostsInitialized', function(event) {518 callHook('twitchHostsInitialized', event, false);519 });520 /*521 * @event twitchClip522 */523 $api.on($script, 'twitchClip', function(event) {524 callHook('twitchClip', event, false);525 });526 /*527 * @event ircChannelJoin528 */529 $api.on($script, 'ircChannelJoin', function(event) {530 callHook('ircChannelJoin', event, false);531 });532 /*533 * @event ircChannelUsersUpdate534 */535 $api.on($script, 'ircChannelUsersUpdate', function(event) {536 callHook('ircChannelUsersUpdate', event, false);537 });538 /*539 * @event ircChannelLeave540 */541 $api.on($script, 'ircChannelLeave', function(event) {542 callHook('ircChannelLeave', event, false);543 });544 /*545 * @event ircJoinComplete546 */547 $api.on($script, 'ircJoinComplete', function(event) {548 callHook('ircJoinComplete', event, false);549 });550 /*551 * @event ircConnectComplete552 */553 $api.on($script, 'ircConnectComplete', function(event) {554 callHook('ircConnectComplete', event, false);555 });556 /*557 * @event ircPrivateMessage558 */559 $api.on($script, 'ircPrivateMessage', function(event) {560 callHook('ircPrivateMessage', event, false);561 });562 /*563 * @event ircClearchat564 */565 $api.on($script, 'ircClearchat', function(event) {566 callHook('ircClearchat', event, false);567 });568 /*569 * @event streamLabsDonation570 */571 $api.on($script, 'streamLabsDonation', function(event) {572 callHook('streamLabsDonation', event, false);573 });574 /*575 * @event streamLabsDonationInitialized576 */577 $api.on($script, 'streamLabsDonationInitialized', function(event) {578 callHook('streamLabsDonationInitialized', event, false);579 });580 /*581 * @event tipeeeStreamDonationInitialized582 */583 $api.on($script, 'tipeeeStreamDonationInitialized', function(event) {584 callHook('tipeeeStreamDonationInitialized', event, false);585 });586 /*587 * @event tipeeeStreamDonation588 */589 $api.on($script, 'tipeeeStreamDonation', function(event) {590 callHook('tipeeeStreamDonation', event, false);591 });592 /*593 * @event streamElementsDonationInitialized594 */595 $api.on($script, 'streamElementsDonationInitialized', function(event) {596 callHook('streamElementsDonationInitialized', event, false);597 });598 /*599 * @event streamElementsDonation600 */601 $api.on($script, 'streamElementsDonation', function(event) {602 callHook('streamElementsDonation', event, false);603 });604 /*605 * @event getEmotes606 */607 $api.on($script, 'emotesGet', function(event) {608 callHook('emotesGet', event, false);609 });610 /*611 * @event yTPlayerConnect612 */613 $api.on($script, 'yTPlayerConnect', function(event) {614 callHook('yTPlayerConnect', event, false);615 });616 /*617 * @event yTPlayerLoadPlaylistEvent618 */619 $api.on($script, 'yTPlayerLoadPlaylist', function(event) {620 callHook('yTPlayerLoadPlaylist', event, false);621 });622 /*623 * @event yTPlayerDisconnect624 */625 $api.on($script, 'yTPlayerDisconnect', function(event) {626 callHook('yTPlayerDisconnect', event, false);627 });628 /*629 * @event yTPlayerState630 */631 $api.on($script, 'yTPlayerState', function(event) {632 callHook('yTPlayerState', event, false);633 });634 /*635 * @event yTPlayeCurrentId636 */637 $api.on($script, 'yTPlayerCurrentId', function(event) {638 callHook('yTPlayerCurrentId', event, false);639 });640 /*641 * @event yTPlayerRequestSonglist642 */643 $api.on($script, 'yTPlayerRequestSonglist', function(event) {644 callHook('yTPlayerRequestSonglist', event, false);645 });646 /*647 * @event yTPlayerRequestPlaylist648 */649 $api.on($script, 'yTPlayerRequestPlaylist', function(event) {650 callHook('yTPlayerRequestPlaylist', event, false);651 });652 /*653 * @event yTPlayerDeleteSREvent654 */655 $api.on($script, 'yTPlayerDeleteSR', function(event) {656 callHook('yTPlayerDeleteSR', event, false);657 });658 /*659 * @event yTPlayerVolumeEvent660 */661 $api.on($script, 'yTPlayerVolume', function(event) {662 callHook('yTPlayerVolume', event, false);663 });664 /*665 * @event yTPlayerSkipSongEvent666 */667 $api.on($script, 'yTPlayerSkipSong', function(event) {668 callHook('yTPlayerSkipSong', event, false);669 });670 /*671 * @event yTPlayerDeleteCurrentEvent672 */673 $api.on($script, 'yTPlayerDeleteCurrent', function(event) {674 callHook('yTPlayerDeleteCurrent', event, false);675 });676 /*677 * @event yTPlayerStealSongEvent678 */679 $api.on($script, 'yTPlayerStealSong', function(event) {680 callHook('yTPlayerStealSong', event, false);681 });682 /*683 * @event yTPlayerSongRequestEvent684 */685 $api.on($script, 'yTPlayerSongRequest', function(event) {686 callHook('yTPlayerSongRequest', event, false);687 });688 /*689 * @event yTPlayerDeletePlaylistByIDEvent690 */691 $api.on($script, 'yTPlayerDeletePlaylistByID', function(event) {692 callHook('yTPlayerDeletePlaylistByID', event, false);693 });694 /*695 * @event yTPlayerRequestCurrentSongEvent696 */697 $api.on($script, 'yTPlayerRequestCurrentSong', function(event) {698 callHook('yTPlayerRequestCurrentSong', event, false);699 });700 /*701 * @event yTPlayerRandomizeEvent702 */703 $api.on($script, 'yTPlayerRandomize', function(event) {704 callHook('yTPlayerRandomize', event, false);705 });706 /*707 * @event gameWispChangeEvent708 */709 $api.on($script, 'gameWispChange', function(event) {710 callHook('gameWispChange', event, false);711 });712 /*713 * @event gameWispBenefitsEvent714 */715 $api.on($script, 'gameWispBenefits', function(event) {716 callHook('gameWispBenefits', event, false);717 });718 /*719 * @event gameWispSubscribeEvent720 */721 $api.on($script, 'gameWispSubscribe', function(event) {722 callHook('gameWispSubscribe', event, false);723 });724 /*725 * @event gameWispAnniversaryEvent726 */727 $api.on($script, 'gameWispAnniversary', function(event) {728 callHook('gameWispAnniversary', event, false);729 });730 /*731 * @event twitterEvent732 */733 $api.on($script, 'twitter', function(event) {734 callHook('twitter', event, false);735 });736 /*737 * @event twitterRetweetEvent738 */739 $api.on($script, 'twitterRetweet', function(event) {740 callHook('twitterRetweet', event, false);741 });742 /*743 * @event twitchOnlineEvent744 */745 $api.on($script, 'twitchOnline', function(event) {746 callHook('twitchOnline', event, false);747 });748 /*749 * @event twitchOfflineEvent750 */751 $api.on($script, 'twitchOffline', function(event) {752 callHook('twitchOffline', event, false);753 });754 /*755 * @event twitchGameChangeEvent756 */757 $api.on($script, 'twitchGameChange', function(event) {758 callHook('twitchGameChange', event, false);759 });760 /*761 * @event twitchTitleChangeEvent762 */763 $api.on($script, 'twitchTitleChange', function(event) {764 callHook('twitchTitleChange', event, false);765 });766 /*767 * @event twitchSubscriber768 */769 $api.on($script, 'twitchSubscriber', function(event) {770 callHook('twitchSubscriber', event, false);771 });772 /*773 * @event twitchPrimeSubscriber774 */775 $api.on($script, 'twitchPrimeSubscriber', function(event) {776 callHook('twitchPrimeSubscriber', event, false);777 });778 /*779 * @event reSubscriber780 */781 $api.on($script, 'twitchReSubscriber', function(event) {782 callHook('twitchReSubscriber', event, false);783 });784 /*785 * @event twitchSubscriptionGift786 */787 $api.on($script, 'twitchSubscriptionGift', function(event) {788 callHook('twitchSubscriptionGift', event, false);789 });790 /*791 * @event twitchBits792 */793 $api.on($script, 'twitchBits', function(event) {794 callHook('twitchBits', event, false);795 });796 /*797 * @event twitchRaid798 */799 $api.on($script, 'twitchRaid', function(event) {800 callHook('twitchRaid', event, false);801 });802 /*803 * @event discordChannelMessage804 */805 $api.on($script, 'discordChannelMessage', function(event) {806 callHook('discordChannelMessage', event, false);807 });808 /*809 * @event discordChannelJoin810 */811 $api.on($script, 'discordChannelJoin', function(event) {812 callHook('discordChannelJoin', event, false);813 });814 /*815 * @event discordChannelPart816 */817 $api.on($script, 'discordChannelPart', function(event) {818 callHook('discordChannelPart', event, false);819 });820 /*821 * @event webPanelSocketUpdate822 */823 $api.on($script, 'webPanelSocketUpdate', function(event) {824 callHook('webPanelSocketUpdate', event, false);825 });826 /*827 * @event webPanelSocketConnected828 */829 $api.on($script, 'webPanelSocketConnected', function(event) {830 callHook('webPanelSocketConnected', event, false);831 });832 /*833 * @event PubSubModerationTimeout834 */835 $api.on($script, 'PubSubModerationTimeout', function(event) {836 callHook('PubSubModerationTimeout', event, false);837 });838 /*839 * @event PubSubModerationUnTimeout840 */841 $api.on($script, 'PubSubModerationUnTimeout', function(event) {842 callHook('PubSubModerationUnTimeout', event, false);843 });844 /*845 * @event PubSubModerationBan846 */847 $api.on($script, 'PubSubModerationBan', function(event) {848 callHook('PubSubModerationBan', event, false);849 });850 /*851 * @event PubSubModerationUnBan852 */853 $api.on($script, 'PubSubModerationUnBan', function(event) {854 callHook('PubSubModerationUnBan', event, false);855 });856 }857 // Export functions to API858 $.consoleLn = consoleLn;859 $.consoleDebug = consoleDebug;860 $.bind = addHook;861 $.unbind = removeHook;862 $.bot = {863 loadScriptRecursive: loadScriptRecursive,864 isModuleEnabled: isModuleEnabled,865 isModuleLoaded: isModuleLoaded,866 getModuleIndex: getModuleIndex,867 getHookIndex: getHookIndex,868 loadScript: loadScript,...

Full Screen

Full Screen

GrapplingHook#callHook.spec.js

Source:GrapplingHook#callHook.spec.js Github

copy

Full Screen

...36 .hook($.PRE_TEST, callback);37 });38 it('should throw an error for an unqualified hook', function() {39 expect(function() {40 instance.callHook('test');41 }).to.throw(/qualified/);42 });43 it('should return the instance', function() {44 var actual = instance.callHook($.PRE_TEST, foo, bar);45 expect(actual).to.equal(instance);46 });47 it('should pass `...parameters` to middleware', function() {48 instance.callHook($.PRE_TEST, foo, bar);49 expect(passed.args).to.eql([foo, bar]);50 });51 it('should pass first parameter to thenables', function(done) {52 instance53 .pre('test')54 .then(function(p) {55 expect(p).to.eql([foo, bar]);56 done();57 });58 instance.callHook($.PRE_TEST, [foo, bar]);59 });60 it('should pass `parameters[]` to middleware', function() {61 instance.callHook($.PRE_TEST, [foo, bar]);62 expect(passed.args).to.eql([[foo, bar]]);63 });64 it('should pass functions as parameters to middleware', function() {65 var f = function funcParam() {66 };67 instance.callHook($.PRE_TEST, [foo, f], NOOP);68 expect(passed.args).to.eql([[foo, f]]);69 });70 it('should execute middleware in scope `context`', function() {71 var context = {};72 instance.callHook(context, $.PRE_TEST, [foo, bar]);73 expect(passed.scope).to.equal(context);74 });75 it('should execute middleware in scope `instance` by default', function() {76 instance.callHook($.PRE_TEST, [foo, bar]);77 expect(passed.scope).to.equal(instance);78 });79 });80 describe('sequencing', function() {81 var sequence,82 instance;83 beforeEach(function() {84 sequence = [];85 instance = subject.create();86 instance.allowHooks($.PRE_TEST);87 });88 it('should finish all serial middleware in a correct sequence', function(done) {89 var expected = [90 'A (serial) setup',91 'A (serial) done',92 'B (serial) setup',93 'B (serial) done',94 'C (serial) setup',95 'C (serial) done'96 ];97 instance.pre('test',98 $.factories.createSerial('A', sequence),99 $.factories.createSerial('B', sequence),100 $.factories.createSerial('C', sequence)101 );102 instance.callHook($.PRE_TEST, function() {103 expect($.factories.toRefString(sequence)).to.eql(expected);104 done();105 });106 });107 it('should finish all parallel middleware in a correct sequence', function(done) {108 var expected = [109 'A (parallel) setup',110 'B (parallel) setup',111 'C (parallel) setup',112 'A (parallel) done',113 'C (parallel) done',114 'B (parallel) done'115 ];116 instance.pre('test',117 $.factories.createParallel('A', sequence, 0),118 $.factories.createParallel('B', sequence, 200),119 $.factories.createParallel('C', sequence, 100)120 );121 instance.callHook($.PRE_TEST, function() {122 expect($.factories.toRefString(sequence)).to.eql(expected);123 done();124 });125 });126 it('should finish all thenable middleware in a correct sequence', function(done) {127 var expected = [128 'A (thenable) setup',129 'A (thenable) done',130 'B (thenable) setup',131 'B (thenable) done',132 'C (thenable) setup',133 'C (thenable) done'134 ];135 instance.pre('test',136 $.factories.createThenable('A', sequence),137 $.factories.createThenable('B', sequence),138 $.factories.createThenable('C', sequence)139 );140 instance.callHook($.PRE_TEST, function() {141 expect($.factories.toRefString(sequence)).to.eql(expected);142 done();143 });144 });145 it('should finish "flipped" parallel middleware in a correct sequence', function(done) {146 function flippedParallel(next, done) {147 setTimeout(function() {148 sequence.push(new $.factories.Ref({149 name: 'A',150 type: 'parallel',151 phase: 'done'152 }));153 done();154 }, 0);155 setTimeout(function() {156 sequence.push(new $.factories.Ref({157 name: 'A',158 type: 'parallel',159 phase: 'setup'160 }));161 next();162 }, 100);163 }164 var expected = [165 'A (parallel) done',166 'A (parallel) setup',167 'B (parallel) setup',168 'B (parallel) done'169 ];170 instance.pre('test',171 flippedParallel,172 $.factories.createParallel('B', sequence)173 ).callHook($.PRE_TEST, function() {174 expect($.factories.toRefString(sequence)).to.eql(expected);175 done();176 });177 });178 it('should call mixed middleware in a correct sequence', function(done) {179 var expected = [180 'A (parallel) setup',181 'B (sync) done',182 'C (parallel) setup',183 'D (parallel) setup',184 'E (serial) setup',185 'A (parallel) done',186 'C (parallel) done',187 'D (parallel) done',188 'E (serial) done',189 'G (thenable) setup',190 'G (thenable) done',191 'F (serial) setup',192 'F (serial) done'193 ];194 instance.pre('test',195 $.factories.createParallel('A', sequence),196 $.factories.createSync('B', sequence),197 $.factories.createParallel('C', sequence),198 $.factories.createParallel('D', sequence),199 $.factories.createSerial('E', sequence),200 $.factories.createThenable('G', sequence),201 $.factories.createSerial('F', sequence)202 );203 instance.callHook($.PRE_TEST, function() {204 expect($.factories.toRefString(sequence)).to.eql(expected);205 done();206 });207 });208 });209 describe('synchronicity', function() {210 var instance;211 beforeEach(function() {212 instance = subject.create();213 instance.allowHooks($.PRE_TEST);214 });215 it('should finish async even with sync middleware', function(done) {216 var isAsync = false;217 instance.hook($.PRE_TEST, function() {218 }).callHook($.PRE_TEST, function() {219 expect(isAsync).to.be.true();220 done();221 });222 isAsync = true;223 });224 it('should finish async even with sync serial middleware', function(done) {225 var isAsync = false;226 instance.hook($.PRE_TEST, function(next) {227 next();228 }).callHook($.PRE_TEST, function() {229 expect(isAsync).to.be.true();230 done();231 });232 isAsync = true;233 });234 it('should finish async even with sync parallel middleware', function(done) {235 var isAsync = false;236 instance.hook($.PRE_TEST, function(next, done) {237 next();238 done();239 }).callHook($.PRE_TEST, function() {240 expect(isAsync).to.be.true();241 done();242 });243 isAsync = true;244 });245 it('should finish async even with resolved thenable middleware', function(done) {246 var promise = new P(function(resolve) {247 resolve();248 });249 var isAsync = false;250 instance.hook($.PRE_TEST, function() {251 return promise;252 }).callHook($.PRE_TEST, function() {253 expect(isAsync).to.be.true();254 done();255 });256 isAsync = true;257 });258 it('should call the next middleware sync with sync serial middleware', function(done) {259 var isAsync;260 instance.hook($.PRE_TEST, function(next) {261 isAsync = false;262 next();263 isAsync = true;264 }, function() {265 expect(isAsync).to.be.false();266 }).callHook($.PRE_TEST, function() {267 expect(isAsync).to.be.true(); // just making sure it's dezalgofied268 done();269 });270 });271 it('should call the next middleware sync with sync parallel middleware', function(done) {272 var isAsync;273 instance.hook($.PRE_TEST, function(next, done) {274 isAsync = false;275 next();276 isAsync = true;277 done();278 }, function() {279 expect(isAsync).to.be.false();280 }).callHook($.PRE_TEST, function() {281 expect(isAsync).to.be.true(); // just making sure it's dezalgofied282 done();283 });284 });285 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import Vue from 'vue';2function callHook$1(vm, hook, params) {3 var handlers = vm.$options[hook];4 if (hook === 'onError' && handlers) {5 handlers = [handlers];6 }7 var ret;8 if (handlers) {9 for (var i = 0, j = handlers.length; i < j; i++) {10 try {11 ret = handlers[i].call(vm, params);12 } catch (e) {13 handleError(e, vm, (hook + " hook"));14 }15 }16 }17 if (vm._hasHookEvent) {18 vm.$emit('hook:' + hook);19 }20 // for child21 if (vm.$children.length) {22 vm.$children.forEach(function (v) {23 return callHook$1(v, hook, params);24 });25 }26 return ret27}28function getRootVueVm(page) {29 return page.$vm.$root;30}31export default function (App) {32 return {33 // 页面的初始数据34 data: {35 $root: {}36 },37 // mp lifecycle for vue38 // 生命周期函数--监听页面加载39 onLoad(query) {40 //页面加载的时候41 const app = new Vue(App);42 // 挂载Vue对象到page上43 this.$vm = app;44 var rootVueVM = app.$root;45 46 //初始化mp对象47 if (!rootVueVM.$mp) {48 rootVueVM.$mp = {};49 }50 var mp = rootVueVM.$mp;51 mp.mpType = 'page';52 mp.page = this;53 mp.query = query;54 mp.status = 'load';55 //mount 要在 mp.status = 'load';赋值之后,不然mount方法会重复添加微信Page56 //具体原因参考mpvue核心库源码,_initMP方法57 app.$mount();58 },59 handleProxy: function handleProxy(e) {60 var rootVueVM = getRootVueVm(this);61 return rootVueVM.$handleProxyWithVue(e)62 },63 // 生命周期函数--监听页面显示64 onShow() {65 var rootVueVM = getRootVueVm(this);66 var mp = rootVueVM.$mp;67 mp.status = 'show';68 callHook$1(rootVueVM, 'onShow');69 // // 只有页面需要 setData70 rootVueVM.$nextTick(function () {71 rootVueVM._initDataToMP();72 });73 },74 // 生命周期函数--监听页面初次渲染完成75 onReady() {76 var rootVueVM = getRootVueVm(this);77 var mp = rootVueVM.$mp;78 mp.status = 'ready';79 callHook$1(rootVueVM, 'onReady');80 },81 // 生命周期函数--监听页面隐藏82 onHide: function onHide() {83 var rootVueVM = getRootVueVm(this);84 var mp = rootVueVM.$mp;85 mp.status = 'hide';86 callHook$1(rootVueVM, 'onHide');87 },88 // 生命周期函数--监听页面卸载89 onUnload: function onUnload() {90 var rootVueVM = getRootVueVm(this);91 callHook$1(rootVueVM, 'onUnload');92 rootVueVM.$destroy();93 },94 // 页面相关事件处理函数--监听用户下拉动作95 onPullDownRefresh: function onPullDownRefresh() {96 var rootVueVM = getRootVueVm(this);97 callHook$1(rootVueVM, 'onPullDownRefresh');98 },99 // 页面上拉触底事件的处理函数100 onReachBottom: function onReachBottom() {101 var rootVueVM = getRootVueVm(this);102 callHook$1(rootVueVM, 'onReachBottom');103 },104 // Do something when page scroll105 onPageScroll: function onPageScroll(options) {106 var rootVueVM = getRootVueVm(this);107 callHook$1(rootVueVM, 'onPageScroll', options);108 },109 // 当前是 tab 页时,点击 tab 时触发110 onTabItemTap: function onTabItemTap(options) {111 var rootVueVM = getRootVueVm(this);112 callHook$1(rootVueVM, 'onTabItemTap', options);113 }, // 页面相关事件处理函数--监听用户下拉动作114 onPullDownRefresh: function onPullDownRefresh() {115 var rootVueVM = getRootVueVm(this);116 callHook$1(rootVueVM, 'onPullDownRefresh');117 },118 // 页面上拉触底事件的处理函数119 onReachBottom: function onReachBottom() {120 var rootVueVM = getRootVueVm(this);121 callHook$1(rootVueVM, 'onReachBottom');122 },123 // // 用户点击右上角分享124 onShareAppMessage: App.onShareAppMessage ?125 function (options) {126 var rootVueVM = getRootVueVm(this);127 return callHook$1(rootVueVM, 'onShareAppMessage', options);128 } : null,129 // Do something when page scroll130 onPageScroll: function onPageScroll(options) {131 var rootVueVM = getRootVueVm(this);132 callHook$1(rootVueVM, 'onPageScroll', options);133 },134 // 当前是 tab 页时,点击 tab 时触发135 onTabItemTap: function onTabItemTap(options) {136 var rootVueVM = getRootVueVm(this);137 callHook$1(rootVueVM, 'onTabItemTap', options);138 }139 };...

Full Screen

Full Screen

createPage.js

Source:createPage.js Github

copy

Full Screen

1/**2 * @file swan Page wrapper3 * @author zhangwentao <winty2013@gmail.com>4 */5/* global Page */6/* global getApp */7/* eslint-disable babel/new-cap */8import pageMixin, {handleProxy, handleModel} from './mixins';9import {setData} from './data';10import {callHook} from './lifecycle';11import $api from './nativeAPI';12import Vue from '../base/vue/index';13import {state} from '../base/state';14import {mark, measure} from '../helper/perf';15import config from '../config';16import {createVue, mountVue} from '../base/createPage';17function makeCreatePage(pageMixin, {handleProxy, handleModel}, setData, callHook) {18 return function (options) {19 options.mixins = [pageMixin];20 let initData = typeof options.data === 'function' ? options.data.call({21 $api22 }) : (options.data || {});23 return {24 data: initData,25 lifetimes: {26 attached(...args) {27 createVue.call(this, options, args, {setData});28 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {29 console.log('[debug: mp pageHooks] attached', this.__uid__);30 }31 }32 },33 methods: {34 handleProxy,35 handleModel,36 onLoad(...args) {37 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {38 console.log('[debug: mp pageHooks] onLoad', this.__uid__);39 }40 // 先 callHook 保证数据可以初始化41 const ret = callHook.call(this, this.$vue, 'page', 'onLoad', args);42 mountVue.call(this, this.$vue);43 return ret;44 },45 onUnload(...args) {46 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {47 console.log('[debug: mp pageHooks] onUnload', this.__uid__);48 }49 const ret = callHook.call(this, this.$vue, 'page', 'onUnload', args);50 if (this.$vue) {51 this.$vue.$destroy();52 }53 // on wx page unload will be triggered before component detached54 setTimeout(_ => {55 const pages = getApp().__pages__;56 const uid = this.__uid__;57 if (pages[uid]) {58 pages[uid] = null;59 delete pages[uid];60 }61 });62 return ret;63 },64 onReady(...args) {65 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {66 console.log('[debug: mp pageHooks] onReady', this.__uid__);67 }68 return callHook.call(this, this.$vue, 'page', 'onReady', args);69 },70 onShow(...args) {71 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {72 console.log('[debug: mp pageHooks] onShow', this.__uid__);73 }74 return callHook.call(this, this.$vue, 'page', 'onShow', args);75 },76 onHide(...args) {77 if (process.env.NODE_ENV !== 'production' && config.debug && config.debug.lifetimes) {78 console.log('[debug: mp pageHooks] onHide', this.__uid__);79 }80 return callHook.call(this, this.$vue, 'page', 'onHide', args);81 },82 onPullDownRefresh(...args) {83 return callHook.call(this, this.$vue, 'page', 'onPullDownRefresh', args);84 },85 onReachBottom(...args) {86 return callHook.call(this, this.$vue, 'page', 'onReachBottom', args);87 },88 onShareAppMessage(...args) {89 return callHook.call(this, this.$vue, 'page', 'onShareAppMessage', args);90 },91 onPageScroll(...args) {92 return callHook.call(this, this.$vue, 'page', 'onPageScroll', args);93 },94 onTabItemTap(...args) {95 return callHook.call(this, this.$vue, 'page', 'onTabItemTap', args);96 }97 }98 };99 };100}101export default makeCreatePage(pageMixin, {102 handleProxy,103 handleModel...

Full Screen

Full Screen

lifeCycle.js

Source:lifeCycle.js Github

copy

Full Screen

...5 // 初始化事件、钩子函数6 initEvent(vm)7 // 编译 slote vnode8 initRender(vm)9 callHook(vm, 'beforeCreated')10 initRejection(vm)11 // 完成数据响应式 data prop watch computed methods12 initState(vm)13 initProvide(vm)14 cookHook('created')15 if (vm.$option.el) {16 vm.$mounted(vm.$option.el)17 }18}19function mountConponent (vm) {20 if (!vm.$option.render) {21 const { render } = compileToFunction()22 vm.$option.render = render23 }24 callHook('beforeMounted')25 const vdom = vm.$option.render()26 vm._update(vdom)27 callHook('mounted')28}29function queueWatcher (watcher) {30 nextTick(flushSchedulerQueue)31}32function flushSchedulerQueue () {33 for () {34 // callHook('beforeUpdate')35 watcher.before()36 watcher.update()37 callHook('updated')38 }39}40Vue.prototype.$destory = function () {41 callHook('beforeDestory')42 // 删除节点自身43 remove()44 // 删除依赖45 watcher.tearDown()46 // 删除监听47 vm.$off()48 callHook('afterDestory')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { callHook } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await callHook(page, 'onRequest', request => {8 console.log('Request:', request.url());9 });10 await browser.close();11})();12const { callHook } = require('playwright/lib/utils/utils');13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await callHook(page, 'onRequest', request => {19 console.log('Request:', request.url());20 });21 await callHook(page, 'onResponse', response => {22 console.log('Response:', response.url());23 });24 await browser.close();25})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { callHook } = require('playwright/lib/server/chromium/crPage');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await callHook(page, 'load', {8 initiator: { type: 'script' }9 });10 await browser.close();11})();12const { callHook } = require('playwright/lib/server/chromium/crPage');13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await callHook(page, 'load', {19 initiator: { type: 'script' }20 });21 await browser.close();22})();23const { callHook } = require('playwright/lib/server/chromium/crPage');24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const page = await context.newPage();29 await callHook(page, 'load', {30 initiator: { type: 'script' }31 });32 await browser.close();33})();34const { callHook } = require('playwright/lib/server/chromium/crPage');35const { chromium } = require('playwright');36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const page = await context.newPage();40 await callHook(page, 'load', {41 initiator: { type: 'script' }42 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { _callHook } = require('playwright/lib/server/chromium/crBrowser');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 console.log(result);7 await browser.close();8})();9{ response: { status: 200, headers: [Object], body: '...' } }10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const page = await browser.newPage();14 await page.route('**', (route) => {15 route.fulfill({16 });17 });18 await browser.close();19})();20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const page = await browser.newPage();24 await page.route('**', (route) => {25 const headers = route.request().headers();26 headers['x-added-by-playwright'] = 'yes';27 route.continue({ headers });28 });29 await browser.close();30})();31const { chromium } = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { callHook } = require('playwright/lib/server/trace/recorder');2const { callHook } = require('playwright/lib/server/trace/recorder');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const page = await browser.newPage();7 await callHook(page, 'beforeInput', { type: 'insertText', value: 'hello' });8 await callHook(page, 'afterInput', { type: 'insertText', value: 'hello' });9 await page.close();10 await browser.close();11})();12{13 "args": {14 }15}16{17 "args": {18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { callHook } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await callHook(page, 'beforeClick', { button: 'left', clickCount: 1, modifiers: [], position: { x: 0, y: 0 }, type: 'mouse' });5 await page.click('text=Click me');6 await callHook(page, 'afterClick', { button: 'left', clickCount: 1, modifiers: [], position: { x: 0, y: 0 }, type: 'mouse' });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const {callHook} = require('@playwright/test/lib/test');2const { it, expect } = require('@playwright/test');3it('should call hook', async ({ page }) => {4 await callHook('beforeEach', async () => {5 });6});

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