Best JavaScript code snippet using wpt
resume-marker-service.test.js
Source:resume-marker-service.test.js
...13 expect(instance).toBeDefined()14 })15 it('starts with zero ranges', function() {16 var instance = service(conf)17 expect(instance.getRanges().length).toBe(0)18 })19 it('sets an id and _id attribute on a newly created range', function() {20 var instance = service(conf)21 instance.createNewRange({trade_id:3000, time:1517787104900})22 expect(instance.getRanges().length).toBe(1)23 expect(instance.getRanges()[0].id).toBeDefined24 expect(instance.getRanges()[0]._id).toBeDefined25 })26 it('has one range, after creating a range, and it only contains the trade_id we just gave it', function() {27 var instance = service(conf)28 29 instance.createNewRange({trade_id:3000, time:1517787104900})30 expect(instance.getRanges().length).toBe(1)31 expect(instance.getRanges()[0].from).toBe(3000)32 expect(instance.getRanges()[0].to).toBe(3000)33 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)34 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)35 })36 it('gets the correct range, when you create a range and then ask is that id in a range', function() {37 var instance = service(conf)38 var trade = {trade_id:3000, time:1517787104900}39 instance.createNewRange(trade)40 var rtn = instance.isWithinRange(trade)41 expect(rtn).toBeDefined()42 expect(rtn.from).toBe(3000)43 expect(rtn.oldest_time).toBe(1517787104900)44 })45 it('returns true when we create a range on XXX, then ask is XXX + 1 within one of any range', function() {46 var instance = service(conf)47 var trade = {trade_id:3000, time:1517787104900}48 instance.createNewRange(trade)49 var trade2 = {trade_id:3001, time:1517787104902}50 var rtn = instance.isWithinOneOfAnyRange(trade2)51 expect(rtn).toBeDefined()52 expect(rtn.from).toBe(3000)53 expect(rtn.oldest_time).toBe(1517787104900)54 })55 it('returns false when we create a range on XXX, then ask is XXX + 2 within one of any range', function() {56 var instance = service(conf)57 var trade = {trade_id:3000, time:1517787104900}58 instance.createNewRange(trade)59 var trade2 = {trade_id:3002, time:1517787104904}60 var rtn = instance.isWithinOneOfAnyRange(trade2)61 expect(rtn).not.toBeDefined()62 })63 it('extends a range', function() {64 var instance = service(conf)65 var trade = {trade_id:3000, time:1517787104900}66 instance.createNewRange(trade)67 var trade2 = {trade_id:2999, time:1517787104898}68 instance.extendARange(trade2)69 expect(instance.getRanges()[0].from).toBe(2999)70 })71 it('merges two now-adjacent ranges', function() {72 var instance = service(conf)73 var trade = {trade_id:3000, time:1517787104900}74 instance.createNewRange(trade)75 expect(instance.getRanges().length).toBe(1)76 var trade2 = {trade_id:2998, time:1517787104894}77 instance.createNewRange(trade2)78 expect(instance.getRanges().length).toBe(2)79 instance.extendARange({trade_id:2999, time:1517787104896})80 expect(instance.getRanges().length).toBe(2)81 instance.merge()82 expect(instance.getRanges().length).toBe(1)83 expect(instance.getRanges()[0].from).toBe(2998)84 expect(instance.getRanges()[0].to).toBe(3000)85 expect(instance.getRanges()[0].oldest_time).toBe(1517787104894)86 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)87 })88 it('pings correctly', function() {89 var instance = service(conf)90 var trade = {trade_id:3000, time:1517787104900}91 var rtn = instance.ping(trade)92 expect(rtn).toBe(3000)93 expect(instance.getRanges().length).toBe(1)94 expect(instance.getRanges()[0].from).toBe(3000)95 expect(instance.getRanges()[0].to).toBe(3000)96 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)97 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)98 var trade2 = {trade_id:2999, time:1517787104896}99 rtn = instance.ping(trade2)100 expect(rtn).toBe(2999)101 expect(instance.getRanges().length).toBe(1)102 expect(instance.getRanges()[0].from).toBe(2999)103 expect(instance.getRanges()[0].to).toBe(3000)104 expect(instance.getRanges()[0].oldest_time).toBe(1517787104896)105 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)106 // TODO: Test what happens if you give the same number. It should return that to you as the farthest so far.107 var trade3 = {trade_id:2998, time:1517787104894}108 rtn = instance.ping(trade3)109 expect(rtn).toBe(2998)110 expect(instance.getRanges().length).toBe(1)111 expect(instance.getRanges()[0].from).toBe(2998)112 expect(instance.getRanges()[0].to).toBe(3000)113 expect(instance.getRanges()[0].oldest_time).toBe(1517787104894)114 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)115 // break from happy path -- skip the next sequential record, should start a new range116 //var trade4 = {trade_id:2997, time:1517787104892};117 var trade4 = {trade_id:2996, time:1517787104890}118 rtn = instance.ping(trade4)119 expect(rtn).toBe(2996)120 expect(instance.getRanges().length).toBe(2)121 expect(instance.getRanges()[0].from).toBe(2998)122 expect(instance.getRanges()[0].to).toBe(3000)123 expect(instance.getRanges()[0].oldest_time).toBe(1517787104894)124 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)125 expect(instance.getRanges()[1].from).toBe(2996)126 expect(instance.getRanges()[1].to).toBe(2996)127 expect(instance.getRanges()[1].oldest_time).toBe(1517787104890)128 expect(instance.getRanges()[1].newest_time).toBe(1517787104890)129 var trade5 = {trade_id:2995, time:1517787104888}130 rtn = instance.ping(trade5)131 expect(rtn).toBe(2995)132 expect(instance.getRanges().length).toBe(2)133 expect(instance.getRanges()[0].from).toBe(2998)134 expect(instance.getRanges()[0].to).toBe(3000)135 expect(instance.getRanges()[0].oldest_time).toBe(1517787104894)136 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)137 expect(instance.getRanges()[1].from).toBe(2995)138 expect(instance.getRanges()[1].to).toBe(2996)139 expect(instance.getRanges()[1].oldest_time).toBe(1517787104888)140 expect(instance.getRanges()[1].newest_time).toBe(1517787104890)141 // now, throw some salt in the game, ping the record we skipped earlier142 var trade6 = {trade_id:2997, time:1517787104892}143 rtn = instance.ping(trade6)144 expect(rtn).toBe(2995)145 expect(instance.getRanges().length).toBe(1)146 expect(instance.getRanges()[0].from).toBe(2995)147 expect(instance.getRanges()[0].to).toBe(3000)148 expect(instance.getRanges()[0].oldest_time).toBe(1517787104888)149 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)150 expect(instance.getPingCount()).toBe(6)151 })152 })153 describe('when forward', function() {154 var conf = {selector:{normalized: 'tests.BTC-USD'} }155 it('starts with zero ranges', function() {156 var instance = service(conf)157 instance.setDirection('forward') // TODO: put this in a constants object158 expect(instance.getRanges().length).toBe(0)159 })160 it('has one range, after creating a range, and it only contains the trade_id we just gave it', function() {161 var instance = service(conf)162 instance.setDirection('forward') // TODO: put this in a constants object163 164 instance.createNewRange({trade_id:3000, time:1517787104900})165 expect(instance.getRanges().length).toBe(1)166 expect(instance.getRanges()[0].from).toBe(3000)167 expect(instance.getRanges()[0].to).toBe(3000)168 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)169 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)170 })171 it('gets the correct range, when you create a range and then ask is that id in a range', function() {172 var instance = service(conf)173 instance.setDirection('forward') // TODO: put this in a constants object174 var trade = {trade_id:3000, time:1517787104900}175 instance.createNewRange(trade)176 var rtn = instance.isWithinRange(trade)177 expect(rtn).toBeDefined()178 expect(rtn.from).toBe(3000)179 expect(rtn.oldest_time).toBe(1517787104900)180 })181 it('returns true when we create a range on XXX, then ask is XXX + 1 within one of any range', function() {182 var instance = service(conf)183 instance.setDirection('forward') // TODO: put this in a constants object184 var trade = {trade_id:3000, time:1517787104900}185 instance.createNewRange(trade)186 var trade2 = {trade_id:3001, time:1517787104902}187 var rtn = instance.isWithinOneOfAnyRange(trade2)188 expect(rtn).toBeDefined()189 expect(rtn.from).toBe(3000)190 expect(rtn.oldest_time).toBe(1517787104900)191 })192 it('returns false when we create a range on XXX, then ask is XXX + 2 within one of any range', function() {193 var instance = service(conf)194 instance.setDirection('forward') // TODO: put this in a constants object195 var trade = {trade_id:3000, time:1517787104900}196 instance.createNewRange(trade)197 var trade2 = {trade_id:3002, time:1517787104902}198 var rtn = instance.isWithinOneOfAnyRange(trade2)199 expect(rtn).not.toBeDefined()200 })201 it('extends a range', function() {202 var instance = service(conf)203 instance.setDirection('forward') // TODO: put this in a constants object204 var trade = {trade_id:2999, time:1517787104898}205 instance.createNewRange(trade)206 var trade2 = {trade_id:3000, time:1517787104900}207 instance.extendARange(trade2)208 expect(instance.getRanges()[0].from).toBe(2999)209 expect(instance.getRanges()[0].to).toBe(3000)210 })211 it('merges two now-adjacent ranges', function() {212 var instance = service(conf)213 instance.setDirection('forward') // TODO: put this in a constants object214 var trade = {trade_id:2998, time:1517787104894}215 instance.createNewRange(trade)216 expect(instance.getRanges().length).toBe(1)217 var trade2 = {trade_id:3000, time:1517787104900}218 instance.createNewRange(trade2)219 expect(instance.getRanges().length).toBe(2)220 instance.extendARange({trade_id:2999, time:1517787104896})221 expect(instance.getRanges().length).toBe(2)222 instance.merge()223 expect(instance.getRanges().length).toBe(1)224 expect(instance.getRanges()[0].from).toBe(2998)225 expect(instance.getRanges()[0].to).toBe(3000)226 expect(instance.getRanges()[0].oldest_time).toBe(1517787104894)227 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)228 })229 it('pings correctly', function() {230 var instance = service(conf)231 instance.setDirection('forward') // TODO: put this in a constants object232 var trade = {trade_id:3000, time:1517787104900}233 var rtn = instance.ping(trade)234 expect(rtn).toBe(3000)235 expect(instance.getRanges().length).toBe(1)236 expect(instance.getRanges()[0].from).toBe(3000)237 expect(instance.getRanges()[0].to).toBe(3000)238 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)239 expect(instance.getRanges()[0].newest_time).toBe(1517787104900)240 var trade2 = {trade_id:3001, time:1517787104902}241 rtn = instance.ping(trade2)242 expect(rtn).toBe(3001)243 expect(instance.getRanges().length).toBe(1)244 expect(instance.getRanges()[0].from).toBe(3000)245 expect(instance.getRanges()[0].to).toBe(3001)246 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)247 expect(instance.getRanges()[0].newest_time).toBe(1517787104902)248 // TODO: Test what happens if you give the same number. It should return that to you as the farthest so far.249 var trade3 = {trade_id:3002, time:1517787104904}250 rtn = instance.ping(trade3)251 expect(rtn).toBe(3002)252 expect(instance.getRanges().length).toBe(1)253 expect(instance.getRanges()[0].from).toBe(3000)254 expect(instance.getRanges()[0].to).toBe(3002)255 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)256 expect(instance.getRanges()[0].newest_time).toBe(1517787104904)257 // break from happy path -- skip the next sequential record, should start a new range258 //var trade4 = {trade_id:3004, time:1517787104906};259 var trade4 = {trade_id:3004, time:1517787104906}260 rtn = instance.ping(trade4)261 expect(rtn).toBe(3004)262 expect(instance.getRanges().length).toBe(2)263 expect(instance.getRanges()[0].from).toBe(3000)264 expect(instance.getRanges()[0].to).toBe(3002)265 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)266 expect(instance.getRanges()[0].newest_time).toBe(1517787104904)267 expect(instance.getRanges()[1].from).toBe(3004)268 expect(instance.getRanges()[1].to).toBe(3004)269 expect(instance.getRanges()[1].oldest_time).toBe(1517787104906)270 expect(instance.getRanges()[1].newest_time).toBe(1517787104906)271 var trade5 = {trade_id:3005, time:1517787104908}272 rtn = instance.ping(trade5)273 expect(rtn).toBe(3005)274 expect(instance.getRanges().length).toBe(2)275 expect(instance.getRanges()[0].from).toBe(3000)276 expect(instance.getRanges()[0].to).toBe(3002)277 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)278 expect(instance.getRanges()[0].newest_time).toBe(1517787104904)279 expect(instance.getRanges()[1].from).toBe(3004)280 expect(instance.getRanges()[1].to).toBe(3005)281 expect(instance.getRanges()[1].oldest_time).toBe(1517787104906)282 expect(instance.getRanges()[1].newest_time).toBe(1517787104908)283 // now, throw some salt in the game, ping the record we skipped earlier284 var trade6 = {trade_id:3003, time:1517787104905}285 rtn = instance.ping(trade6)286 expect(rtn).toBe(3005)287 expect(instance.getRanges().length).toBe(1)288 expect(instance.getRanges()[0].from).toBe(3000)289 expect(instance.getRanges()[0].to).toBe(3005)290 expect(instance.getRanges()[0].oldest_time).toBe(1517787104900)291 expect(instance.getRanges()[0].newest_time).toBe(1517787104908)292 })293 })294 describe('database stuff', function() {295 var conf = {selector: {normalized: 'tests.BTC-USD'}, resumeMarkersArray: []}296 it('still calls the callback when flush is called and there are no ranges', function() {297 var instance = service(conf)298 instance.load()299 expect(instance.getRanges().length).toBe(0)300 var cb = jasmine.createSpy('flushCallback')301 instance.flush(cb)302 expect(cb).toHaveBeenCalled()303 })304 })305 describe('database stuff', function() {306 var conf = {307 selector: {normalized: 'tests.BTC-USD'},308 resumeMarkersArray: [ {from: 2994, to: 2998, oldest_time: 1517787104960, newest_time: 1517787104986},309 {from: 2894, to: 2898, oldest_time: 1517787103960, newest_time: 1517787103986},310 {from: 2794, to: 2798, oldest_time: 1517787102960, newest_time: 1517787102986}311 ],312 mockDeleteManyFunction: jasmine.createSpy('mockDeleteManyFunction'),313 mockInsertManyFunction: jasmine.createSpy('mockInsertManyFunction')314 }315 it('loads records from the database correctly', function() {316 var instance = service(conf)317 instance.load()318 expect(instance.getRanges().length).toBe(3)319 })320 it('writes changed records correctly', function() {321 var instance = service(conf)322 instance.load()323 var range = instance.getRanges()[0]324 range.from -= 1325 instance.flush()326 expect(conf.mockDeleteManyFunction).toHaveBeenCalled()327 expect(conf.mockInsertManyFunction).toHaveBeenCalled()328 })329 })330 describe('ping count', function() {331 var conf = {selector: {normalized: 'tests.BTC-USD'}}332 it('increases, but not when a number is already in range', function() {333 var instance = service(conf)334 var trade = {trade_id:3000, time:1517787104900}335 instance.ping(trade)336 var trade2 = {trade_id:2999, time:1517787104896}337 instance.ping(trade2)...
Using AI Code Generation
1var editor = CKEDITOR.instances.editor1;2var ranges = editor.getRanges();3var range = ranges[0];4var startContainer = range.startContainer;5var endContainer = range.endContainer;6var startOffset = range.startOffset;7var endOffset = range.endOffset;8var isCollapsed = range.collapsed;9console.log('startContainer: ' + startContainer.getName());10console.log('endContainer: ' + endContainer.getName());11console.log('startOffset: ' + startOffset);12console.log('endOffset: ' + endOffset);13console.log('isCollapsed: ' + isCollapsed);14var editor = CKEDITOR.instances.editor1;15editor.insertText('Hello World!');16var editor = CKEDITOR.instances.editor1;17editor.insertHtml('<p>Hello World!</p>');18var editor = CKEDITOR.instances.editor1;19var p = editor.document.createElement('p');20p.setText('Hello World!');21editor.insertElement(p);22var editor = CKEDITOR.instances.editor1;23editor.insertText('Hello World!');24var editor = CKEDITOR.instances.editor1;25editor.insertHtml('<p>Hello World!</p>');26var editor = CKEDITOR.instances.editor1;27var p = editor.document.createElement('p');28p.setText('Hello World!');29editor.insertElement(p);30var editor = CKEDITOR.instances.editor1;31editor.insertText('Hello World!');32var editor = CKEDITOR.instances.editor1;33editor.insertHtml('<p>Hello World!</p>');34var editor = CKEDITOR.instances.editor1;35var p = editor.document.createElement('p');36p.setText('Hello World!');37editor.insertElement(p);38var editor = CKEDITOR.instances.editor1;39editor.insertText('Hello World!');40var editor = CKEDITOR.instances.editor1;41editor.insertHtml('<
Using AI Code Generation
1var editor = CKEDITOR.instances.editor1;2var ranges = editor.getRanges();3var range = ranges[0];4var startContainer = range.startContainer;5var endContainer = range.endContainer;6var startOffset = range.startOffset;7var endOffset = range.endOffset;8var text = startContainer.getText();9var textToReplace = text.substring(startOffset, endOffset);10var editor = CKEDITOR.instances.editor1;11var range = editor.createRange();12range.setStart(startContainer, startOffset);13range.setEnd(endContainer, endOffset);14var ranges = [range];15editor.setRanges(ranges);16function insertImageIntoEditor(src, alt, width, height) {17 var editor = CKEDITOR.instances.editor1;18 var img = new CKEDITOR.dom.element('img');19 img.setAttribute('src', src);20 img.setAttribute('alt', alt);21 img.setAttribute('width', width);22 img.setAttribute('height', height);23 editor.insertElement(img);24}25CKEDITOR.dialog.on('show', function(event) {26 var editor = CKEDITOR.instances.editor1;27 editor.focus();28});
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org');2wpt.getLocations(function(err, data) {3 if (err) return console.error(err);4 console.log(data);5});6var wpt = new WebPageTest('www.webpagetest.org');7wpt.getLocations(function(err, data) {8 if (err) return console.error(err);9 console.log(data);10});11var wpt = new WebPageTest('www.webpagetest.org');12wpt.getTesters(function(err, data) {13 if (err) return console.error(err);14 console.log(data);15});16var wpt = new WebPageTest('www.webpagetest.org');17wpt.getTesters(function(err, data) {18 if (err) return console.error(err);19 console.log(data);20});21var wpt = new WebPageTest('www.webpagetest.org');22wpt.getTesters(function(err, data) {23 if (err) return console.error(err);24 console.log(data);25});26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getTesters(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = new WebPageTest('www.webpagetest.org');32wpt.getTesters(function(err, data) {33 if (err) return console.error(err);34 console.log(data);35});36var wpt = new WebPageTest('www.webpagetest.org');37wpt.getTesters(function(err, data) {38 if (err) return console.error(err);39 console.log(data);40});41var wpt = new WebPageTest('www.webpag
Using AI Code Generation
1var wptjs = require('wptjs');2var wpt = new wptjs('API_KEY');3wpt.getRanges(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wptjs = require('wptjs');11var wpt = new wptjs('API_KEY');12wpt.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.getRanges(options, function (err, data) {5 if (err) {6 console.log('Error: ' + err.message);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var ranges = wptoolkit.getRanges('test.txt');3console.log(ranges);4var wptoolkit = require('wptoolkit');5var ranges = wptoolkit.getRangesSync('test.txt');6console.log(ranges);7var wptoolkit = require('wptoolkit');8var stream = wptoolkit.getRangesStream('test.txt');9stream.on('data', function(ranges) {10 console.log(ranges);11});
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const item = wptools.page('Q42');4item.getRanges((err, ranges) => {5 if (err) {6 console.log(err);7 } else {8 console.log(ranges);9 }10});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestResults('160610_1X_9a2e0f8a2e76d6c0e6f7b0c8f8d7f1d9', function(err, data) {4 if (err) return console.error(err);5 console.log(data.data.median.firstView.SpeedIndex);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getTestResults('160610_1X_9a2e0f8a2e76d6c0e6f7b0c8f8d7f1d9', function(err, data) {10 if (err) return console.error(err);11 console.log(data.data.median.firstView.SpeedIndex);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.getTestResults('160610_1X_9a2e0f8a2e76d6c0e6f7b0c8f8d7f1d9', function(err, data) {16 if (err) return console.error(err);17 console.log(data.data.median.firstView.SpeedIndex);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTestResults('160610_1X_9a2e0f8a2e76d6c0e6f7b0c8f8d7f1d9', function(err, data) {22 if (err) return console.error(err);23 console.log(data.data.median.firstView.SpeedIndex);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getTestResults('160610
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!!