Best JavaScript code snippet using devicefarmer-stf
instanceApi.unit.spec.js
Source:instanceApi.unit.spec.js
1describe('instance api',function() {2 "use strict";3 var oboeBus, oboeInstance,4 sampleUrl = 'http://example.com';5 beforeEach(function () {6 oboeBus = spiedPubSub();7 spyOn(oboeBus, 'emit' );8 spyOn(oboeBus, 'on' );9 spyOn(oboeBus, 'un' );10 oboeInstance = instanceApi(oboeBus, sampleUrl);11 });12 function anAscent() {13 return list(namedNode(ROOT_PATH, {}));14 }15 it('puts the url on the oboe instance', function(){16 expect( oboeInstance.source).toBe( sampleUrl );17 });18 describe('header method', function(){19 it('returns undefined if not available', function() {20 expect( oboeInstance.header() ).toBeUndefined();21 });22 it('can provide object once available', function() {23 var headers = {"x-remainingRequests": 100};24 oboeBus(HTTP_START).emit( 200, headers );25 expect( oboeInstance.header() ).toEqual(headers);26 });27 it('can provide single header once available', function() {28 var headers = {"x-remainingRequests": 100};29 oboeBus(HTTP_START).emit( 200, headers );30 expect( oboeInstance.header('x-remainingRequests') ).toEqual(100);31 });32 it('gives undefined for non-existent single header', function() {33 var headers = {"x-remainingRequests": 100};34 oboeBus(HTTP_START).emit( 200, headers );35 expect( oboeInstance.header('x-remainingBathtubs') ).toBeUndefined();36 });37 });38 describe('root method', function(){39 it('returns undefined if not available', function() {40 expect( oboeInstance.root() ).toBeUndefined();41 });42 it('can provide object once available', function() {43 var root = {I:'am', the:'root'};44 oboeBus(ROOT_PATH_FOUND).emit( root);45 expect( oboeInstance.root() ).toEqual(root);46 });47 });48 describe('node and path callbacks', function(){49 it('calls node callback when notified of matching node', function() {50 var callback = jasmine.createSpy('node callback'),51 node = {},52 path = [],53 ancestors = [];54 oboeInstance.on('node', 'a_pattern', callback);55 expect(callback).not.toHaveBeenCalled()56 oboeBus('node:a_pattern').emit( node, path, ancestors );57 expect(callback).toHaveBeenCalledWith( node, path, ancestors );58 });59 it('calls path callback when notified of matching path', function() {60 var callback = jasmine.createSpy('path callback'),61 node = {},62 path = [],63 ancestors = [];64 oboeInstance.on('path', 'a_pattern', callback);65 expect(callback).not.toHaveBeenCalled()66 oboeBus('path:a_pattern').emit( node, path, ancestors );67 expect(callback).toHaveBeenCalledWith( node, path, ancestors );68 });69 it('allows short-cut node matching', function() {70 var pattern1Callback = jasmine.createSpy('pattern 1 callback'),71 pattern2Callback = jasmine.createSpy('pattern 2 callback');72 oboeInstance.on('node', {73 pattern1: pattern1Callback,74 pattern2: pattern2Callback75 });76 expect(pattern1Callback).not.toHaveBeenCalled()77 expect(pattern2Callback).not.toHaveBeenCalled()78 oboeBus('node:pattern1').emit( {}, anAscent())79 expect(pattern1Callback).toHaveBeenCalled()80 expect(pattern2Callback).not.toHaveBeenCalled()81 oboeBus('node:pattern2').emit( {}, anAscent())82 expect(pattern2Callback).toHaveBeenCalled()83 });84 it('calls node callback added using 2-arg mode when notified of match to pattern', function() {85 var callback = jasmine.createSpy('node callback'),86 node = {},87 path = [],88 ancestors = [];89 oboeInstance.on('node:a_pattern', callback)90 expect(callback).not.toHaveBeenCalled()91 oboeBus('node:a_pattern').emit( node, path, ancestors );92 expect(callback).toHaveBeenCalledWith( node, path, ancestors );93 });94 it('allows adding using addListener method', function() {95 var callback = jasmine.createSpy('node callback'),96 node = {},97 path = [],98 ancestors = [];99 oboeInstance.addListener('node:a_pattern', callback)100 expect(callback).not.toHaveBeenCalled()101 oboeBus('node:a_pattern').emit( node, path, ancestors );102 expect(callback).toHaveBeenCalledWith( node, path, ancestors );103 });104 it('calls path callback added using 2-arg mode when notified of match to pattern', function() {105 var callback = jasmine.createSpy('path callback'),106 node = {},107 path = [],108 ancestors = [];109 oboeInstance.on('path:a_pattern', callback);110 expect(callback).not.toHaveBeenCalled()111 oboeBus('path:a_pattern').emit( node, path, ancestors );112 expect(callback).toHaveBeenCalledWith( node, path, ancestors );113 });114 it('doesn\'t call node callback on path found', function() {115 var callback = jasmine.createSpy('node callback');116 oboeInstance.on('node', 'a_pattern', callback);117 expect(callback).not.toHaveBeenCalled()118 oboeBus('path:a_pattern').emit( {}, list(namedNode(ROOT_PATH, {}) ) );119 expect(callback).not.toHaveBeenCalled();120 });121 it('doesn\'t call again after forget called from inside callback', function() {122 var nodeCallback = jasmine.createSpy('node callback').and.callFake(function(){123 this.forget();124 }),125 ascent = list(namedNode('node', {}));126 oboeInstance.on('node', 'a_pattern', nodeCallback);127 oboeBus('node:a_pattern').emit( {}, ascent);128 expect(nodeCallback.calls.count()).toBe(1)129 oboeBus('node:a_pattern').emit( {}, ascent);130 expect(nodeCallback.calls.count()).toBe(1)131 });132 xit('doesn\'t call node callback after callback is removed', function() {133 var nodeCallback = jasmine.createSpy('node callback'),134 ascent = list(namedNode('node', {}));135 oboeInstance.on('node', 'a_pattern', nodeCallback);136 oboeInstance.removeListener('node', 'a_pattern', nodeCallback);137 oboeBus('node:a_pattern').emit( {}, ascent);138 expect(nodeCallback).not.toHaveBeenCalled()139 });140 it('doesn\'t call node callback after callback is removed using 2-arg form', function() {141 var nodeCallback = jasmine.createSpy('node callback'),142 ascent = list(namedNode('node', {}));143 // oboeInstance.on('node', 'a_pattern', nodeCallback);144 oboeInstance.on('node', 'a_pattern', nodeCallback);145 oboeInstance.removeListener('node:a_pattern', nodeCallback);146 oboeBus('node:a_pattern').emit( {}, ascent);147 expect(nodeCallback).not.toHaveBeenCalled()148 });149 xit('doesn\'t call path callback after callback is removed', function() {150 var pathCallback = jasmine.createSpy('path callback'),151 ascent = list(namedNode('path', {}));152 oboeInstance.on('path', 'a_pattern', pathCallback);153 oboeInstance.removeListener('path', 'a_pattern', pathCallback);154 oboeBus('path:a_pattern').emit( {}, ascent);155 expect(pathCallback).not.toHaveBeenCalled()156 });157 it('doesn\'t call path callback after callback is removed using 2-arg form', function() {158 var pathCallback = jasmine.createSpy('path callback'),159 ascent = list(namedNode('path', {}));160 oboeInstance.on('path', 'a_pattern', pathCallback);161 oboeInstance.removeListener('path:a_pattern', pathCallback);162 oboeBus('path:a_pattern').emit( {}, ascent);163 expect(pathCallback).not.toHaveBeenCalled()164 });165 it('doesn\'t remove callback if wrong pattern is removed', function() {166 var nodeCallback = jasmine.createSpy('node callback'),167 ascent = list(namedNode('node', {}));168 oboeInstance.on('node', 'a_pattern', nodeCallback);169 oboeInstance.removeListener('node', 'wrong_pattern', nodeCallback);170 oboeBus('node:a_pattern').emit( {}, ascent);171 expect(nodeCallback).toHaveBeenCalled()172 });173 it('doesn\'t remove callback if wrong callback is removed', function() {174 var correctCallback = jasmine.createSpy('correct callback'),175 wrongCallback = jasmine.createSpy('wrong callback'),176 ascent = list(namedNode('node', {}));177 oboeInstance.on('node', 'a_pattern', correctCallback);178 oboeInstance.removeListener('node', 'a_pattern', wrongCallback);179 oboeBus('node:a_pattern').emit( {}, ascent);180 expect(correctCallback).toHaveBeenCalled()181 });182 it('allows node listeners to be removed in a different style than they were added', function() {183 var184 callback1 = jasmine.createSpy('callback 1'),185 callback2 = jasmine.createSpy('callback 2'),186 callback3 = jasmine.createSpy('callback 3'),187 ascent = list(namedNode('node', {}));188 oboeInstance.node('pattern1', callback1);189 oboeInstance.on('node', 'pattern2', callback2);190 oboeInstance.on('node', {pattern3: callback3});191 oboeInstance.removeListener('node:pattern1', callback1);192 oboeInstance.removeListener('node:pattern2', callback2);193 oboeInstance.removeListener('node:pattern3', callback3);194 oboeBus('node:pattern1').emit( {}, ascent);195 oboeBus('node:pattern2').emit( {}, ascent);196 oboeBus('node:pattern3').emit( {}, ascent);197 expect(callback1).not.toHaveBeenCalled()198 expect(callback2).not.toHaveBeenCalled()199 expect(callback3).not.toHaveBeenCalled()200 });201 });202 describe('start event', function() {203 it('notifies .on(start) listener when http response starts', function(){204 var startCallback = jasmine.createSpy('start callback');205 oboeInstance.on('start', startCallback);206 expect(startCallback).not.toHaveBeenCalled()207 oboeBus(HTTP_START).emit( 200, {a_header:'foo'} )208 expect(startCallback).toHaveBeenCalledWith( 200, {a_header:'foo'} )209 });210 it('notifies .start listener when http response starts', function(){211 var startCallback = jasmine.createSpy('start callback');212 oboeInstance.start(startCallback);213 expect(startCallback).not.toHaveBeenCalled()214 oboeBus(HTTP_START).emit( 200, {a_header:'foo'} )215 expect(startCallback).toHaveBeenCalledWith( 200, {a_header:'foo'} )216 });217 it('can be de-registered', function() {218 var startCallback = jasmine.createSpy('start callback');219 oboeInstance.on('start', startCallback);220 oboeInstance.removeListener('start', startCallback);221 oboeBus(HTTP_START).emit( 200, {a_header:'foo'} )222 expect(startCallback).not.toHaveBeenCalled()223 });224 });225 describe('done event', function(){226 it('calls listener on end of JSON when added using .on(done)', function() {227 var doneCallback = jasmine.createSpy('done callback');228 oboeInstance.on('done', doneCallback);229 expect(doneCallback).not.toHaveBeenCalled()230 oboeBus(ROOT_NODE_FOUND).emit( {}, anAscent())231 expect(doneCallback).toHaveBeenCalled()232 });233 it('calls listener on end of JSON when added using .done', function() {234 var doneCallback = jasmine.createSpy('done callback');235 oboeInstance.done(doneCallback);236 expect(doneCallback).not.toHaveBeenCalled()237 oboeBus(ROOT_NODE_FOUND).emit( {}, anAscent())238 expect(doneCallback).toHaveBeenCalled()239 });240 it('can be de-registered', function() {241 var doneCallback = jasmine.createSpy('done callback');242 oboeInstance.on('done', doneCallback);243 oboeInstance.removeListener('done', doneCallback);244 oboeBus('node:!').emit( {}, anAscent())245 expect(doneCallback).not.toHaveBeenCalled()246 });247 });248 it('emits ABORTING when .abort() is called', function() {249 oboeInstance.abort();250 expect(oboeBus(ABORTING).emit.calls.count()).toEqual(1)251 expect(oboeBus(ABORTING).emit).toHaveBeenCalled()252 });253 describe('errors cases', function(){254 describe('calling fail listener', function() {255 it('notifies .on(fail) listener when something fails', function(){256 var failCallback = jasmine.createSpy('fail callback');257 oboeInstance.on('fail', failCallback);258 expect(failCallback).not.toHaveBeenCalled()259 oboeBus(FAIL_EVENT).emit( 'something went wrong' )260 expect(failCallback).toHaveBeenCalledWith( 'something went wrong' )261 });262 it('notifies .fail listener when something fails', function(){263 var failCallback = jasmine.createSpy('fail callback');264 oboeInstance.fail(failCallback);265 expect(failCallback).not.toHaveBeenCalled()266 oboeBus(FAIL_EVENT).emit( 'something went wrong' )267 expect(failCallback).toHaveBeenCalledWith( 'something went wrong' )268 });269 it('can be de-registered', function() {270 var failCallback = jasmine.createSpy('fail callback');271 oboeInstance.on('fail', failCallback);272 oboeInstance.removeListener('fail', failCallback);273 oboeBus(FAIL_EVENT).emit( 'something went wrong' )274 expect(failCallback).not.toHaveBeenCalled()275 });276 });277 it('is protected from error in node callback', function() {278 var e = "an error";279 var nodeCallback = jasmine.createSpy('nodeCallback').and.throwError(e);280 oboeInstance.on('node', 'a_pattern', nodeCallback);281 spyOn(window, 'setTimeout');282 expect(function(){283 oboeBus('node:a_pattern').emit( {}, anAscent())284 }).not.toThrow()285 expect(nodeCallback).toHaveBeenCalled()286 expect(window.setTimeout.calls.mostRecent().args[0]).toThrow(new Error(e))287 });288 it('is protected from error in node callback added via shortcut', function() {289 var e = "an error";290 var nodeCallback = jasmine.createSpy('node callback').and.throwError(e);291 oboeInstance.on('node', {'a_pattern': nodeCallback});292 spyOn(window, 'setTimeout');293 expect(function(){294 oboeBus('node:a_pattern').emit( {}, anAscent())295 }).not.toThrow()296 expect(nodeCallback).toHaveBeenCalled()297 expect(window.setTimeout.calls.mostRecent().args[0]).toThrow(new Error(e))298 });299 it('is protected from error in path callback', function() {300 var e = "an error";301 var pathCallback = jasmine.createSpy('path callback').and.throwError(e);302 oboeInstance.on('path', 'a_pattern', pathCallback);303 spyOn(window, 'setTimeout');304 expect(function(){305 oboeBus('path:a_pattern').emit( {}, anAscent())306 }).not.toThrow()307 expect(pathCallback).toHaveBeenCalled()308 expect(window.setTimeout.calls.mostRecent().args[0]).toThrow(new Error(e))309 });310 it('is protected from error in start callback', function() {311 var e = "an error";312 var startCallback = jasmine.createSpy('start callback').and.throwError(e);313 oboeInstance.on('start', startCallback);314 spyOn(window, 'setTimeout');315 expect(function(){316 oboeBus(HTTP_START).emit()317 }).not.toThrow()318 expect(startCallback).toHaveBeenCalled()319 expect(window.setTimeout.calls.mostRecent().args[0]).toThrow(new Error(e))320 });321 it('is protected from error in done callback', function() {322 var e = "an error";323 var doneCallback = jasmine.createSpy('done callback').and.throwError(e);324 oboeInstance.done( doneCallback);325 spyOn(window, 'setTimeout');326 expect(function(){327 oboeBus(ROOT_NODE_FOUND).emit( {}, anAscent())328 }).not.toThrow()329 expect(doneCallback).toHaveBeenCalled()330 expect(window.setTimeout.calls.mostRecent().args[0]).toThrow(new Error(e))331 });332 });333 xdescribe('unknown event types', function() {334 it('can be added and fired', function() {335 var spy1 = jasmine.createSpy('xyzzy callback');336 var spy2 = jasmine.createSpy('end of universe callback');337 var setUp = function(){338 oboeInstance339 .on('xyzzy', spy1)340 .on('end_of_universe', spy2);341 };342 expect(setUp).not.toThrow();343 oboeInstance344 .on('xyzzy', spy1)345 .on('end_of_universe', spy2);346 oboeInstance.emit('xyzzy', 'hello');347 oboeInstance.emit('end_of_universe', 'oh no!');348 expect( spy1 ).toHaveBeenCalledWith('hello');349 expect( spy2 ).toHaveBeenCalledWith('oh no!');350 });351 it('is allows removal', function() {352 var spy1 = jasmine.createSpy('xyzzy callback');353 var spy2 = jasmine.createSpy('end of universe callback');354 oboeInstance355 .on('xyzzy', spy1)356 .on('end_of_universe', spy2);357 oboeInstance.removeListener('xyzzy', spy1);358 oboeInstance.removeListener('end_of_universe', spy2);359 oboeInstance.emit('xyzzy', 'hello');360 oboeInstance.emit('end_of_universe', 'oh no!');361 expect( spy1 ).not.toHaveBeenCalled()362 expect( spy2 ).not.toHaveBeenCalled()363 });364 });...
osr.js
Source:osr.js
...26 t.is(reqOptions, url);27 t.end();28 return emitter;29 });30 oboe(url);31});32test.cb('=> fn : calls oboe', (t) => {33 let emitter = new EventEmitter(),34 url = 'http://www.domain.com.au/index.json',35 oboe = oboeStreamRequest(() => {36 t.end();37 return emitter;38 }, (reqOptions) => { return emitter; });39 oboe(url);40});41test.cb('=> fn : calls self.setup with correct arguments', (t) => {42 const originalSetup = oboeStreamRequest.setup;43 let emitter = new EventEmitter(),44 url = 'http://www.domain.com.au/index.json',45 oboe = oboeStreamRequest(46 () => { return emitter; },47 () => { return emitter; }48 );49 oboeStreamRequest.setup = (req, oboeStream) => {50 oboeStreamRequest.setup = originalSetup;51 t.deepEqual(req, emitter, 'req is passed correctly');52 t.deepEqual(oboeStream, emitter, 'oboeStream is passed correctly');53 t.end();54 return originalSetup();55 };56 oboe(url);57});58test('=> fn : returns an emitter', (t) => {59 let emitter = new EventEmitter(),60 url = 'http://www.domain.com.au/index.json',61 oboe = oboeStreamRequest(62 () => { return emitter; },63 (reqOptions) => { return emitter; }64 );65 t.deepEqual(oboe(url), emitter);66});67function createSetupTest (options) {68 const originalSetup = oboeStreamRequest.setup;69 return (t) => {70 let emitter = {71 request : new EventEmitter(),72 oboe : new EventEmitter()73 },74 url = 'http://www.domain.com.au/index.json',75 oboe = oboeStreamRequest(76 () => { return emitter.oboe; },77 () => { return emitter.request; }78 );79 oboeStreamRequest.setup = (req, oboeStream) => {80 oboeStreamRequest.setup = originalSetup;81 let handlers = originalSetup();82 handlers[options.handler] = () => { t.end(); };83 return handlers;84 };85 oboe(url);86 emitter[options.emitter].emit(options.event);87 };88}89test.cb(90 '=> fn : onResponse handler called when req "response" event emitted',91 createSetupTest({92 emitter : 'request',93 event : 'response',94 handler : 'onResponse'95 })96);97test.cb(98 '=> fn : onError handler called when req "error" event emitted',99 createSetupTest({...
Using AI Code Generation
1var oboe = require('oboe');2oboe(url)3 .node('!.*', function(device) {4 console.log(device);5 })6 .done(function() {7 console.log('done');8 });9var oboe = require('oboe');10oboe(url)11 .node('!.*', function(device) {12 console.log(device);13 })14 .done(function() {15 console.log('done');16 });17var oboe = require('oboe');18oboe(url)19 .node('!.*', function(device) {20 console.log(device);21 })22 .done(function() {23 console.log('done');24 });25var oboe = require('oboe');26oboe(url)27 .node('!.*', function(device) {28 console.log(device);29 })30 .done(function() {31 console.log('done');32 });33var oboe = require('oboe');34oboe(url)35 .node('!.*', function(device) {36 console.log(device);37 })38 .done(function() {39 console.log('done');40 });41var oboe = require('oboe');42oboe(url)43 .node('!.*', function(device) {44 console.log(device);45 })46 .done(function() {47 console.log('done');48 });
Using AI Code Generation
1var oboe = require('oboe');2var http = require('http');3var fs = require('fs');4var server = http.createServer(function(req, res) {5 res.writeHead(200, {'Content-Type': 'text/html'});6 var myReadShort = fs.createReadStream('index.html', 'utf8');7 myReadShort.pipe(res);8});9server.listen(3000, '
Using AI Code Generation
1var oboe = require('oboe');2 .node('!.*', function(device) {3 console.log(device);4 });5var request = require('request');6});7var request = require('request');8});9var request = require('request');10});11var request = require('request');12});13var request = require('request');
Using AI Code Generation
1var oboe = require('oboe');2oboe(url)3 .node('!.*', function(device) {4 console.log('Found device: %s', device.serial);5 })6 .done(function() {7 console.log('All devices found!');8 });
Using AI Code Generation
1var oboe = require('oboe');2 .node('!.*', function(device) {3 console.log(device);4 });5var request = require('request');6 if (!error && response.statusCode == 200) {7 }8})9var request = require('request');10 if (!error && response.statusCode == 200) {11 }12})13var request = require('request');14 if (!error && response.statusCode == 200) {15 }16})17var request = require('request');18 if (!error && response.statusCode == 200) {19 }20})21var request = require('request');22 if (!error && response.statusCode == 200) {23 }24})25var request = require('request');26 if (!error && response.statusCode == 200) {27 }28})29var request = require('request');30 if (!error && response.statusCode == 200) {
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2 console.log(data);3});4{ serial: 'emulator-5554',5 provider: { network: 'local', channel: 'local' },6 owner: { email: 'admin@localhost' },7 display: { id: 0, width: 1080, height: 1920, xdpi: 420, ydpi: 420 },8 phone: { network: 'UNKNOWN', signal: false, roaming: false },9 battery: { present: false, level: 0, scale: 0, status: null, health: null },10 memory: { ram: 2076184576, internalStorage: 0, externalStorage: 0 },11 network: { wifi: false, ipv4: null, ipv6: null, mac: null },12 telephony: { phone: null, network: null, sim: null },
Using AI Code Generation
1var oboe = require('oboe');2var data = {3};4var opts = {5};6oboe(opts)7 .node('!.*', function (message) {8 console.log(message);9 })10 .done(function (video) {11 console.log('done', video);12 });13{ id: '8dQl2QcKl1E',14 status: 'pending' }15{ id: '8dQl2QcKl1E',16 status: 'processing' }17{ id: '8dQl2QcKl1E',18 status: 'processing' }19{ id: '8dQl2QcKl1E',20 status: 'processing' }21{ id: '8dQl2QcKl1E',22 status: 'processing' }23{ id: '8dQl2QcKl1E',24 status: 'processing' }25{ id: '8dQl2QcKl1E',26 status: 'processing' }27{ id: '8dQl2QcKl1E',28 status: 'processing' }29{ id
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!!