Best JavaScript code snippet using wpt
request-disturbed.any.js
Source:request-disturbed.any.js
1// META: global=window,worker2// META: title=Request disturbed3// META: script=../resources/utils.js4var initValuesDict = {"method" : "POST",5 "body" : "Request's body"6};7var noBodyConsumed = new Request("");8var bodyConsumed = new Request("", initValuesDict);9test(() => {10 assert_equals(noBodyConsumed.body, null, "body's default value is null");11 assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");12 assert_not_equals(bodyConsumed.body, null, "non-null body");13 assert_true(bodyConsumed.body instanceof ReadableStream, "non-null body type");14 assert_false(noBodyConsumed.bodyUsed, "bodyUsed is false when request is not disturbed");15}, "Request's body: initial state");16noBodyConsumed.blob();17bodyConsumed.blob();18test(function() {19 assert_false(noBodyConsumed.bodyUsed , "bodyUsed is false when request is not disturbed");20 try {21 noBodyConsumed.clone();22 } catch (e) {23 assert_unreached("Can use request not disturbed for creating or cloning request");24 }25}, "Request without body cannot be disturbed");26test(function() {27 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");28 assert_throws_js(TypeError, function() { bodyConsumed.clone(); });29}, "Check cloning a disturbed request");30test(function() {31 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");32 assert_throws_js(TypeError, function() { new Request(bodyConsumed); });33}, "Check creating a new request from a disturbed request");34promise_test(function() {35 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");36 const originalBody = bodyConsumed.body;37 const bodyReplaced = new Request(bodyConsumed, { body: "Replaced body" });38 assert_not_equals(bodyReplaced.body, originalBody, "new request's body is new");39 assert_false(bodyReplaced.bodyUsed, "bodyUsed is false when request is not disturbed");40 return bodyReplaced.text().then(text => {41 assert_equals(text, "Replaced body");42 });43}, "Check creating a new request with a new body from a disturbed request");44promise_test(function() {45 var bodyRequest = new Request("", initValuesDict);46 const originalBody = bodyRequest.body;47 assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");48 var requestFromRequest = new Request(bodyRequest);49 assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");50 assert_equals(bodyRequest.body, originalBody, "body should not change");51 assert_not_equals(originalBody, undefined, "body should not be undefined");52 assert_not_equals(originalBody, null, "body should not be null");53 assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");54 return requestFromRequest.text().then(text => {55 assert_equals(text, "Request's body");56 });57}, "Input request used for creating new request became disturbed");58promise_test(() => {59 const bodyRequest = new Request("", initValuesDict);60 const originalBody = bodyRequest.body;61 assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");62 const requestFromRequest = new Request(bodyRequest, { body : "init body" });63 assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");64 assert_equals(bodyRequest.body, originalBody, "body should not change");65 assert_not_equals(originalBody, undefined, "body should not be undefined");66 assert_not_equals(originalBody, null, "body should not be null");67 assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");68 return requestFromRequest.text().then(text => {69 assert_equals(text, "init body");70 });71}, "Input request used for creating new request became disturbed even if body is not used");72promise_test(function(test) {73 assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");74 return promise_rejects_js(test, TypeError, bodyConsumed.blob());75}, "Check consuming a disturbed request");76test(function() {77 var req = new Request(URL, {method: 'POST', body: 'hello'});78 assert_false(req.bodyUsed,79 'Request should not be flagged as used if it has not been ' +80 'consumed.');81 assert_throws_js(TypeError,82 function() { new Request(req, {method: 'GET'}); },83 'A get request may not have body.');84 assert_false(req.bodyUsed, 'After the GET case');85 assert_throws_js(TypeError,86 function() { new Request(req, {method: 'CONNECT'}); },87 'Request() with a forbidden method must throw.');88 assert_false(req.bodyUsed, 'After the forbidden method case');89 var req2 = new Request(req);90 assert_true(req.bodyUsed,91 'Request should be flagged as used if it has been consumed.');...
controller.js
Source:controller.js
1(function() {2 'use strict';3 ObjectControllerFunction.$inject = ["$scope", "$state", "$stateParams", "$timeout", "apiServices", "generalServices", "uiServices"];4 function ObjectControllerFunction($scope, $state, $stateParams, $timeout, apiServices, generalServices, uiServices) {5 var vm = this;6 vm.getProjectLicense = getProjectLicense;7 vm.getChevron = getChevron;8 vm.getNpmPackages = getNpmPackages;9 vm.rollOverCredits = rollOverCredits;10 initializeUIValues();11 getOpenParamTab();12 // ==========================================================13 function getOpenParamTab() {14 var tab = $stateParams.tab;15 if (tab) {16 vm[(tab + "Open")] = true;17 $timeout(function() { $("html, body").animate({ scrollTop: ($("#" + tab).offset().top - 150) }, "slow"); }, 500);18 }19 }20 function rollOverCredits() {21 if (!vm.ui.creditsStarted) {22 vm.ui.creditsStarted = true;23 vm.ui.currentScroll = 0;24 $("#mouse-warning").fadeIn();25 initializeCreditsUIValues();26 mouseOverCreditsHandler();27 $timeout(function() { scrollCredits(); }, 500);28 }29 }30 function scrollCreditsHandler() {31 if ($state.current.name !== "app.public.about") return false;32 var tgtCtn = "about-container";33 return uiServices.bindScrollToElement(tgtCtn, tgtCtn, function(tgt, ypos) {34 if (vm.ui.creditsStarted) vm.ui.currentScroll = (ypos * -1) + 250;35 });36 }37 function mouseOverCreditsHandler() { vm.ui.mainContainer.on("mousemove", handleScroll); }38 function handleScroll(e) {39 var mX = e.clientX;40 vm.ui.stopScroll = ((mX >= vm.ui.cDom.eLeft) && (mX <= vm.ui.cDom.totalWidth));41 }42 function scrollCredits() {43 var cScroll = vm.ui.currentScroll,44 loweringSpeed = vm.ui.creditsSpeed,45 topScroll = (vm.ui.getScrollTop() + vm.ui.cDom.endHeightOffset),46 doneScrolling = (topScroll >= vm.ui.cDom.totalHeight);47 $timeout(function() {48 var cLowering = (vm.ui.stopScroll ? 0 : loweringSpeed);49 if (!doneScrolling) {50 if (!vm.ui.stopScroll) {51 $('html, body').animate({ scrollTop: (vm.ui.cDom.offsetTop - cScroll) }, (vm.ui.scrollDelay));52 vm.ui.currentScroll = (cScroll - cLowering);53 }54 scrollCredits(vm.ui.currentScroll);55 } else {56 $('html, body').animate({ scrollTop: ((vm.ui.cDom.offsetTop - cScroll) + vm.ui.cDom.finalScroll) }, 2000);57 vm.ui.creditsStarted = false;58 }59 }, vm.ui.scrollDelay);60 }61 function initializeUIValues() {62 vm.ui = {63 creditsStarted: false,64 stopScroll: false,65 body: document.body,66 docElem: document.documentElement,67 mainContainer: $("#about-container"),68 currentScroll: 150,69 scrollDelay: 2000,70 creditsSpeed: 150,71 EH: {72 scrollHandler: scrollCreditsHandler()73 }74 };75 vm.ui.getScrollTop = function() { return (window.pageYOffset || vm.ui.docElem.scrollTop || vm.ui.body.scrollTop); };76 }77 function initializeCreditsUIValues() {78 vm.ui.creditsDOM = $("#credits");79 vm.ui.cDom = {80 eWidth: vm.ui.creditsDOM.outerWidth(),81 eLeft: vm.ui.creditsDOM.position().left,82 eHeight: vm.ui.creditsDOM.outerHeight(),83 eTop: vm.ui.creditsDOM.position().top,84 offsetTop: vm.ui.creditsDOM.offset().top,85 endHeightOffset: 900,86 finalScroll: 5087 };88 vm.ui.cDom.totalWidth = (vm.ui.cDom.eLeft + vm.ui.cDom.eWidth);89 vm.ui.cDom.totalHeight = (vm.ui.cDom.eTop + vm.ui.cDom.eHeight);90 }91 function getNpmPackages() {92 generalServices.getNpmPackages().then(function(packages) { vm.npmPackages = packages; });93 }94 function getProjectLicense() {95 var repoURL = "https://api.github.com/repos/Neefay/Belligerence/license";96 apiServices.simpleGET(repoURL).then(function(data) {97 getProjectLicenseDetails(data.license.url);98 });99 }100 function getChevron(status) { return ('ion-chevron-' + (status ? 'down' : 'right')); }101 function getProjectLicenseDetails(url) {102 apiServices.simpleGET(url).then(function(data) {103 vm.licenseData = data;104 var bodyReplaced = vm.licenseData.body;105 bodyReplaced = _.replace(bodyReplaced, "[year]", new Date().getFullYear());106 bodyReplaced = _.replace(bodyReplaced, "[fullname]", "Ian Ribeiro");107 vm.licenseData.body = bodyReplaced;108 });109 }110 function destroyEHs() {111 vm.ui.mainContainer.off("mousemove", handleScroll);112 }113 $scope.$on("$destroy", destroyEHs);114 $scope.$on("$destroy", scrollCreditsHandler());115 }116 exports.function = ObjectControllerFunction;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log('Test submitted. Polling results...');10 wpt.bodyReplaced(data.data.testId, function(err, data) {11 if (err) {12 console.log(err);13 } else {
Using AI Code Generation
1var wpt = require('webpagetest');var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.ong', 'API_KEY');3 if (err) {4 console.log(err);5 } else {6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) {8 console.log(err);9 } else {10 console.log(data.data.median.firstView.bodyReplaced);11 }12 });13 }14});15var wpt = rew WebPageTest('www.webpagetest.org', 'API_KEY');16 if (err) {17 console.log(err);18 } else {19 getTestResults(data.data.testId, function(e r, data) {20 if (err) {21 console.log(err);22 } else {23 console.log(data.data.median.firstView.bodyReplaced);24 }25 });26 }27});28var wpt = require('webpagetest');29var wpt = ew WebPage consowww.webpagetest.org', 'API_KEY');30wpt.runTest('le.log(err);function(err, data) 31 if (err) {32 consoe.lg(err);33 } else {34 wpt.getTestResults(data.data.testId, funtion(err, da) {35 f (err) {36 console.log(err);37 } else {38 console.lg(data.data.media.firstView.bodyReplaced);39 }40 });41 }42});43var wpt = require('webpagetest');44var wpt = new WebPageTest('www.webpagetest.org','API_KEY');45 if (err) {46 console.log(err);47 } else {48 wpt.getTestResults(data.data.testId, function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data.data.median.firstView.bodyReplaced
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890123456789012345678901');5 }, function(err, data) {6 if (err) return console.error(err);7 console.log('Test Status:', data.statusText);8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log('First View:', data.data.runs[1].firstView);11 console.log('Repeat View:', data.data.runs[1].repeatView);12 });13 });
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 } else {4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data.data.median.firstView.bodyReplaced);9 }10 });11 }12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');15 if (err) {16 console.log(err);17 } else {18 wpt.getTestResults(data.data.testId, function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data.data.median.firstView.bodyReplaced);23 }24 });25 }26});27var wpt = require('webpagetest');28var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');29 if (err) {30 console.log(err);31 } else {32 wpt.getTestResults(data.data.testId, function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log(data.data.median.firstView.bodyReplaced);37 }38 });39 }40});41var wpt = require('webpagetest');42var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');43 if (err) {44 console.log(err);45 } else {46 wpt.getTestResults(data.data.testId, function(err, data) {47 if (err) {48 console.log(err);49 } else {50 console.log(data.data.median.firstView.bodyReplaced
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');5 }, function(err, data) {6 if (err) return console.error(err);7 console.log('Test Status:', data.statusText);8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log('First View:', data.data.runs[1].firstView);11 console.log('Repeat View:', data.data.runs[1].repeatView);12 });13 });
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 wpt.getTestResults(data.data.testId, function(err, data) {4 console.log(data.data.median.firstView.TTFB);5 console.log(data.data.median.firstView.render);6 });7});8 wpt.getTestResults(data.data.testId, function(err, data) {9 console.log(data.data.median.firstView.TTFB);10 console.log(data.data.median.firstView.render);11 });12});13 wpt.getTestResults(data.data.testId, function(err, data) {14 console.log(data.data.median.firstView.TTFB);15 console.log(data.data.median.firstView.render);16 });17});18 wpt.getTestResults(data.data.testId, function(err, data) {19 console.log(data.data.median.firstView.TTFB);20 console.log(data.data.median.firstView.render);21 });22});23 wpt.getTestResults(data.data.testId, function(err, data) {24 console.log(data.data.median.firstView.TTFB);25 console.log(data.data.median.firstView.render);26 });27});28 wpt.getTestResults(data.data.testId, function(err, data) {29 console.log(data.data.median.firstView.TTFB);30 console.log(data.data.median.firstView.render);31 });32});
Using AI Code Generation
1var wpt = require('webpagetest');2var webPageTest = new wpt('API KEY');3 videoParams: { fps: 30, screenShot: 1, screenShotFormat: 'jpg', screenShotQuality: 30 },4}, function (err, data) {5 if (err) {6 console.log(err);7 } else {8 webPageTest.on('testProgress', function (data) {9 console.log('Test Progress', data);10 });11 webPageTest.on('testFinished', function (data) {12 console.log('Test Finished', data);13 });14 webPageTest.on('bodyReplaced', function (data) {15 console.log('Body Replaced', data);16 });17 }18});19var wpt = require('webpagetest');20var webPageTest = new wpt('API KEY');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org','A.3b9c9b0e1e8d8d0e1b2c2b2f2b2d8d0f');3 if (err) return console.error(err);4 var testId = data.data.testId;5 wpt.getTestResults(testId, function(err, data) {6 if (err) return console.error(err);7 console.log('First View (load time): %d ms'i data.data.average.firstView.loadTime);ty: '3G',8 });9 if (err) return console.error(err);10 });11});12var wpt = require('webpageleyt');13var wpt = new WebPageTest('www.webpagetest.org','A.3b9c9b0e1e8d8d0e1b2c2b2f2b2d8d0f');14 if (err) return console.error(err);15 var testId = data.data.testId;16 wpt.getTestResults(testId, function(err, data) {17 if (err) return console.error(err);18 console.log('First View (load time): %d ms', data.data.average.firstView.loadTime);19 });20 if (err) return console.error(err);21 videoParams: { fps: 30, screenShot: 1, screenShotFormat: 'jpg', screenShotQuality: 30 },22}, function (err, data) {23 if (err) {24 console.log(err);25 } else {26 webPageTest.on('testProgress', function (data) {27 console.log('Test Progress', data);28 });29 webPageTest.on('testFinished', function (data) {30 console.log('Test Finished', data);31 });32 webPageTest.on('bodyReplaced', function (data) {33 console.log('Body Replaced', data);34 });35 }36});37var wpt = require('webpag
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3var options = {4 videoParams: {5 },6};7test.runTest(url, options, function(err, data) {8 if (err) return console.error(err);9 console.log('Test status: ' + data.statusText);10 test.getTestResults(data.data.testId, function(err, data) {11 if (err) return console.error(err);12 console.log('Test results: ' + data.data.summary);13 });14});15var wpt = require('webpagetest');16var test = wpt('www.webpagetest.org');17var options = {18 videoParams: {19 },20};21test.runTest(url, options, function(err, data) {22 if (err) return console.error(err);23 console.log('Test status: ' + data.statusText);24 test.getTestResults(data.data.testId, function(err, data) {25 if (err) return console.error(err);26 console.log('Test results: ' + data.data.summary);27 });28});29var wpt = require('webpagetest');30var test = wpt('www.webpagetest.org');31var options = {
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!!