Best JavaScript code snippet using wpt
MixedCollection.js
Source:MixedCollection.js
1/*!2 * Ext JS Library 3.2.23 * Copyright(c) 2006-2010 Ext JS, Inc.4 * licensing@extjs.com5 * http://www.extjs.com/license6 */7(function() {8 var suite = Ext.test.session.getSuite('Ext.util.MixedCollection'),9 assert = Y.Assert;10 suite.add(new Y.Test.Case({11 name: 'constructor',12 setUp: function() {13 this.mc = new Ext.util.MixedCollection();14 },15 tearDown: function() {16 this.mc.clear();17 },18 //test that a default getKey implementation is set19 testHasDefaultGetKey: function() {20 var item1 = {id: 1, data: 'first item' },21 item2 = {id: 2, data: 'second item'};22 23 this.mc.add(item1);24 this.mc.add(item2);25 26 assert.areSame(item1, this.mc.get(1));27 assert.areSame(item2, this.mc.get(2));28 },29 //test that we can provide a getKey implementation30 testCanSetGetKey: function() {31 var collection = new Ext.util.MixedCollection(false, function(item) {32 return item.myKey;33 });34 35 var item1 = {myKey: 'a', data: 'first item' },36 item2 = {myKey: 'b', data: 'second item'};37 38 collection.add(item1);39 collection.add(item2);40 41 assert.areSame(item2, collection.get('b'));42 assert.areSame(item1, collection.get('a'));43 }44 }));45 46 suite.add(new Y.Test.Case({47 name: 'iterators',48 49 setUp: function() {50 this.mc = new Ext.util.MixedCollection();51 52 this.mc.addAll([53 {id: 1, name: 'first'},54 {id: 2, name: 'second'},55 {id: 3, name: 'third'}56 ]);57 },58 testEach: function() {59 var callCount = 0, callScope, total;60 61 this.mc.each(function(item, index, length) {62 //make sure that the function is called in the correct scope63 callScope = this;64 callCount ++;65 total = length;66 }, this);67 68 assert.areEqual(this, callScope);69 assert.areEqual(3, callCount);70 assert.areEqual(3, total);71 },72 73 testEachKey: function() {74 var callCount = 0, callScope;75 76 this.mc.eachKey(function(key, index, length) {77 //make sure that the function is called in the correct scope78 callScope = this;79 callCount ++;80 }, this);81 82 assert.areEqual(this, callScope);83 assert.areEqual(3, callCount);84 }85 }));86 87 suite.add(new Y.Test.Case({88 name: 'add and remove',89 90 setUp: function() {91 this.mc = new Ext.util.MixedCollection();92 },93 94 testAddAll: function() {95 var mc = this.mc;96 97 assert.areEqual(0, mc.length);98 99 mc.addAll([{id: 1}, {id: 2}, {id: 3}]);100 101 assert.areEqual(3, mc.length);102 },103 104 testAddAndClear: function() {105 var mc = this.mc;106 107 mc.add({id: 1});108 mc.add({id: 2});109 mc.add({id: 3});110 111 assert.areEqual(3, mc.length);112 113 mc.clear();114 assert.areEqual(0, mc.length);115 },116 117 testAddEventFired: function() {118 var mc = this.mc,119 fired = false;120 121 mc.on('add', function() {fired = true;});122 123 mc.add({id: 1});124 assert.isTrue(fired);125 },126 127 testClearEventFired: function() {128 var mc = this.mc,129 fired = false;130 131 mc.on('clear', function() {fired = true;}, this);132 mc.clear();133 134 assert.isTrue(fired);135 },136 137 testGetCount: function() {138 this.mc.add({id: 1});139 this.mc.add({id: 2});140 this.mc.add({id: 3});141 142 assert.areEqual(3, this.mc.getCount());143 },144 145 testRemove: function() {146 147 },148 149 testRemoveFiresEvent: function() {150 151 }152 }));153 154 suite.add(new Y.Test.Case({155 name: 'insert',156 157 setUp: function() {158 this.mc = new Ext.util.MixedCollection();159 160 this.mc.addAll([161 {id: 1, name: 'first'},162 {id: 2, name: 'second'},163 {id: 3, name: 'third'}164 ]);165 },166 167 doInsert: function() {168 this.mc.insert(1, {id: 4, name: 'fourth'});169 },170 171 testInsertsToCorrectLocation: function() {172 this.doInsert();173 174 assert.areEqual(4, this.mc.itemAt(1).id);175 },176 177 testOtherItemsPreserved: function() {178 var prevCount = this.mc.getCount();179 180 this.doInsert();181 assert.areEqual(prevCount + 1, this.mc.getCount());182 },183 184 testFiresAddEvent: function() {185 var fired = false;186 187 this.mc.on('add', function() { fired = true; });188 this.doInsert();189 190 assert.isTrue(fired);191 }192 }));193 194 suite.add(new Y.Test.Case({195 name: 'replace',196 197 setUp: function() {198 this.mc = new Ext.util.MixedCollection();199 200 this.mc.addAll([201 {id: 1, name: 'first'},202 {id: 2, name: 'second'},203 {id: 3, name: 'third'}204 ]);205 },206 207 doReplace: function() {208 this.mc.replace(2, {id: 4, name: 'fourth'});209 },210 211 testReplacesCorrectItem: function() {212 this.doReplace();213 assert.areEqual("fourth", this.mc.itemAt(1).name);214 },215 216 testPreviousItemRemoved: function() {217 var prevCount = this.mc.getCount();218 219 this.doReplace();220 assert.areEqual(prevCount, this.mc.getCount());221 },222 223 testReplaceEventFired: function() {224 var fired = false;225 226 this.mc.on('replace', function() { fired = true; });227 this.doReplace();228 229 assert.isTrue(fired);230 }231 }));232 233 suite.add(new Y.Test.Case({234 name: 'clone',235 236 setUp: function() {237 this.mc = new Ext.util.MixedCollection();238 239 this.mc.addAll([240 {id: 1, name: 'first'},241 {id: 2, name: 'second'},242 {id: 3, name: 'third'}243 ]);244 },245 246 //test that a shallow clone is completed correctly247 testClone: function() {248 var newMC = this.mc.clone();249 250 assert.areEqual(3, newMC.getCount());251 252 Ext.each([1, 2, 3], function(id) {253 assert.areEqual(this.mc.get(id).id, newMC.get(id).id);254 }, this);255 }256 }));257 258 suite.add(new Y.Test.Case({259 name: 'getting items',260 261 setUp: function() {262 this.mc = new Ext.util.MixedCollection();263 this.item1 = {id: 1, name: 'first'};264 265 this.mc.addAll([266 this.item1,267 {id: 2, name: 'second'},268 {id: 3, name: 'third'}269 ]);270 },271 272 testFirst: function() {273 assert.areEqual(1, this.mc.first().id);274 },275 276 testLast: function() {277 assert.areEqual(3, this.mc.last().id);278 },279 280 testGet: function() {281 assert.areEqual(2, this.mc.get(2).id);282 },283 284 testGetKey: function() {285 assert.areEqual(1, this.mc.getKey(this.item1));286 },287 288 //should return items in the given range289 testGetRange: function() {290 var items = this.mc.getRange(1, 2);291 292 assert.areEqual(2, items.length);293 assert.areEqual(2, items[0].id);294 assert.areEqual(3, items[1].id);295 },296 297 //should get all items298 testGetRangeWithNoArguments: function() {299 var items = this.mc.getRange();300 301 assert.areEqual(3, items.length);302 },303 304 //should get all items after the provided start index305 testGetRangeWithNoEnd: function() {306 var items = this.mc.getRange(1);307 308 assert.areEqual(2, items.length);309 },310 311 testIndexOf: function() {312 assert.areEqual(0, this.mc.indexOf(this.item1));313 },314 315 testIndexOfKey: function() {316 assert.areEqual(2, this.mc.indexOfKey(3));317 },318 319 testKey: function() {320 assert.areEqual(3, this.mc.key(3).id);321 },322 323 testItemByIndex: function() {324 this.mc.add({id: 'a', name: 'another item'});325 this.mc.add({id: 'b', name: 'yet another item'});326 327 assert.areEqual('b', this.mc.item(4).id);328 },329 330 //key should take priority over index331 testItemByKey: function() {332 this.mc.add({id: 'a', name: 'another item'});333 334 assert.areEqual('a', this.mc.item('a').id);335 },336 337 testItemAt: function() {338 assert.areEqual(3, this.mc.itemAt(2).id);339 }340 }));341 342 suite.add(new Y.Test.Case({343 name: 'find functions',344 345 setUp: function() {346 this.mc = new Ext.util.MixedCollection();347 348 this.mc.addAll([349 {id: 1, name: 'first'},350 {id: 2, name: 'second'},351 {id: 3, name: 'third'}352 ]);353 },354 355 testFind: function() {356 var matched = this.mc.find(function(item) {357 return item.name == 'third';358 });359 360 assert.areEqual('third', matched.name);361 },362 363 testFindIndex: function() {364 var matched = this.mc.findIndex('name', 'third');365 366 assert.areEqual(2, matched);367 },368 369 testFindIndexBy: function() {370 var matched = this.mc.findIndexBy(function(item) {371 return item.name == 'second';372 });373 374 assert.areEqual(1, matched);375 }376 }));377 378 suite.add(new Y.Test.Case({379 name: 'contains',380 381 setUp: function() {382 this.mc = new Ext.util.MixedCollection();383 this.item = {id: 1, name: 'first'};384 385 this.mc.addAll([386 this.item,387 {id: 2, name: 'second'},388 {id: 3, name: 'third'}389 ]);390 },391 392 tearDown: function() {393 delete this.item;394 },395 396 testContains: function() {397 assert.isTrue(this.mc.contains(this.item));398 },399 400 testDoesNotContain: function() {401 assert.isFalse(this.mc.contains({some: 'object'}));402 },403 404 testContainsKey: function() {405 assert.isTrue(this.mc.containsKey(1));406 },407 408 testDoesNotContainKey: function() {409 assert.isFalse(this.mc.containsKey('abc'));410 }411 }));412 413 suite.add(new Y.Test.Case({414 name: 'single sorting',415 416 setUp: function() {417 this.mc = new Ext.util.MixedCollection(false, function(item) {418 return item['code'];419 });420 421 this.mc.addAll([422 {id: 1, name: 'first', code: 'C', modifier: 10},423 {id: 2, name: 'second', code: 'A', modifier: 100},424 {id: 3, name: 'third', code: 'B', modifier: 5}425 ]);426 },427 428 testKeySort: function() {429 var mc = this.mc;430 mc.keySort();431 432 assert.areEqual('A', mc.itemAt(0).code);433 assert.areEqual('B', mc.itemAt(1).code);434 assert.areEqual('C', mc.itemAt(2).code);435 },436 437 testDirectionalKeySort: function() {438 var mc = this.mc;439 mc.keySort('DESC');440 441 assert.areEqual('C', mc.itemAt(0).code);442 assert.areEqual('B', mc.itemAt(1).code);443 assert.areEqual('A', mc.itemAt(2).code);444 },445 446 testSort: function() {447 var mc = new Ext.util.MixedCollection();448 mc.addAll(3, 1, 4, 2);449 mc.sort();450 451 assert.areEqual(1, mc.itemAt(0));452 assert.areEqual(2, mc.itemAt(1));453 assert.areEqual(3, mc.itemAt(2));454 assert.areEqual(4, mc.itemAt(3));455 },456 457 testDirectionalSort: function() {458 459 },460 461 testSortWithComparator: function() {462 var mc = this.mc;463 mc.sort('ASC', function(a, b) {464 return (a.id * a.modifier) - (b.id * b.modifier);465 });466 467 assert.areEqual('C', mc.itemAt(0).code);468 assert.areEqual('B', mc.itemAt(1).code);469 assert.areEqual('A', mc.itemAt(2).code);470 },471 472 testDirectionalSortWithComparator: function() {473 var mc = this.mc;474 mc.sort('DESC', function(a, b) {475 return (a.id * a.modifier) - (b.id * b.modifier);476 });477 478 assert.areEqual('A', mc.itemAt(0).code);479 assert.areEqual('B', mc.itemAt(1).code);480 assert.areEqual('C', mc.itemAt(2).code);481 },482 483 testSortEventFired: function() {484 var fired = false;485 486 this.mc.on('sort', function() { fired = true; });487 this.mc.sort('name');488 489 assert.isTrue(fired);490 }491 }));492 493 suite.add(new Y.Test.Case({494 name: 'reordering',495 496 setUp: function() {497 this.mc = new Ext.util.MixedCollection(false, function(item) {498 return item['code'];499 });500 501 this.mc.addAll([502 {id: 1, name: 'first', code: 'C', modifier: 10},503 {id: 2, name: 'second', code: 'A', modifier: 100},504 {id: 3, name: 'third', code: 'B', modifier: 5}505 ]);506 },507 508 testReordering: function() {509 var mc = this.mc;510 511 mc.reorder({512 1: 2,513 2: 0514 });515 516 assert.areEqual('B', mc.itemAt(0).code);517 assert.areEqual('C', mc.itemAt(1).code);518 assert.areEqual('A', mc.itemAt(2).code);519 },520 521 testSortEventFired: function() {522 var wasFired = false,523 mc = this.mc;524 525 mc.on('sort', function() {526 wasFired = true;527 }, this);528 529 mc.reorder({530 1: 2,531 2: 0532 });533 534 assert.isTrue(wasFired);535 }536 }));...
Mc.js
Source:Mc.js
1if (loglvl) print("--> Mc.js");2var GPSEE = require('rpmmc');3var mc = new GPSEE.Mc();4ack("typeof mc;", "object");5ack("mc instanceof GPSEE.Mc;", true);6ack("mc.debug = 1;", 1);7ack("mc.debug = 0;", 0);8ack('mc.expand("%{_bindir}")', "/usr/bin");9// XXX noisy, adding pattern/index/level filters todo++10// nack('mc.list()', null);11ack('mc.add("foo bar")', true);12ack('mc.expand("%{foo}")', "bar");13ack('mc.del("foo")', true);14ack('mc.expand("%{foo}")', "%{foo}");15// XXX noisy, adding pattern/index/level filters todo++16// ack('mc.list()', false);17ack('mc.expand("%{lua:print(\\"lua\\")}")', "lua");18// FIXME: reloading rpm modules within embedded interpreter segfaults19// ack('mc.expand("%{perl:print \\"perl\\"}")', "perl");20// ack('mc.expand("%{python:print \\"python\\"}")', "python");21// XXX hmmm, HEAD segfaults here, rpm-5_2 doesn't. todo++22// ack('mc.expand("%{ruby:puts \\"ruby\\"}")', "ruby");23// ack('mc.expand("%{tcl:puts \\"tcl\\"}")', "tcl");24delete mc25mc = new GPSEE.Mc("cli");26ack('mc.list()', null);27ack('mc.add("foo bar")', true);28ack('mc.list()', "%foo bar");29ack('mc.expand("%{foo}")', "bar");30ack('mc.del("foo")', true);31ack('mc.list()', null);32ack('mc.expand("%{foo}")', "%{foo}");33delete mc34mc = new GPSEE.Mc("tscripts/macros");35ack('mc.list()', null);36ack('mc.add("foo bar")', true);37ack('mc.list()', "%foo bar");38ack('mc.expand("%{foo}")', "bar");39ack('mc.del("foo")', true);40ack('mc.list()', null);41ack('mc.expand("%{foo}")', "%{foo}");42delete mc43mc = new GPSEE.Mc("");44ack('mc.list()', null);45ack('mc.add("foo bar")', true);46ack('mc.list()', "%foo bar");47ack('mc.expand("%{foo}")', "bar");48ack('mc.del("foo")', true);49ack('mc.list()', null);50ack('mc.expand("%{foo}")', "%{foo}");51delete mc52// FIXME: there's no internal code path error returns to force an error out.53mc = new GPSEE.Mc("tscripts/nonexistent");54delete mc...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var fs = require('fs');6var request = require('request');7var cheerio = require('cheerio');8request(url, function (error, response, html) {9 if (!error && response.statusCode == 200) {10 var $ = cheerio.load(html);11 var mc = $('.median .stat').text();12 console.log(mc);13 }14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17 console.log(data);18});19var fs = require('fs');20var request = require('request');21var cheerio = require('cheerio');22request(url, function (error, response, html) {23 if (!error && response.statusCode == 200) {24 var $ = cheerio.load(html);25 var wpt = $('.median .stat').text();26 console.log(wpt);27 }28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31 console.log(data);32});33var fs = require('fs');34var request = require('request');35var cheerio = require('cheerio');36request(url, function (error, response, html) {37 if (!error && response.statusCode == 200) {38 var $ = cheerio.load(html);39 var wpt = $('.median .stat').text();40 var mc = $('.median .stat').text();41 console.log(wpt);
Using AI Code Generation
1var wpt = require('webpagetest');2var mc = require('multicore');3var fs = require('fs');4var util = require('util');5var mc = new mc();6var wpt = new wpt('www.webpagetest.org');7var test = function (url, key, callback) {8 wpt.runTest(url, {9 videoParams: {10 }11 }, function (err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 callback(data);17 }18 });19}20var process = function (data, callback) {21 var url = data.data.url;22 var key = data.data.key;23 var location = data.data.location;24 var connectivity = data.data.connectivity;25 var runs = data.data.runs;26 var firstViewOnly = data.data.firstViewOnly;27 var pollResults = data.data.pollResults;28 var video = data.data.video;29 var videoParams = data.data.videoParams;30 wpt.runTest(url, {31 }, function (err, data) {32 if (err) {33 console.log(err);34 } else {35 console.log(data);36 callback(data);37 }38 });39}40var download = function (data, callback) {41 var key = data.data.key;42 var location = data.data.location;43 var connectivity = data.data.connectivity;44 var runs = data.data.runs;45 var firstViewOnly = data.data.firstViewOnly;46 var pollResults = data.data.pollResults;47 var video = data.data.video;48 var videoParams = data.data.videoParams;49 var url = data.data.url;50 var results = data.data;51 wpt.getVideo(key, location, function (
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!!