Best JavaScript code snippet using wpt
event-timing-test-utils.js
Source:event-timing-test-utils.js
...168 'pointerover',169 'pointerup'170 ].includes(eventType);171}172function notCancelable(eventType) {173 return ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'].includes(eventType);174}175// Tests the given |eventType|'s performance.eventCounts value. Since this is populated only when176// the event is processed, we check every 10 ms until we've found the |expectedCount|.177function testCounts(t, resolve, looseCount, eventType, expectedCount) {178 const counts = performance.eventCounts.get(eventType);179 if (counts < expectedCount) {180 t.step_timeout(() => {181 testCounts(t, resolve, looseCount, eventType, expectedCount);182 }, 10);183 return;184 }185 if (looseCount) {186 assert_greater_than_equal(performance.eventCounts.get(eventType), expectedCount,187 `Should have at least ${expectedCount} ${eventType} events`)188 } else {189 assert_equals(performance.eventCounts.get(eventType), expectedCount,190 `Should have ${expectedCount} ${eventType} events`);191 }192 resolve();193}194// Tests the given |eventType| by creating events whose target are the element with id195// 'target'. The test assumes that such element already exists. |looseCount| is set for196// eventTypes for which events would occur for other interactions other than the ones being197// specified for the target, so the counts could be larger.198async function testEventType(t, eventType, looseCount=false) {199 assert_implements(window.EventCounts, "Event Counts isn't supported");200 const target = document.getElementById('target');201 if (requiresListener(eventType)) {202 target.addEventListener(eventType, () =>{});203 }204 const initialCount = performance.eventCounts.get(eventType);205 if (!looseCount) {206 assert_equals(initialCount, 0, 'No events yet.');207 }208 // Trigger two 'fast' events of the type.209 await applyAction(eventType, target);210 await applyAction(eventType, target);211 await new Promise(t.step_func(resolve => {212 testCounts(t, resolve, looseCount, eventType, initialCount + 2);213 }));214 // The durationThreshold used by the observer. A slow events needs to be slower than that.215 const durationThreshold = 16;216 // Now add an event handler to cause a slow event.217 target.addEventListener(eventType, () => {218 mainThreadBusy(durationThreshold + 4);219 });220 const observerPromise = new Promise(async resolve => {221 new PerformanceObserver(t.step_func(entryList => {222 let eventTypeEntries = entryList.getEntriesByName(eventType);223 if (eventTypeEntries.length === 0)224 return;225 let entry = null;226 if (!looseCount) {227 entry = eventTypeEntries[0];228 assert_equals(eventTypeEntries.length, 1);229 } else {230 // The other events could also be considered slow. Find the one with the correct231 // target.232 eventTypeEntries.forEach(e => {233 if (e.target === document.getElementById('target'))234 entry = e;235 });236 if (!entry)237 return;238 }239 verifyEvent(entry,240 eventType,241 'target',242 false /* isFirst */,243 durationThreshold,244 notCancelable(eventType));245 // Shouldn't need async testing here since we already got the observer entry, but might as246 // well reuse the method.247 testCounts(t, resolve, looseCount, eventType, initialCount + 3);248 })).observe({type: 'event', durationThreshold: durationThreshold});249 });250 // Cause a slow event.251 let actionPromise = applyAction(eventType, target);252 return Promise.all([actionPromise, observerPromise]);...
knime_service_lazy_loading_1_0_0.js
Source:knime_service_lazy_loading_1_0_0.js
1initLazyLoading = function() {2 3 var viewRequests = [], requestSequence = 0, responseBuffer = [], pushSupported;4 if (!knimeService) {5 throw new Error("KNIME service is not defined.");6 }7 8 function MonitorablePromise(executor, promise) {9 this.progressListeners = [];10 this.monitor = {};11 if (promise) {12 this.realPromise = promise;13 } else {14 this.realPromise = new Promise(executor);15 }16 }17 18 MonitorablePromise.prototype = {19 progress: function(onProgress) {20 this.progressListeners.push(onProgress);21 //immediately call progress listener if progress is already available22 if (this.monitor) {23 onProgress(this.monitor);24 }25 return this;26 },27 then: function(onResolve, onReject) {28 let newPromise = new MonitorablePromise(null, this.realPromise.then(onResolve, onReject));29 newPromise.progressListeners = this.progressListeners;30 newPromise.monitor = this.monitor;31 return newPromise;32 },33 catch: function(onReject) {34 let newPromise = new MonitorablePromise(null, this.realPromise.catch(onReject));35 newPromise.progressListeners = this.progressListeners;36 newPromise.monitor = this.monitor;37 return newPromise;38 },39 finally: function(onFinally) {40 let newPromise = new MonitorablePromise(null, this.realPromise.finally(onFinally));41 newPromise.progressListeners = this.progressListeners;42 newPromise.monitor = this.monitor;43 return newPromise;44 },45 updateProgress: function(mon) {46 this.monitor = mon;47 this.progressListeners.forEach(function(onProgress) {48 onProgress(mon);49 });50 },51 cancel: function(invokeCatch) {52 if (!this.monitor || !this.monitor.requestSequence) {53 return;54 }55 for (let i = 0; i < viewRequests.length; i++) {56 let request = viewRequests[i];57 if (request.sequence == this.monitor.requestSequence) {58 if (!request.notCancelable) {59 let id = request.sequence;60 if (request.monitor && request.monitor.id) {61 id = request.monitor.id;62 }63 id = '' + id;64 if (knimeService.isInteractivityAvailable()) {65 monitor = knimeService.getGlobalService().cancelViewRequest(window.frameElement.id, id, invokeCatch);66 } else {67 knimeCancelRequest(id);68 }69 if (!invokeCatch) {70 viewRequests.splice(i, 1);71 }72 }73 break;74 }75 }76 }77 }78 79 getNextRequestSequence = function(sequence) {80 let mod = (typeof Number.MAX_SAFE_INTEGER !== 'undefined') ? 81 Number.MAX_SAFE_INTEGER : Number.MAX_VALUE;82 return ++sequence % mod;83 }84 85 getPreviousRequestSequence = function(sequence) {86 let mod = (typeof Number.MAX_SAFE_INTEGER !== 'undefined') ? 87 Number.MAX_SAFE_INTEGER : Number.MAX_VALUE;88 return --sequence % mod;89 }90 91 getAndSetNextRequestSequence = function() {92 requestSequence = getNextRequestSequence(requestSequence);93 return requestSequence;94 }95 96 async function _requestViewUpdate(request, resolvable) {97 try {98 let monitor;99 if (knimeService.isInteractivityAvailable()) {100 monitor = knimeService.getGlobalService()101 .requestViewUpdate(window.frameElement.id, JSON.stringify(request), request.sequence);102 } else {103 monitor = knimeViewRequest(JSON.stringify(request));104 }105 if (!monitor) {106 monitor = {};107 }108 if (typeof monitor === 'string') {109 monitor = JSON.parse(monitor);110 }111 if (!monitor.requestSequence) {112 monitor.requestSequence = request.sequence;113 }114 resolvable.monitor = monitor;115 if (resolvable.promise) {116 resolvable.promise.updateProgress(monitor);117 }118 if (typeof pushSupported === 'undefined') {119 initPushSupported();120 }121 if (!pushSupported) {122 initUpdateMonitorPolling(resolvable);123 }124 } catch (exception) {125 for (let i = 0; i < viewRequests.length; i++) {126 if (viewRequests[i].requestSequence === request.sequence) {127 viewRequests.splice(i, 1);128 break;129 }130 }131 if (resolvable.reject) {132 resolvable.reject(exception);133 }134 }135 }136 137 initPushSupported = function() {138 if (knimeService.isInteractivityAvailable()) {139 pushSupported = knimeService.getGlobalService().isPushSupported();140 } else {141 pushSupported = knimePushSupported();142 }143 }144 145 knimeService.requestViewUpdate = function(request, preserveOrder, notCancelable) {146 let prevSequence = requestSequence;147 request.sequence = getAndSetNextRequestSequence();148 let resolvable = {149 'sequence': request.sequence,150 'monitor': {},151 'notCancelable': notCancelable,152 'preserveOrder': preserveOrder153 };154 let promise = new MonitorablePromise(function(res, rej) {155 resolvable.resolve = res;156 resolvable.reject = rej;157 });158 resolvable.promise = promise;159 viewRequests.push(resolvable);160 _requestViewUpdate(request, resolvable);161 return promise;162 }163 164 initUpdateMonitorPolling = function(resolvable) {165 //initialize first update poll with a default of 500ms166 setTimeout(pollMonitorUpdate, 500, resolvable, 500);167 }168 169 pollMonitorUpdate = function(resolvable, time) {170 let updatedMonitor, id = resolvable.monitor.id;171 if (knimeService.isInteractivityAvailable()) {172 updatedMonitor = knimeService.getGlobalService().updateRequestStatus(window.frameElement.id, id);173 } else {174 updatedMonitor = knimeUpdateRequestStatus(id);175 }176 if (typeof updatedMonitor === 'string') {177 updatedMonitor = JSON.parse(updatedMonitor);178 }179 if (!compareResponseMonitor(resolvable.monitor, updatedMonitor)) {180 knimeService.updateResponseMonitor(updatedMonitor);181 }182 183 if (!((updatedMonitor.executionFinished && updatedMonitor.responseAvailable) 184 || updatedMonitor.executionFailed || updatedMonitor.cancelled)) {185 //slightly increase timeout every time up to a maximum of 5s, long running requests will186 //have fewer update calls187 let newTime = Math.min(5000, 1.05 * time);188 setTimeout(pollMonitorUpdate, newTime, resolvable, newTime);189 }190 }191 192 compareResponseMonitor = function(mon, otherMon) {193 //naive string comparison for performance reasons 194 return JSON.stringify(mon) === JSON.stringify(otherMon);195 }196 197 knimeService.updateResponseMonitor = function(updatedMonitor) {198 let sequence = updatedMonitor.requestSequence;199 if (typeof sequence === 'undefined') {200 return;201 }202 if (updatedMonitor.executionFinished && updatedMonitor.responseAvailable) {203 knimeService.respondToViewRequest(updatedMonitor.response);204 }205 for (let i = 0; i < viewRequests.length; i++) {206 let resolvable = viewRequests[i];207 if (resolvable.sequence === sequence) {208 if (updatedMonitor.executionFailed || updatedMonitor.cancelled) {209 resolvable.reject(updatedMonitor.errorMessage);210 viewRequests.splice(i, 1);211 } else {212 resolvable.monitor = updatedMonitor;213 if (resolvable.promise) {214 resolvable.promise.updateProgress(updatedMonitor);215 }216 }217 break;218 }219 }220 }221 222 knimeService.respondToViewRequest = function(response) {223 let sequence = response.sequence;224 if (typeof sequence === 'undefined') {225 return;226 }227 for (var i = 0; i < viewRequests.length; i++) {228 let request = viewRequests[i];229 if (request.sequence === sequence) {230 if (request.preserveOrder) {231 request.response = response;232 for (let j = 0; j < viewRequests.length; j++) {233 if (typeof viewRequests[j].response !== 'undefined') {234 resolveResponse(j, viewRequests[j].response);235 j--;236 } else {237 break;238 }239 }240 } else {241 resolveResponse(i, response);242 }243 break;244 }245 }246 }247 248 resolveResponse = function(index, response) {249 let resolvable = viewRequests[index];250 if (resolvable.sequence !== response.sequence) {251 return;252 }253 viewRequests.splice(index, 1);254 try {255 resolvable.resolve(response);256 } catch (exception) {257 resolvable.reject(exception);258 }259 } 260 261};262if (typeof KnimeInteractivity === 'undefined') {263 KnimeInteractivity = {264 respondToViewRequest: function(response) {265 return knimeService.respondToViewRequest(response);266 },267 updateResponseMonitor: function(monitor) {268 return knimeService.updateResponseMonitor(monitor);269 }270 }...
memento.js
Source:memento.js
1/**2 * Created by HDA3014 on 06/08/2016.3 */4exports.Memento = {5 enabled : true,6 previous : [],7 next : [],8 current : null,9 MAX_DO : 100,10 clear() {11 if (this.enabled) {12 this.previous = [];13 this.next = [];14 this.current = new Map();15 }16 },17 enable() {18 console.log("Memento enable");19 this.enabled = true;20 },21 disable() {22 console.log("Memento disable");23 this.enabled = false;24 },25 begin() {26 if (this.enabled) {27 while (this.previous.length>this.MAX_DO) {28 this.previous.shift();29 }30 if (this.current && this.current.size) {31 console.log("begin");32 this.previous.push(this.current);33 }34 this.current = new Map();35 }36 },37 register(registrable) {38 if (this.enabled && this.current) {39 this.next.length = 0;40 let memento = this.current.get(registrable);41 if (!memento) {42 memento = registrable.memorize();43 this.current.set(registrable, memento);44 }45 }46 },47 registerArray(source) {48 return source.duplicate();49 },50 revertArray(memento, target) {51 target.length = 0;52 target.push.apply(target, memento);53 },54 registerArrayOfArrays(source) {55 let memento = [];56 for (let c = 0; c<source.length; c++) {57 memento.push(this.registerArray(source[c]));58 }59 return memento;60 },61 revertArrayOfArrays(memento, target) {62 target.length = 0;63 for (let c = 0; c<memento.length; c++) {64 target.push(this.registerArray(memento[c]));65 }66 },67 registerObject(source) {68 if (!source) {69 console.log("! source ?");70 }71 return source.duplicate();72 },73 revertObject(memento, target) {74 for (let field in target) {75 delete target[field];76 }77 for (let field in memento) {78 target[field] = memento[field];79 }80 },81 registerSVHHandler(source) {82 let memento = {};83 memento.children = this.registerArray(source.children);84 memento._active = source._active;85 return memento;86 },87 revertSVGHandler(memento, target) {88 target.clear();89 for (let i=0; i<memento.children.length; i++) {90 target.add(memento.children[i]);91 }92 target._active = memento._active;93 },94 registerSVGTranslation(source) {95 let memento = this.registerSVHHandler(source);96 memento.x = source.x;97 memento.y = source.y;98 return memento;99 },100 revertSVGTranslation(memento, target) {101 this.revertSVGHandler(memento, target);102 target.move(memento.x, memento.y);103 },104 registerSVGRotation(source) {105 let memento = this.registerSVHHandler(source);106 memento.angle = source.angle;107 return memento;108 },109 revertSVGRotation(memento, target) {110 this.revertSVGHandler(memento, target);111 target.rotate(memento.angle);112 },113 registerSVGScale(source) {114 let memento = this.registerSVHHandler(source);115 memento.factor = source.factor;116 return memento;117 },118 revertSVGScale(memento, target) {119 this.revertSVGHandler(memento, target);120 target.scale(memento.factor);121 },122 registerSVGOrdered(source) {123 let memento = this.registerSVHHandler(source);124 return memento;125 },126 revertSVGOrdered(memento, target) {127 target.clear();128 for (let i=0; i<memento.children.length; i++) {129 target.add(memento.children[i]);130 }131 target._active = memento._active;132 },133 registerSVGPath(source) {134 let memento = {};135 memento.fillColor = source.fillColor;136 memento.strokeWidth = source.strokeWidth;137 memento.strokeColor = source.strokeColor;138 memento._opacity = source.opacity;139 memento._fillopacity = source.opacity;140 memento.drawing = source.drawing;141 memento.points = this.registerArray(source.points);142 return memento;143 },144 revertSVGPath(memento, target) {145 target.color(memento.fillColor, memento.strokeWidth, memento.strokeColor);146 target.opacity(memento._opacity);147 target.fillOpacity(memento._fillopacity);148 target.drawing = memento.drawing;149 this.revertArray(memento.points, target.points);150 target._draw();151 },152 rollback(notCancelable) {153 if (notCancelable) {154 console.log("not cancel");155 }156 if (this.enabled) {157 this.enabled = false;158 if (!this.current || this.current.size == 0) {159 this.current = this.previous.pop();160 }161 if (this.current) {162 let toCome = new Map();163 for (let registrable of this.current.keys()) {164 let memento = this.current.get(registrable);165 if (!notCancelable) {166 let save = registrable.memorize();167 toCome.set(registrable, save);168 }169 registrable.revert(memento);170 }171 if (!notCancelable) {172 this.next.push(toCome);173 }174 this.finalizer && this.finalizer();175 }176 this.current = new Map();177 this.enabled = true;178 }179 },180 replay() {181 if (this.enabled) {182 this.enabled = false;183 if (!this.current || this.current.size == 0) {184 this.current = this.next.pop();185 }186 if (this.current) {187 let last = new Map();188 for (let registrable of this.current.keys()) {189 let memento = this.current.get(registrable);190 let save = registrable.memorize();191 last.set(registrable, save);192 registrable.revert(memento);193 }194 this.previous.push(last);195 this.finalizer && this.finalizer();196 }197 this.current = new Map();198 this.enabled = true;199 }200 },201 finalize(handler) {202 this.finalizer = handler;203 }...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status: %s', data.statusText);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('First View: %s', data.data.average.firstView.loadTime);9 });10});
Using AI Code Generation
1var wpt = require('wpt');2wpt.notCancelable(function(err, data) {3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.notCancelable(function(err, data) {11 if(err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.notCancelable(function(err, data) {19 if(err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.notCancelable(function(err, data) {27 if(err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.notCancelable(function(err, data) {35 if(err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.notCancelable(function(err, data) {43 if(err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.notCancelable(function(err, data) {51 if(err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var wpt = require('wpt');58wpt.notCancelable(function(err, data) {59 if(err) {60 console.log(err);61 } else {62 console.log(data);63 }64});65var wpt = require('wpt');66wpt.notCancelable(function(err, data) {67 if(err) {
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test status: ' + data.statusCode);7 console.log('Test results: ' + data.statusText);8 console.log('Test ID: ' + data.data.testId);9 console.log('Test URL: ' + data.data.summary);10 console.log('View test: ' + data.data.userUrl);11 }12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15 if (err) {16 console.log('Error: ' + err);17 } else {18 console.log('Test status: ' + data.statusCode);19 console.log('Test results: ' + data.statusText);20 console.log('Test ID: ' + data.data.testId);21 console.log('Test URL: ' + data.data.summary);22 console.log('View test: ' + data.data.userUrl);23 }24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) {28 console.log('Error: ' + err);29 } else {30 console.log('Test status: ' + data.statusCode);31 console.log('Test results: ' + data.statusText);32 console.log('Test ID: ' + data.data.testId);33 console.log('Test URL: ' + data.data.summary);34 console.log('View test: ' + data.data.userUrl);35 }36});37var wpt = require('webpagetest');38var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1CKEDITOR.replace('editor1', {2 wptextpattern: {3 }4});5CKEDITOR.replace('editor1', {6 wptextpattern: {7 }8});9CKEDITOR.replace('editor1', {10 wptextpattern: {11 }12});13CKEDITOR.replace('editor1', {14 wptextpattern: {15 }16});17CKEDITOR.replace('editor1', {18 wptextpattern: {19 }20});21CKEDITOR.replace('editor1', {22 wptextpattern: {23 }24});25CKEDITOR.replace('editor1', {26 wptextpattern: {27 }28});29CKEDITOR.replace('editor1', {30 wptextpattern: {31 }32});33CKEDITOR.replace('editor1', {34 wptextpattern: {35 }36});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0c4e7d2e2b0f7c9b9d9c7e8b8c7d7e8');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 wpt.notCancelable(data.data.testId, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log(data);12 }13 });14 }15});16var wpt = require('wpt');17var wpt = new WebPageTest('www.webpagetest.org', 'A.0c4e7d2e2b0f7c9b9d9c7e8b8c7d7e8');18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 wpt.cancelTest(data.data.testId, function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28 });29 }30});31var wpt = require('wpt');32var wpt = new WebPageTest('www.webpagetest.org', 'A.0c4e7d2e2b0f7c9b9d9c7e8b8c7d7e8');33wpt.getLocations(function(err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39});40var wpt = require('wpt');41var wpt = new WebPageTest('
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!!