Best JavaScript code snippet using wpt
adminApp.js
Source:adminApp.js
1const admin = require("../logic/adminHandling");2const election = require("../logic/electionHandling");3const validate = require("../helpers/validate");4const errorHandler = require("../helpers/errors");5const successHandler = require("../helpers/create-success");6const electionHandler = require("../helpers/electionHas");7const getToken = require("../helpers/getToken");8const jwt = require("jsonwebtoken");9const config = require("../../config/env");10const bcrypt = require("bcrypt");11// Small helper12function success(token) {13 return {14 success: true,15 message: "Successful login.",16 token: `JWT ${token}`,17 };18}19/**20 * Function to allow admin to login to admin portal to access admin functionality21 * @function22 * @async23 * @name loginAdmin24 * @param {*} req25 * @param {*} res26 * @returns {Promise}27 */28module.exports.loginAdmin = async function (req, res) {29 const { email, password } = req.body;30 if (!(email && password)) {31 res.status(503).json(errorHandler.emptyParam);32 return;33 }34 const vEmail = validate.valEmail(email);35 const vPassword = validate.valPassword(password);36 if (vPassword && vEmail) {37 try {38 const adminn = await admin.findAdmin(email);39 if (!adminn) {40 res.status(401).json(errorHandler.noAdmins);41 } else if (adminn) {42 if (bcrypt.compareSync(password, adminn.password)) {43 const token = jwt.sign(44 {45 id: adminn.aid,46 email: adminn.email,47 },48 config.jwt_key,49 {50 expiresIn: "1h",51 }52 );53 res.status(200).json(success(token));54 return;55 } else {56 res.status(401).json(errorHandler.noAdmins);57 }58 } else {59 res.status(500).json(errorHandler.serverError);60 return;61 }62 } catch (err) {63 res.status(500).json(errorHandler.jwtError);64 }65 } else if (vEmail !== true || vPassword !== true) {66 res.status(401).json(errorHandler.generalValidation);67 } else {68 res.status(500).json(errorHandler.serverError);69 }70};71/**72 * @function73 * @name registerVoter74 * @description Function to register a voter given that the given email is not currently registered75 * @param {*} req76 * @param {*} res77 * @return {Promise}78 * Need to add that email should not be in admin table79 */80module.exports.registerVoter = async function (req, res) {81 if (req.headers === null || req.headers === "") {82 res.status(401).json(errorHandler.cannotAccess);83 } else {84 try {85 const token = getToken(req.headers);86 const payload = await jwt.verify(token, config.jwt_key);87 const { email, hall, faculty, doesCommute, isPostGrad } = req.body;88 if (payload && payload.id) {89 const adminn = await admin.findAdminById(payload.id);90 if (!adminn) {91 res.status(401).json(errorHandler.noAdmins);92 } else if (adminn) {93 if (!(email && hall && faculty)) {94 res.status(400).json(errorHandler.emptyParam);95 } else {96 const vEmail = validate.valEmail(email);97 if (98 vEmail &&99 Number.isInteger(hall) &&100 Number.isInteger(faculty) &&101 (doesCommute === true || doesCommute === false) &&102 (isPostGrad === true || isPostGrad === false)103 ) {104 try {105 const addVoter = await admin.addVoter(106 email,107 hall,108 faculty,109 doesCommute,110 isPostGrad111 );112 if (addVoter === 0) {113 res114 .status(201)115 .json(successHandler(true, "Voter added successfully"));116 return;117 } else if (addVoter === 1) {118 res.status(422).json(errorHandler.causingDuplicate);119 return;120 } else if (addVoter === 2) {121 res.status(500).json(errorHandler.emptyParam);122 return;123 } else {124 res.status(500).json(errorHandler.serverError);125 return;126 }127 } catch (err) {128 res.status(400).json(errorHandler.noHallorFaculty);129 }130 } else if (131 vEmail != true ||132 !Number.isInteger(hall) ||133 !Number.isInteger(faculty) ||134 !(doesCommute === true || doesCommute === false) ||135 !(isPostGrad === true || isPostGrad === false)136 ) {137 res.status(400).json(errorHandler.generalValidation);138 } else {139 res.status(500).json(errorHandler.serverError);140 }141 }142 } else {143 res.status(500).json(errorHandler.serverError);144 }145 } else {146 res.status(500).json(errorHandler.jwtError);147 }148 } catch (err) {149 res.status(401).json(errorHandler.jwtTokenExpired);150 return;151 }152 }153};154/**155 * @function156 * @name getAllHalls157 * @description Function to return all halls in the UWI158 * @param {*} req159 * @param {*} res160 * @return {Promise}161 */162module.exports.getAllHalls = async function (req, res) {163 if (req.headers === null || req.headers === "") {164 res.status(401).json(errorHandler.cannotAccess);165 } else {166 try {167 const token = getToken(req.headers);168 const payload = await jwt.verify(token, config.jwt_key);169 170 if (payload && payload.id) {171 try {172 const adminn = await admin.findAdminById(payload.id);173 if (!adminn) {174 res.status(401).json(errorHandler.noAdmins);175 return;176 } else if (adminn) {177 const allHalls = await admin.getAllHalls();178 if (allHalls) {179 res.status(200).json(successHandler(true, allHalls));180 return;181 } else {182 res.status(500).json(errorHandler.serverError);183 return;184 }185 }186 } catch (err) {187 res.status(500).json(errorHandler.serverError);188 }189 } else {190 res.status(500).json(errorHandler.jwtError);191 return;192 }193 } catch (err) {194 res.status(401).json(errorHandler.jwtTokenExpired);195 return;196 }197 }198};199/**200 * @function201 * @name getAllFaculties202 * @description Function to return all faculties in the UWI203 * @param {*} req204 * @param {*} res205 * @return {Promise}206 */207module.exports.getAllFaculties = async function (req, res) {208 if (req.headers === null || req.headers === "") {209 res.status(401).json(errorHandler.cannotAccess);210 } else {211 try {212 const token = getToken(req.headers);213 const payload = await jwt.verify(token, config.jwt_key);214 if (payload && payload.id) {215 try {216 const adminn = await admin.findAdminById(payload.id);217 if (!adminn) {218 res.status(401).json(errorHandler.noAdmins);219 return;220 } else if (adminn) {221 const allFaculties = await admin.getAllFaculties();222 if (allFaculties) {223 res.status(200).json(successHandler(true, allFaculties));224 return;225 } else {226 res.status(500).json(errorHandler.serverError);227 return;228 }229 }230 } catch (err) {231 res.status(500).json(errorHandler.serverError);232 }233 } else {234 res.status(500).json(errorHandler.jwtError);235 return;236 }237 } catch (err) {238 res.status(401).json(errorHandler.jwtTokenExpired);239 return;240 }241 }242};243/**244 * @function245 * @name getAllPositions246 * @description gets all the positions for the uwi guild election247 * @param {*} req248 * @param {*} res249 * @return {Promise}250 */251module.exports.getAllPositions = async function (req, res) {252 if (req.headers === null || req.headers === "") {253 res.status(401).json(errorHandler.cannotAccess);254 } else {255 try {256 const token = getToken(req.headers);257 const payload = await jwt.verify(token, config.jwt_key);258 if (payload && payload.id) {259 try {260 const adminn = await admin.findAdminById(payload.id);261 if (!adminn) {262 res.status(401).json(errorHandler.noAdmins);263 return;264 } else if (adminn) {265 const allPositions = await admin.getAllPositions();266 if (allPositions) {267 res.status(200).json(successHandler(true, allPositions));268 return;269 } else {270 res.status(500).json(errorHandler.serverError);271 return;272 }273 }274 } catch (err) {275 res.status(500).json(errorHandler.serverError);276 }277 } else {278 res.status(500).json(errorHandler.jwtError);279 return;280 }281 } catch (err) {282 res.status(401).json(errorHandler.jwtTokenExpired);283 return;284 }285 }286};287/**288 * @function289 * @name addCandidate290 * @description Function to add a people who are up for a position in the election - aka a candidates291 * @param {*} req292 * @param {*} res293 * @return {Promise}294 */295module.exports.addCandidate = async function (req, res) {296 if (req.headers === null || req.headers === "") {297 res.status(401).json(errorHandler.cannotAccess);298 return;299 } else {300 try {301 const token = getToken(req.headers);302 const payload = await jwt.verify(token, config.jwt_key);303 const { candidates } = req.body;304 if (payload && payload.id) {305 const adminn = await admin.findAdminById(payload.id);306 if (!adminn) {307 res.status(401).json(errorHandler.noAdmins);308 return;309 } else if (adminn) {310 try {311 for (let c = 0; c < candidates.length; c++) {312 if (313 !(314 candidates[c].firstName &&315 candidates[c].lastName &&316 candidates[c].email &&317 candidates[c].hall &&318 candidates[c].faculty &&319 candidates[c].position &&320 candidates[c].about321 )322 ) {323 res.status(400).json(errorHandler.missingField);324 return;325 } else {326 const vEmail = validate.valEmail(candidates[c].email);327 const vFname = validate.valName(candidates[c].firstName);328 const vLname = validate.valName(candidates[c].lastName);329 const vHall = Number.isInteger(candidates[c].hall);330 const vFaculty = Number.isInteger(candidates[c].faculty);331 const vPosition = Number.isInteger(candidates[c].position);332 var addCandidate;333 var addSum = 0;334 if (vEmail && vFname && vLname && vHall && vFaculty && vPosition) {335 try {336 addCandidate = await admin.addCandidate(337 candidates[c].firstName,338 candidates[c].lastName,339 candidates[c].email,340 candidates[c].hall,341 candidates[c].faculty,342 candidates[c].position,343 candidates[c].about344 );345 addSum = addSum + addCandidate;346 } catch (err) {347 res.status(400).json(errorHandler.queryError);348 return;349 }350 } else if (!vEmail || !vFname || !vLname || !vHall || !vFaculty || !vPosition) {351 res.status(400).json(errorHandler.generalValidation);352 return;353 } else {354 res.status(500).json(errorHandler.serverError);355 return;356 }357 }358 }359 if (addSum === 0) {360 res361 .status(201)362 .json(363 successHandler(true, "All candidates added successfully")364 );365 return;366 } else if (addSum < 0) {367 res.status(500).json(errorHandler.serverError);368 return;369 } else {370 res.status(422).json(errorHandler.cannotAddCandidate);371 return;372 }373 } catch (err) {374 res.status(400).json(errorHandler.missingField);375 return;376 }377 }378 } else {379 res.status(401).json(errorHandler.jwtError);380 return;381 }382 } catch (err) {383 res.status(401).json(errorHandler.jwtTokenExpired);384 return;385 }386 }387};388/**389 * Makes the results of an election public390 * @function391 * @async392 * @name makeResultsPublic393 * @param {*} req394 * @param {*} res395 * @returns396 */397module.exports.makeResultsPublic = async function (req, res) {398 if (req.headers === null || req.headers === "") {399 res.status(401).json(errorHandler.cannotAccess);400 } else {401 try {402 const token = getToken(req.headers);403 const payload = await jwt.verify(token, config.jwt_key);404 if (payload && payload.id) {405 try {406 const adminn = await admin.findAdminById(payload.id);407 if (!adminn) {408 res.status(401).json(errorHandler.noAdmins);409 return;410 } else if (adminn) {411 const electionDetails = await election.selectElection();412 if (electionDetails.length === 0) {413 res.status(500).json(errorHandler.serverError);414 return;415 } else if (electionDetails.length === 1) {416 const hasEnded = electionHandler.hasElectionEnded(417 electionDetails[0].endDate418 );419 if (hasEnded === true) {420 const results = await election.updatePostResults(1, true);421 if (results === 0) {422 res423 .status(200)424 .json(425 successHandler(426 true,427 "Election results have now been posted"428 )429 );430 return;431 } else if (results === 1) {432 res.status(400).json(errorHandler.queryError);433 return;434 }435 } else if (hasEnded === false) {436 res.status(422).json(errorHandler.electionNotEnded);437 return;438 } else {439 res.status(400).json(errorHandler.generalValidation);440 return;441 }442 }443 } else {444 res.status(500).json(errorHandler.serverError);445 return;446 }447 } catch (err) {448 res.status(400).json(errorHandler.queryError);449 return;450 }451 } else {452 res.status(500).json(errorHandler.jwtError);453 return;454 }455 } catch (err) {456 res.status(401).json(errorHandler.jwtTokenExpired);457 return;458 }459 }460};461/**462 * Makes the resuts of an election private463 * @function464 * @async465 * @name makeResultsPrivate466 * @param {*} req467 * @param {*} res468 * @returns469 */470module.exports.makeResultsPrivate = async function (req, res) {471 if (req.headers === null || req.headers === "") {472 res.status(401).json(errorHandler.cannotAccess);473 } else {474 try {475 const token = getToken(req.headers);476 const payload = await jwt.verify(token, config.jwt_key);477 if (payload && payload.id) {478 try {479 const adminn = await admin.findAdminById(payload.id);480 if (!adminn) {481 res.status(401).json(errorHandler.noAdmins);482 return;483 } else if (adminn) {484 const electionDetails = await election.selectElection();485 if (electionDetails.length === 0) {486 res.status(500).json(errorHandler.serverError);487 return;488 } else if (electionDetails.length === 1) {489 const hasEnded = electionHandler.hasElectionEnded(490 electionDetails[0].endDate491 );492 if (hasEnded === true) {493 const results = await election.updatePostResults(1, false);494 if (results === 0) {495 res496 .status(200)497 .json(498 successHandler(499 true,500 "Election results have now been made private"501 )502 );503 } else if (results === 1) {504 res.status(400).json(errorHandler.queryError);505 return;506 }507 } else if (hasEnded === false) {508 res.status(400).json(errorHandler.electionNotEnded);509 return;510 } else {511 res.status(400).json(errorHandler.generalValidation);512 return;513 }514 }515 } else {516 res.status(500).json(errorHandler.serverError);517 return;518 }519 } catch (err) {520 res.status(400).json(errorHandler.queryError);521 return;522 }523 } else {524 res.status(500).json(errorHandler.jwtError);525 return;526 }527 } catch (err) {528 res.status(401).json(errorHandler.jwtTokenExpired);529 return;530 }531 }...
tests.js
Source:tests.js
1exports.defineAutoTests = function() {2 var ss, handlers;3 var SERVICE = 'testing';4 describe('cordova-plugin-secure-storage', function () {5 beforeEach(function () {6 handlers = {7 successHandler: function () {},8 errorHandler: function () {}9 };10 });11 it('should be defined', function() {12 expect(cordova.plugins.SecureStorage).toBeDefined();13 });14 it('should be able to initialize', function (done) {15 spyOn(handlers, 'successHandler').and.callFake(function () {16 expect(ss.service).toEqual(SERVICE);17 expect(handlers.errorHandler).not.toHaveBeenCalled();18 done();19 });20 spyOn(handlers, 'errorHandler');21 ss = new cordova.plugins.SecureStorage(handlers.successHandler, handlers.errorHandler, SERVICE);22 });23 it('should be able to set a key/value', function (done) {24 spyOn(handlers, 'successHandler').and.callFake(function (res) {25 expect(res).toEqual('foo');26 expect(handlers.errorHandler).not.toHaveBeenCalled();27 done();28 });29 spyOn(handlers, 'errorHandler');30 ss = new cordova.plugins.SecureStorage(function () {31 ss.set(handlers.successHandler, handlers.errorHandler, 'foo', 'bar');32 }, handlers.errorHandler, SERVICE);33 });34 it('should be able to get a key/value', function (done) {35 spyOn(handlers, 'successHandler').and.callFake(function (res) {36 expect(res).toEqual('bar');37 expect(handlers.errorHandler).not.toHaveBeenCalled();38 done();39 });40 spyOn(handlers, 'errorHandler');41 ss = new cordova.plugins.SecureStorage(function () {42 ss.set(function () {43 ss.get(handlers.successHandler, handlers.errorHandler, 'foo');44 }, handlers.errorHandler, 'foo', 'bar');45 }, handlers.errorHandler, SERVICE);46 });47 it('should be able to get a key/value that was set before', function (done) {48 spyOn(handlers, 'successHandler').and.callFake(function (res) {49 expect(res).toEqual('bar');50 expect(handlers.errorHandler).not.toHaveBeenCalled();51 done();52 });53 spyOn(handlers, 'errorHandler');54 ss = new cordova.plugins.SecureStorage(function () {55 ss.get(handlers.successHandler, handlers.errorHandler, 'foo');56 }, handlers.errorHandler, SERVICE);57 });58 it('should call the error handler when getting a key that does not exist', function (done) {59 spyOn(handlers, 'errorHandler').and.callFake(function () {60 expect(handlers.successHandler).not.toHaveBeenCalled();61 done();62 });63 spyOn(handlers, 'successHandler');64 ss = new cordova.plugins.SecureStorage(function () {65 ss.get(handlers.successHandler, handlers.errorHandler, 'nofoo');66 }, handlers.errorHandler, SERVICE);67 });68 it('should be able to remove a key/value', function (done) {69 spyOn(handlers, 'successHandler').and.callFake(function (res) {70 expect(res).toEqual('foo');71 expect(handlers.errorHandler).not.toHaveBeenCalled();72 done();73 });74 spyOn(handlers, 'errorHandler');75 ss = new cordova.plugins.SecureStorage(function () {76 ss.remove(handlers.successHandler, handlers.errorHandler, 'foo');77 }, handlers.errorHandler, SERVICE);78 });79 it('should be able to set and retrieve multiple values in sequence', function (done) {80 var results = [];81 spyOn(handlers, 'successHandler').and.callFake(function (res) {82 results.push(res);83 expect(res === 'foo' || res === 'bar').toBe(true);84 if (results.indexOf('foo') !== -1 && results.indexOf('bar') !== -1) {85 done();86 }87 });88 ss = new cordova.plugins.SecureStorage(function () {89 ss.set(function () {90 ss.set(function () {91 ss.get(handlers.successHandler, handlers.errorHandler, 'foo');92 ss.get(handlers.successHandler, handlers.errorHandler, 'bar');93 }, function () {}, 'bar', 'bar');94 }, function () {}, 'foo', 'foo');95 }, handlers.errorHandler, 'testing');96 });97 });98 if (cordova.platformId === 'android') {99 describe('cordova-plugin-secure-storage-android', function () {100 beforeEach(function () {101 handlers = {102 successHandler: function () {},103 errorHandler: function () {}104 };105 });106 it('should be able to set a key/value with sjcl', function (done) {107 localStorage.clear();108 spyOn(handlers, 'successHandler').and.callFake(function (res) {109 expect(res).toEqual('foo');110 expect(handlers.errorHandler).not.toHaveBeenCalled();111 done();112 });113 spyOn(handlers, 'errorHandler');114 ss = new cordova.plugins.SecureStorage(function () {115 ss.set(handlers.successHandler, handlers.errorHandler, 'foo', 'bar');116 },117 handlers.errorHandler,118 SERVICE,119 {native: false}120 );121 });122 it('should be able to get a key/value that was set before with sjcl', function (done) {123 spyOn(handlers, 'successHandler').and.callFake(function (res) {124 expect(res).toEqual('bar');125 expect(handlers.errorHandler).not.toHaveBeenCalled();126 done();127 });128 spyOn(handlers, 'errorHandler');129 ss = new cordova.plugins.SecureStorage(function () {130 ss.get(handlers.successHandler, handlers.errorHandler, 'foo');131 }, handlers.errorHandler, SERVICE);132 });133 });134 }...
errorhandler.js
Source:errorhandler.js
1/*TRANSPILED*//*2 Copyright The Closure Library Authors.3 SPDX-License-Identifier: Apache-2.04*/5'use strict';6goog.provide("goog.debug.ErrorHandler");7goog.provide("goog.debug.ErrorHandler.ProtectedFunctionError");8goog.require("goog.Disposable");9goog.require("goog.asserts");10goog.require("goog.debug.EntryPointMonitor");11goog.require("goog.debug.Error");12goog.debug.ErrorHandler = function(handler) {13 goog.debug.ErrorHandler.base(this, "constructor");14 this.errorHandlerFn_ = handler;15 this.wrapErrors_ = true;16 this.prefixErrorMessages_ = false;17};18goog.inherits(goog.debug.ErrorHandler, goog.Disposable);19goog.debug.ErrorHandler.prototype.wrap = function(fn) {20 return this.protectEntryPoint(goog.asserts.assertFunction(fn));21};22goog.debug.ErrorHandler.prototype.unwrap = function(fn) {23 goog.asserts.assertFunction(fn);24 return fn[this.getFunctionIndex_(false)] || fn;25};26goog.debug.ErrorHandler.prototype.getFunctionIndex_ = function(wrapper) {27 return (wrapper ? "__wrapper_" : "__protected_") + goog.getUid(this) + "__";28};29goog.debug.ErrorHandler.prototype.protectEntryPoint = function(fn) {30 var protectedFnName = this.getFunctionIndex_(true);31 if (!fn[protectedFnName]) {32 var wrapper = fn[protectedFnName] = this.getProtectedFunction(fn);33 wrapper[this.getFunctionIndex_(false)] = fn;34 }35 return fn[protectedFnName];36};37goog.debug.ErrorHandler.prototype.getProtectedFunction = function(fn) {38 var that = this;39 var googDebugErrorHandlerProtectedFunction = function() {40 var self = this;41 if (that.isDisposed()) {42 return fn.apply(self, arguments);43 }44 try {45 return fn.apply(self, arguments);46 } catch (e) {47 that.handleError_(e);48 }49 };50 googDebugErrorHandlerProtectedFunction[this.getFunctionIndex_(false)] = fn;51 return googDebugErrorHandlerProtectedFunction;52};53goog.debug.ErrorHandler.prototype.handleError_ = function(e) {54 var MESSAGE_PREFIX = goog.debug.ErrorHandler.ProtectedFunctionError.MESSAGE_PREFIX;55 if (e && typeof e === "object" && typeof e.message === "string" && e.message.indexOf(MESSAGE_PREFIX) == 0 || typeof e === "string" && e.indexOf(MESSAGE_PREFIX) == 0) {56 return;57 }58 this.errorHandlerFn_(e);59 if (!this.wrapErrors_) {60 if (this.prefixErrorMessages_) {61 if (typeof e === "object" && e && typeof e.message === "string") {62 e.message = MESSAGE_PREFIX + e.message;63 } else {64 e = MESSAGE_PREFIX + e;65 }66 }67 if (goog.DEBUG) {68 if (e && typeof e.stack === "string" && Error.captureStackTrace && goog.global["console"]) {69 goog.global["console"]["error"](e.message, e.stack);70 }71 }72 throw e;73 }74 throw new goog.debug.ErrorHandler.ProtectedFunctionError(e);75};76goog.debug.ErrorHandler.prototype.protectWindowSetTimeout = function() {77 this.protectWindowFunctionsHelper_("setTimeout");78};79goog.debug.ErrorHandler.prototype.protectWindowSetInterval = function() {80 this.protectWindowFunctionsHelper_("setInterval");81};82goog.debug.ErrorHandler.prototype.catchUnhandledRejections = function(win) {83 win = win || goog.global["window"];84 if ("onunhandledrejection" in win) {85 win.onunhandledrejection = event => {86 const e = event && event.reason ? event.reason : new Error("uncaught error");87 this.handleError_(e);88 };89 }90};91goog.debug.ErrorHandler.prototype.protectWindowRequestAnimationFrame = function() {92 var win = goog.global["window"];93 var fnNames = ["requestAnimationFrame", "mozRequestAnimationFrame", "webkitAnimationFrame", "msRequestAnimationFrame"];94 for (var i = 0; i < fnNames.length; i++) {95 var fnName = fnNames[i];96 if (fnNames[i] in win) {97 this.protectWindowFunctionsHelper_(fnName);98 }99 }100};101goog.debug.ErrorHandler.prototype.protectWindowFunctionsHelper_ = function(fnName) {102 var win = goog.global["window"];103 var originalFn = win[fnName];104 var that = this;105 win[fnName] = function(fn, time) {106 if (typeof fn === "string") {107 fn = goog.partial(goog.globalEval, fn);108 }109 arguments[0] = fn = that.protectEntryPoint(fn);110 if (originalFn.apply) {111 return originalFn.apply(this, arguments);112 } else {113 var callback = fn;114 if (arguments.length > 2) {115 var args = Array.prototype.slice.call(arguments, 2);116 callback = function() {117 fn.apply(this, args);118 };119 }120 return originalFn(callback, time);121 }122 };123 win[fnName][this.getFunctionIndex_(false)] = originalFn;124};125goog.debug.ErrorHandler.prototype.setWrapErrors = function(wrapErrors) {126 this.wrapErrors_ = wrapErrors;127};128goog.debug.ErrorHandler.prototype.setPrefixErrorMessages = function(prefixErrorMessages) {129 this.prefixErrorMessages_ = prefixErrorMessages;130};131goog.debug.ErrorHandler.prototype.disposeInternal = function() {132 var win = goog.global["window"];133 win.setTimeout = this.unwrap(win.setTimeout);134 win.setInterval = this.unwrap(win.setInterval);135 goog.debug.ErrorHandler.base(this, "disposeInternal");136};137goog.debug.ErrorHandler.ProtectedFunctionError = function(cause) {138 var message = goog.debug.ErrorHandler.ProtectedFunctionError.MESSAGE_PREFIX + (cause && cause.message ? String(cause.message) : String(cause));139 goog.debug.ErrorHandler.ProtectedFunctionError.base(this, "constructor", message, cause);140 var stack = cause && cause.stack;141 if (stack && typeof stack === "string") {142 this.stack = stack;143 }144};145goog.inherits(goog.debug.ErrorHandler.ProtectedFunctionError, goog.debug.Error);...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test Results: ' + data);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log('Test Results: ' + data);15 }16}, function(err) {17 console.log('Error: ' + err);18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21 if (err) {22 console.log('Error: ' + err);23 } else {24 console.log('Test Results: ' + data);25 }26}, function(err) {27 console.log('Error: ' + err);28});29var wpt = require('wpt');30var wpt = new WebPageTest('www.webpagetest.org');31 if (err) {32 console.log('Error: ' + err);33 } else {34 console.log('Test Results: ' + data);35 }36}, function(err) {37 console.log('Error: ' + err);38});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var test = wpt.runTest(url, {4}, function (err, data) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log('Test ID: ' + data.data.testId);9 wpt.getTestResults(data.data.testId, function (err, data) {10 if (err) {11 console.log('Error: ' + err);12 } else {13 console.log('Test Results: ' + JSON.stringify(data.data));14 }15 });16 }17});
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var _ = require('underscore');5var request = require('request');6var async = require('async');7var cheerio = require('cheerio');8var csv = require('csvtojson');9var json2csv = require('json2csv');
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('en.wikipedia.org');3wp.get(function(err, data) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10});11{ error: 'No page found' }12var wptools = require('wptools');13var wp = new wptools('en.wikipedia.org');14wp.get(function(err, data) {15 if (err) {16 console.log(err);17 }18 else {19 console.log(data);20 }21});22{ error: 'No page found' }23var wptools = require('wptools');24var wp = new wptools('en.wikipedia.org');25wp.get(function(err, data) {26 if (err) {27 console.log(err);28 }29 else {30 console.log(data);31 }32});
Using AI Code Generation
1var wpt = require('./wpt');2var wptObj = new wpt();3wptObj.errorHandler('test error');4wptObj.errorHandler('test error', 'test error');5wptObj.errorHandler('test error', 'test error', 'test error');6Your name to display (optional):7Your name to display (optional):
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org', 'A.3c3b8f4b4d4c1d4f4c4e4c4c4e4c4f4');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test ID: ' + data.data.testId);7 console.log('Test URL: ' + data.data.summary);8 }9});10var wpt = require('webpagetest');11var client = wpt('www.webpagetest.org', 'A.3c3b8f4b4d4c1d4f4c4e4c4c4e4c4f4');12 if (err) {13 console.log('Error: ' + err);14 } else {15 console.log('Test ID: ' + data.data.testId);16 console.log('Test URL: ' + data.data.summary);17 }18});
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!!