Best JavaScript code snippet using wpt
spyFallPollResultCollectDialog.js
Source:spyFallPollResultCollectDialog.js
1// Copyright (c) Microsoft Corporation. All rights reserved.2// Licensed under the MIT License.3const { Dialog } = require('botbuilder-dialogs');4const Resolvers = require('../../../resolvers');5const { spyfallEndGamehelper } = require('../../../helpers/games/spyfall');6const { pollCardId, pollWaitingId } = require('../../../helpers/updatableId');7const constants = require('../../../config/constants');8const SpyfallRaisePollDialogCache = require('./spyfallRaisePollDialog');9// The poll result will be collected in this dialog.10// A global dictionary will be cached to determine whether a poll is ended.11//12let sessionVoteResultMap = new Map();13class SpyfallPollResultCollectDialog extends Dialog {14 constructor(luisRecognizer) {15 super(constants.SPYFALL_POLL_RESULT_COLLECT_DIALOG);16 this._luisRecognizer = luisRecognizer;17 }18 async beginDialog(dc, options) {19 const pollResultInfo = dc.context.activity.value;20 const sessionCode = pollResultInfo.sessionCode;21 const session = await Resolvers.gameSession.getSession({ code: sessionCode });22 const spyfallPollSelectedResult = pollResultInfo.spyfallPollSelectedResult;23 session.players.push(session.host);24 const raisedPollPlayer = session.players[pollResultInfo.votePlayerIndex];25 const spyInfo = session.players[pollResultInfo.spyIndex];26 // 1. Once we catched call here, we push the value into the map.27 //28 let pollResult = null;29 if (sessionVoteResultMap.has(sessionCode)) {30 pollResult = sessionVoteResultMap.get(sessionCode);31 } else {32 pollResult = {33 votedPlayersCount: 1,34 agreedCount: 1,35 totalPlayers: session.players.length,36 isRightGuess: pollResultInfo.isRightGuess37 };38 }39 pollResult.votedPlayersCount += 140 if (spyfallPollSelectedResult === 'Agree') {41 pollResult.agreedCount += 1;42 }43 sessionVoteResultMap.set(sessionCode, pollResult);44 // 2. If we have collected all responses from every player in the specific session,45 // we can display the poll result.46 //47 if (pollResult.votedPlayersCount === pollResult.totalPlayers) {48 const isRightGuess = pollResult.isRightGuess;49 const isPollPassed = pollResult.agreedCount > pollResult.totalPlayers / 2;50 if (isPollPassed) {51 await Resolvers.countdown.kill(pollResultInfo.sessionCode);52 await spyfallEndGamehelper({53 code: sessionCode,54 res: isRightGuess ? 'voteCorrect' : 'voteWrong',55 spyIdx: pollResultInfo.spyIndex,56 voterIdx: pollResultInfo.votePlayerIndex57 });58 } else {59 // The poll is not passed. Resume the countdown.60 //61 await Resolvers.countdown.resume(pollResultInfo.sessionCode);62 // Notify session, the game is not ended.63 //64 await Resolvers.proactiveMessage.notifySession(65 pollResultInfo.sessionCode,66 `**Spyfall ${sessionCode}. Poll not pass. Resume countdown!**`67 );68 }69 // Whenever a poll is done. We should clean it from the map.70 // Besides, we need to clean the cache in the SpyFallRaisePollDialog.71 // Otherwise, it may block the further poll request and clean up all updatable session.72 //73 sessionVoteResultMap.delete(sessionCode);74 await Resolvers.proactiveMessage.deleteUpdatableSession(75 sessionCode, pollWaitingId(sessionCode));76 // Sanity check77 // DEVNOTE: However, if SpyfallRaisePollDialogCache does not have the value for78 // this sessionCode. It must be a bug, though it is transient error.79 //80 if (SpyfallRaisePollDialogCache.SpyfallRaisePollDialogCache.has(sessionCode)) {81 SpyfallRaisePollDialogCache.SpyfallRaisePollDialogCache.delete(sessionCode);82 } else {83 console.log(`WARNING: ${sessionCode} was not inserted into the SpyfallRaisePollDialogCache!`);84 }85 }86 // Handle a situation where the other player is still voting87 if (pollResult.votedPlayersCount < pollResult.totalPlayers) {88 await Resolvers.proactiveMessage.deleteUpdatableIndividual(89 options.user.aad, pollCardId(sessionCode));90 const remainingVoter = pollResult.totalPlayers - pollResult.votedPlayersCount;91 await Resolvers.proactiveMessage.notifyUpdatableSession(92 sessionCode,93 `Waiting for ${remainingVoter} players to vote`,94 pollWaitingId(sessionCode));95 }96 return await dc.endDialog();97 }98}99module.exports = {100 SpyfallPollResultCollectDialog...
axiosWrapper.js
Source:axiosWrapper.js
1import createDefensivePromise from './../utils/createDefensivePromise'2/**3 * A wrapper for the axios http library4 * @param {object} axios the core axios library5 * @param {object} Rx the Rx library6 * @param {number} maxPollTries the maximum polls to try to get the response7 * @param {number} pollingInterval time interval between polling requests8 */9export default ({ axios, Rx, maxPollTries, pollingInterval }) => ({10 get: axios.get.bind(axios),11 postWithPolling: (url, data) =>12 createDefensivePromise(async (resolve, reject) => {13 const postResponse = await axios.post(url, data)14 .catch(e => e.response || e)15 if (postResponse.status === 202) {16 // Request has been accepted for processing17 const requestToken = postResponse.data.requestToken18 const _pollResult = {19 requestToken,20 locked: false,21 completed: false,22 succeeded: false,23 error: new Error(`Exhausted all (${maxPollTries}) poll tries`)24 }25 Rx.Observable26 .interval(pollingInterval)27 .take(maxPollTries)28 .map(_ => _pollResult)29 .map(pollResult => {30 if (!(pollResult.locked) && !(pollResult.completed)) {31 pollResult.locked = true32 axios.post(url, { requestToken }).catch(e => e.response || e)33 .then(pollResponse => {34 if (pollResponse.status === 200) {35 // successfully posted data36 pollResult.completed = true37 pollResult.succeeded = true38 pollResult.error = null39 } else if (pollResponse.status === 202) {40 // still processing41 pollResult.locked = false42 } else if (pollResponse.status === 500) {43 // failed to post data44 pollResult.completed = true45 pollResult.succeeded = false46 pollResult.error = new Error(`Failed: ${pollResponse.data}`)47 } else if (pollResponse.status === 404) {48 // requestToken not found49 pollResult.completed = true50 pollResult.succeeded = false51 pollResult.error =52 new Error(`RequestID (${requestToken}) not found`)53 } else {54 // unknown error55 pollResult.completed = true56 pollResult.succeeded = false57 pollResult.error =58 new Error(`${pollResponse.status}: ${pollResponse.data}`)59 }60 })61 .catch(err => {62 pollResult.completed = true63 pollResult.succeeded = false64 pollResult.error = err65 })66 }67 return pollResult68 })69 .takeWhile(pollResult => !(pollResult.completed))70 .takeLast(1)71 .map(pollResult => resolve({72 requestToken: pollResult.requestToken,73 succeeded: pollResult.succeeded,74 error: pollResult.error }))75 // unknown errors76 .catch(err => reject(err))77 // This can happen if maxPollTries are exhausted78 .finally(_ => reject('Failed to poll back response'))79 .subscribe()80 } else if (postResponse.status === 503) {81 // Request queue is overloaded82 reject(new Error('Request queue is overloaded'))83 } else {84 // Unknown error85 reject(new Error(postResponse))86 }87 })...
teacher.export.js
Source:teacher.export.js
1'use strict';2angular.module('hitsaOis').controller('TeacherExportController', ['$route', '$scope', 'message', 'QueryUtils',3 '$translate', 'busyHandler', 'dialogService', '$filter', 'PollingService', 'POLLING_STATUS',4 function ($route, $scope, message, QueryUtils, $translate, busyHandler, dialogService, $filter, PollingService, POLLING_STATUS) {5 $scope.auth = $route.current.locals.auth;6 $scope.higher = $route.current.locals.higher;7 var exportUrl = $scope.higher ? '/teachers/exportToEhis/higher' : '/teachers/exportToEhis/vocational';8 $scope.teacher = {};9 $scope.teacher.allDates = false;10 function send() {11 if ($scope.cancelledBy) {12 $scope.cancelledBy = null;13 }14 QueryUtils.loadingWheel($scope, true, false, $translate.instant('ehis.messages.requestInProgress'), true);15 PollingService.sendRequest({16 url: exportUrl,17 data: $scope.teacher,18 pollUrl: '/teachers/ehisTeacherExportStatus',19 successCallback: function (pollResult) {20 message.info(pollResult && pollResult.result.length > 0 ? 'ehis.messages.exportFinished' : 21 ($scope.auth.higher ? 'ehis.messages.noTeachersFoundHigher' : 'ehis.messages.noTeachersFoundVocational'));22 $scope.result = pollResult.result;23 busyHandler.setProgress(100);24 QueryUtils.loadingWheel($scope, false);25 },26 failCallback: function (pollResult) {27 if (pollResult) {28 message.error('ehis.messages.taskStatus.' + pollResult.status, {error: pollResult.error});29 if ((pollResult.status === POLLING_STATUS.CANCELLED || pollResult.status === POLLING_STATUS.INTERRUPTED) && pollResult.result) {30 $scope.cancelledBy = pollResult.cancelledBy;31 $scope.result = pollResult.result;32 }33 }34 QueryUtils.loadingWheel($scope, false);35 },36 updateProgress: function (pollResult) {37 if (pollResult) {38 busyHandler.setProgress(Math.round(pollResult.progress * 100));39 if (pollResult.message) {40 busyHandler.setText($translate.instant(pollResult.message));41 }42 }43 }44 });45 }46 47 $scope.exportTeachers = function() {48 if($scope.teacherExportForm.$valid) {49 QueryUtils.endpoint('/teachers/ehisTeacherExportCheck').get($scope.criteria).$promise.then(function(checkResult) {50 if (checkResult && checkResult.user) {51 dialogService.confirmDialog({52 prompt: checkResult.from ? 'ehis.messages.overlappedRequestDateRangeTeacher' : 'ehis.messages.overlappedRequestTeacher',53 user: checkResult.user,54 from: $filter('hoisDate')(checkResult.from),55 thru: $filter('hoisDate')(checkResult.thru)56 }, function() {57 send();58 });59 } else {60 send();61 }62 }).catch(angular.noop);63 } else {64 message.error('main.messages.form-has-errors');65 }66 };67 }...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3test.pollResult('TEST_ID', function(err, data) {4 if(err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var test = new wpt('API_KEY');12test.getLocations(function(err, data) {13 if(err) {14 console.log('Error: ' + err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var test = new wpt('API_KEY');21test.getLocations(function(err, data) {22 if(err) {23 console.log('Error: ' + err);24 } else {25 console.log(data);26 }27});28var wpt = require('webpagetest');29var test = new wpt('API_KEY');30test.getTesters(function(err, data) {31 if(err) {32 console.log('Error: ' + err);33 } else {34 console.log(data);35 }36});37var wpt = require('webpagetest');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');3wpt.pollResult('150610_8P_5f5a0c1b5a2b9c5b5e1c5f5e5f5a5e5d', 0, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10### WebPageTest(options)11### .runTest(url, options, callback)
Using AI Code Generation
1var wpt = require('wpt-api');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) {6 console.log('Error: ' + err);7 return;8 }9 console.log('Test Started');10 console.log('Test ID: ' + data.data.testId);11 console.log('Poll Results: ' + data.data.pollResults);12 console.log('Test Status: ' + data.data.statusText);13 console.log('Test URL: ' + data.data.summary);14 console.log('Test Runs: ' + data.data.average.firstView.runs);15 console.log('Test Load Time: ' + data.data.average.firstView.loadTime);16 console.log('Test TTFB: ' + data.data.average.firstView.TTFB);17 console.log('Test Speed Index: ' + data.data.average.firstView.SpeedIndex);18 console.log('Test Visual Complete: ' + data.data.average.firstView.visualComplete);19});20var wpt = require('wpt-api');21var options = {22};23wpt.runTest(options, function(err, data) {24 if (err) {25 console.log('Error: ' + err);26 return;27 }28 console.log('Test Started');29 console.log('Test ID: ' + data.data.testId);30 console.log('Poll Results: ' + data.data.pollResults);31 console.log('Test Status: ' + data.data.statusText);32 console.log('Test URL: ' + data.data.summary);33 console.log('Test Runs: ' + data.data.average.firstView.runs);34 console.log('Test Load Time: ' + data.data.average.firstView.loadTime);35 console.log('Test TTFB: ' + data.data.average.firstView.TTFB);36 console.log('Test Speed Index: ' + data.data.average.firstView.SpeedIndex);37 console.log('Test Visual Complete: ' + data.data.average.firstView.visualComplete);38});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('140917_1Y_1', function(err, data) {4});5var wpt = require('wpt');6var wpt = new WebPageTest('www.webpagetest.org');7});8var wpt = require('wpt');9var wpt = new WebPageTest('www.webpagetest.org');10wpt.getLocations(function(err, data) {11});12var wpt = require('wpt');13var wpt = new WebPageTest('www.webpagetest.org');14wpt.getLocations(function(err, data) {15});16var wpt = require('wpt');17var wpt = new WebPageTest('www.webpagetest.org');18wpt.getTesters(function(err, data) {19});20var wpt = require('wpt');21var wpt = new WebPageTest('www.webpagetest.org');22wpt.getTesters(function(err, data) {23});24var wpt = require('wpt');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.getTesters(function(err, data) {27});28var wpt = require('wpt');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getTesters(function(err, data) {31});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = require('wpt');3wpt.getLocations();4var wpt = require('wpt');5wpt.getTesters();6var wpt = require('wpt');7wpt.getTesters('ec2-us-west-1');8var wpt = require('wpt');9wpt.getTesters('ec2-us-west-1', 'Chrome');10var wpt = require('wpt');11wpt.getTesters('ec2-us-west-1', 'Chrome', 'Dulles_IE8');12var wpt = require('wpt');13wpt.getTesters('ec2-us-west-1', 'Chrome', 'Dulles_IE8', '3G');14var wpt = require('wpt');15wpt.getTesters('ec2-us-west-1', 'Chrome', 'Dulles_IE8', '3G', '10');16var wpt = require('wpt');17wpt.getTesters('ec2-us-west-1', 'Chrome', 'Dulles_IE8', '3G', '10', '1');18var wpt = require('wpt');19wpt.getTesters('ec2-us-west-1', 'Chrome', 'Dulles_IE8', '3G', '10', '1', '1');
Using AI Code Generation
1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.pollResult(160311_4D_1C4, 30000, function(data) {4 console.log(data);5});6var wpt = new WebPageTest('www.webpagetest.org');7wpt.pollResult(160311_4D_1C4, 30000, function(data) {8 console.log(data);9});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!