How to use server.close method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

eventsource_test.js

Source:eventsource_test.js Github

copy

Full Screen

...58 server.on('request', writeEvents(["id: 1\ndata: €豆腐\n\n"]));59 var es = new EventSource(server.url);60 es.onmessage = function (m) {61 assert.equal("€豆腐", m.data);62 server.close(done);63 };64 });65 });66 it('parses empty lines with multibyte characters', function (done) {67 createServer(function (err, server) {68 if (err) return done(err);69 server.on('request', writeEvents(["\n\n\n\nid: 1\ndata: 我現在都看實況不玩遊戲\n\n"]));70 var es = new EventSource(server.url);71 es.onmessage = function (m) {72 assert.equal("我現在都看實況不玩遊戲", m.data);73 server.close(done);74 };75 });76 });77 it('parses one one-line message in one chunk', function (done) {78 createServer(function (err, server) {79 if (err) return done(err);80 server.on('request', writeEvents(["data: Hello\n\n"]));81 var es = new EventSource(server.url);82 es.onmessage = function (m) {83 assert.equal("Hello", m.data);84 server.close(done);85 };86 });87 });88 it('parses one one-line message in two chunks', function (done) {89 createServer(function (err, server) {90 if (err) return done(err);91 server.on('request', writeEvents(["data: Hel", "lo\n\n"]));92 var es = new EventSource(server.url);93 es.onmessage = function (m) {94 assert.equal("Hello", m.data);95 server.close(done);96 };97 });98 });99 it('parses two one-line messages in one chunk', function (done) {100 createServer(function (err, server) {101 if (err) return done(err);102 server.on('request', writeEvents(["data: Hello\n\n", "data: World\n\n"]));103 var es = new EventSource(server.url);104 es.onmessage = first;105 function first(m) {106 assert.equal("Hello", m.data);107 es.onmessage = second;108 }109 function second(m) {110 assert.equal("World", m.data);111 server.close(done);112 }113 });114 });115 it('parses one two-line message in one chunk', function (done) {116 createServer(function (err, server) {117 if (err) return done(err);118 server.on('request', writeEvents(["data: Hello\ndata:World\n\n"]));119 var es = new EventSource(server.url);120 es.onmessage = function (m) {121 assert.equal("Hello\nWorld", m.data);122 server.close(done);123 };124 });125 });126 it('parses really chopped up unicode data', function (done) {127 createServer(function (err, server) {128 if (err) return done(err);129 var chopped = "data: Aslak\n\ndata: Hellesøy\n\n".split("");130 server.on('request', writeEvents(chopped));131 var es = new EventSource(server.url);132 es.onmessage = first;133 function first(m) {134 assert.equal("Aslak", m.data);135 es.onmessage = second;136 }137 function second(m) {138 assert.equal("Hellesøy", m.data);139 server.close(done);140 }141 });142 });143 it('accepts CRLF as separator', function (done) {144 createServer(function (err, server) {145 if (err) return done(err);146 var chopped = "data: Aslak\r\n\r\ndata: Hellesøy\r\n\r\n".split("");147 server.on('request', writeEvents(chopped));148 var es = new EventSource(server.url);149 es.onmessage = first;150 function first(m) {151 assert.equal("Aslak", m.data);152 es.onmessage = second;153 }154 function second(m) {155 assert.equal("Hellesøy", m.data);156 server.close(done);157 }158 });159 });160 it('accepts CR as separator', function (done) {161 createServer(function (err, server) {162 if (err) return done(err);163 var chopped = "data: Aslak\r\rdata: Hellesøy\r\r".split("");164 server.on('request', writeEvents(chopped));165 var es = new EventSource(server.url);166 es.onmessage = first;167 function first(m) {168 assert.equal("Aslak", m.data);169 es.onmessage = second;170 }171 function second(m) {172 assert.equal("Hellesøy", m.data);173 server.close(done);174 }175 });176 });177 it('delivers message with explicit event', function (done) {178 createServer(function (err, server) {179 if (err) return done(err);180 server.on('request', writeEvents(["event: greeting\ndata: Hello\n\n"]));181 var es = new EventSource(server.url);182 es.addEventListener('greeting', function (m) {183 assert.equal("Hello", m.data);184 server.close(done);185 });186 });187 });188 it('ignores comments', function (done) {189 createServer(function (err, server) {190 if (err) return done(err);191 server.on('request', writeEvents(["data: Hello\n\n:nothing to see here\n\ndata: World\n\n"]));192 var es = new EventSource(server.url);193 es.onmessage = first;194 function first(m) {195 assert.equal("Hello", m.data);196 es.onmessage = second;197 }198 function second(m) {199 assert.equal("World", m.data);200 server.close(done);201 }202 });203 });204 it('ignores empty comments', function (done) {205 createServer(function (err, server) {206 if (err) return done(err);207 server.on('request', writeEvents(["data: Hello\n\n:\n\ndata: World\n\n"]));208 var es = new EventSource(server.url);209 es.onmessage = first;210 function first(m) {211 assert.equal("Hello", m.data);212 es.onmessage = second;213 }214 function second(m) {215 assert.equal("World", m.data);216 server.close(done);217 }218 });219 });220 it('does not ignore multilines strings', function (done) {221 createServer(function (err, server) {222 if (err) return done(err);223 server.on('request', writeEvents(["data: line one\ndata:\ndata: line two\n\n"]));224 var es = new EventSource(server.url);225 es.onmessage = function (m) {226 assert.equal('line one\n\nline two', m.data);227 server.close(done);228 };229 });230 });231 it('does not ignore multilines strings even in data beginning', function (done) {232 createServer(function (err, server) {233 if (err) return done(err);234 server.on('request', writeEvents(["data:\ndata:line one\ndata: line two\n\n"]));235 var es = new EventSource(server.url);236 es.onmessage = function (m) {237 assert.equal('\nline one\nline two', m.data);238 server.close(done);239 };240 });241 });242 it('causes entire event to be ignored for empty event field', function (done) {243 createServer(function (err, server) {244 if (err) return done(err);245 server.on('request', writeEvents(["event:\n\ndata: Hello\n\n"]));246 var es = new EventSource(server.url);247 var originalEmit = es.emit;248 es.emit = function (event) {249 assert.ok(event === 'message' || event === 'newListener');250 return originalEmit.apply(this, arguments);251 };252 es.onmessage = function (m) {253 assert.equal('Hello', m.data);254 server.close(done);255 };256 });257 });258 it('parses relatively huge messages efficiently', function (done) {259 this.timeout(1000);260 createServer(function (err, server) {261 if (err) return done(err);262 var longMessage = "data: " + new Array(100000).join('a') + "\n\n";263 server.on('request', writeEvents([longMessage]));264 var es = new EventSource(server.url);265 es.onmessage = function () {266 server.close(done);267 };268 });269 });270});271describe('HTTP Request', function () {272 it('passes cache-control: no-cache to server', function (done) {273 createServer(function (err, server) {274 if (err) return done(err);275 server.on('request', function (req) {276 assert.equal('no-cache', req.headers['cache-control']);277 server.close(done);278 });279 new EventSource(server.url);280 });281 });282 it('sets request headers', function (done) {283 var server = createServer(function (err, server) {284 if (err) return done(err);285 server.on('request', function (req) {286 assert.equal(req.headers['user-agent'], 'test');287 assert.equal(req.headers['cookie'], 'test=test');288 assert.equal(req.headers['last-event-id'], '99');289 server.close(done);290 });291 var headers = {292 'User-Agent': 'test',293 'Cookie': 'test=test',294 'Last-Event-ID': '99'295 };296 new EventSource(server.url, {headers: headers});297 });298 });299 it("does not set request headers that don't have a value", function (done) {300 var server = createServer(function (err, server) {301 if (err) return done(err);302 server.on('request', function (req) {303 assert.equal(req.headers['user-agent'], 'test');304 assert.equal(req.headers['cookie'], 'test=test');305 assert.equal(req.headers['last-event-id'], '99');306 assert.equal(req.headers['X-Something'], undefined);307 server.close(done);308 });309 var headers = {310 'User-Agent': 'test',311 'Cookie': 'test=test',312 'Last-Event-ID': '99',313 'X-Something': null314 };315 assert.doesNotThrow(316 function() {317 new EventSource(server.url, {headers: headers});318 }319 );320 });321 });322 [301, 307].forEach(function (status) {323 it('follows http ' + status + ' redirect', function (done) {324 var redirectSuffix = '/foobar';325 var clientRequestedRedirectUrl = false;326 createServer(function (err, server) {327 if(err) return done(err);328 server.on('request', function (req, res) {329 if (req.url === '/') {330 res.writeHead(status, {331 'Connection': 'Close',332 'Location': server.url + redirectSuffix333 });334 res.end();335 } else if (req.url === redirectSuffix) {336 clientRequestedRedirectUrl = true;337 res.writeHead(200, {'Content-Type': 'text/event-stream'});338 res.end();339 }340 });341 var es = new EventSource(server.url);342 es.onopen = function () {343 assert.ok(clientRequestedRedirectUrl);344 assert.equal(server.url + redirectSuffix, es.url);345 server.close(done);346 };347 });348 });349 it('causes error event when response is ' + status + ' with missing location', function (done) {350 var redirectSuffix = '/foobar';351 var clientRequestedRedirectUrl = false;352 createServer(function (err, server) {353 if(err) return done(err);354 server.on('request', function (req, res) {355 res.writeHead(status, {356 'Connection': 'Close'357 });358 res.end();359 });360 var es = new EventSource(server.url);361 es.onerror = function (err) {362 assert.equal(err.status, status);363 server.close(done);364 };365 });366 });367 });368 [401, 403].forEach(function (status) {369 it('causes error event when response status is ' + status, function (done) {370 createServer(function (err, server) {371 if(err) return done(err);372 server.on('request', function (req, res) {373 res.writeHead(status, {'Content-Type': 'text/html'});374 res.end();375 });376 var es = new EventSource(server.url);377 es.onerror = function (err) {378 assert.equal(err.status, status);379 server.close(done);380 };381 });382 });383 });384});385describe('HTTPS Support', function () {386 it('uses https for https urls', function (done) {387 createHttpsServer(function (err, server) {388 if(err) return done(err);389 server.on('request', writeEvents(["data: hello\n\n"]));390 var es = new EventSource(server.url, {rejectUnauthorized: false});391 es.onmessage = function (m) {392 assert.equal("hello", m.data);393 server.close(done);394 }395 });396 });397});398describe('Reconnection', function () {399 it('is attempted when server is down', function (done) {400 var es = new EventSource('http://localhost:' + _port);401 es.reconnectInterval = 0;402 es.onerror = function () {403 es.onerror = null;404 createServer(function (err, server) {405 if(err) return done(err);406 server.on('request', writeEvents(["data: hello\n\n"]));407 es.onmessage = function (m) {408 assert.equal("hello", m.data);409 server.close(done);410 }411 });412 };413 });414 it('is attempted when server goes down after connection', function (done) {415 createServer(function (err, server) {416 if(err) return done(err);417 server.on('request', writeEvents(["data: hello\n\n"]));418 var es = new EventSource(server.url);419 es.reconnectInterval = 0;420 es.onmessage = function (m) {421 assert.equal("hello", m.data);422 server.close(function (err) {423 if(err) return done(err);424 var port = u.parse(es.url).port;425 configureServer(http.createServer(), 'http', port, function (err, server2) {426 if(err) return done(err);427 server2.on('request', writeEvents(["data: world\n\n"]));428 es.onmessage = function (m) {429 assert.equal("world", m.data);430 server2.close(done);431 };432 });433 });434 };435 });436 });437 it('is stopped when server goes down and eventsource is being closed', function (done) {438 createServer(function (err, server) {439 if(err) return done(err);440 server.on('request', writeEvents(["data: hello\n\n"]));441 var es = new EventSource(server.url);442 es.reconnectInterval = 0;443 es.onmessage = function (m) {444 assert.equal("hello", m.data);445 server.close(function (err) {446 if(err) return done(err);447 // The server has closed down. es.onerror should now get called,448 // because es's remote connection was dropped.449 });450 };451 es.onerror = function () {452 // We received an error because the remote connection was closed.453 // We close es, so we do not want es to reconnect.454 es.close();455 var port = u.parse(es.url).port;456 configureServer(http.createServer(), 'http', port, function (err, server2) {457 if(err) return done(err);458 server2.on('request', writeEvents(["data: world\n\n"]));459 es.onmessage = function (m) {460 return done(new Error("Unexpected message: " + m.data));461 };462 setTimeout(function () {463 // We have not received any message within 100ms, we can464 // presume this works correctly.465 server2.close(done);466 }, 100);467 });468 };469 });470 });471 it('is not attempted when server responds with HTTP 204', function (done) {472 createServer(function (err, server) {473 if(err) return done(err);474 server.on('request', function (req, res) {475 res.writeHead(204);476 res.end();477 });478 var es = new EventSource(server.url);479 es.reconnectInterval = 0;480 es.onerror = function (e) {481 assert.equal(e.status, 204);482 server.close(function (err) {483 if(err) return done(err);484 var port = u.parse(es.url).port;485 configureServer(http.createServer(), 'http', port, function (err, server2) {486 if(err) return done(err);487 // this will be verified by the readyState488 // going from CONNECTING to CLOSED,489 // along with the tests verifying that the490 // state is CONNECTING when a server closes.491 // it's next to impossible to write a fail-safe492 // test for this, though.493 var ival = setInterval(function () {494 if (es.readyState == EventSource.CLOSED) {495 clearInterval(ival);496 server2.close(done);497 }498 }, 5);499 });500 });501 };502 });503 });504 it('sends Last-Event-ID http header when it has previously been passed in an event from the server', function (done) {505 createServer(function (err, server) {506 if(err) return done(err);507 server.on('request', writeEvents(['id: 10\ndata: Hello\n\n']));508 var es = new EventSource(server.url);509 es.reconnectInterval = 0;510 es.onmessage = function () {511 server.close(function (err) {512 if(err) return done(err);513 var port = u.parse(es.url).port;514 configureServer(http.createServer(), 'http', port, function (err, server2) {515 server2.on('request', function (req, res) {516 assert.equal('10', req.headers['last-event-id']);517 server2.close(done);518 });519 });520 });521 };522 });523 });524 it('sends correct Last-Event-ID http header when an initial Last-Event-ID header was specified in the constructor', function (done) {525 createServer(function (err, server) {526 if(err) return done(err);527 server.on('request', function (req, res) {528 assert.equal('9', req.headers['last-event-id']);529 server.close(done);530 });531 new EventSource(server.url, {headers: {'Last-Event-ID': '9'}});532 });533 });534 it('does not send Last-Event-ID http header when it has not been previously sent by the server', function (done) {535 createServer(function (err, server) {536 if(err) return done(err);537 server.on('request', writeEvents(['data: Hello\n\n']));538 var es = new EventSource(server.url);539 es.reconnectInterval = 0;540 es.onmessage = function () {541 server.close(function (err) {542 if(err) return done(err);543 var port = u.parse(es.url).port;544 configureServer(http.createServer(), 'http', port, function (err, server2) {545 server2.on('request', function (req, res) {546 assert.equal(undefined, req.headers['last-event-id']);547 server2.close(done);548 });549 });550 });551 };552 });553 });554});555describe('readyState', function () {556 it('has CONNECTING constant', function () {557 assert.equal(0, EventSource.CONNECTING);558 });559 it('has OPEN constant', function () {560 assert.equal(1, EventSource.OPEN);561 });562 it('has CLOSED constant', function () {563 assert.equal(2, EventSource.CLOSED);564 });565 it('is CONNECTING before connection has been established', function (done) {566 var es = new EventSource('http://localhost:' + _port);567 assert.equal(EventSource.CONNECTING, es.readyState);568 es.onerror = function () {569 es.close();570 done();571 }572 });573 it('is CONNECTING when server has closed the connection', function (done) {574 createServer(function (err, server) {575 if(err) return done(err);576 server.on('request', writeEvents([]));577 var es = new EventSource(server.url);578 es.reconnectInterval = 0;579 es.onopen = function (m) {580 server.close(function (err) {581 if(err) return done(err);582 es.onerror = function () {583 es.onerror = null;584 assert.equal(EventSource.CONNECTING, es.readyState);585 done();586 };587 });588 };589 });590 });591 it('is OPEN when connection has been established', function (done) {592 createServer(function (err, server) {593 if(err) return done(err);594 server.on('request', writeEvents([]));595 var es = new EventSource(server.url);596 es.onopen = function () {597 assert.equal(EventSource.OPEN, es.readyState);598 server.close(done);599 }600 });601 });602 it('is CLOSED after connection has been closed', function (done) {603 createServer(function (err, server) {604 if(err) return done(err);605 server.on('request', writeEvents([]));606 var es = new EventSource(server.url);607 es.onopen = function () {608 es.close();609 assert.equal(EventSource.CLOSED, es.readyState);610 server.close(done);611 }612 });613 });614});615describe('Properties', function () {616 it('url exposes original request url', function () {617 var url = 'http://localhost:' + _port;618 var es = new EventSource(url);619 assert.equal(url, es.url);620 });621});622describe('Events', function () {623 it('calls onopen when connection is established', function (done) {624 createServer(function (err, server) {625 if(err) return done(err);626 server.on('request', writeEvents([]));627 var es = new EventSource(server.url);628 es.onopen = function (event) {629 assert.equal(event.type, 'open');630 server.close(done);631 }632 });633 });634 it('supplies the correct origin', function (done) {635 createServer(function (err, server) {636 if(err) return done(err);637 server.on('request', writeEvents(["data: hello\n\n"]));638 var es = new EventSource(server.url);639 es.onmessage = function (event) {640 assert.equal(event.origin, server.url);641 server.close(done);642 }643 });644 });645 it('emits open event when connection is established', function (done) {646 createServer(function (err, server) {647 if(err) return done(err);648 server.on('request', writeEvents([]));649 var es = new EventSource(server.url);650 es.addEventListener('open', function (event) {651 assert.equal(event.type, 'open');652 server.close(done);653 });654 });655 });656 it('does not emit error when connection is closed by client', function (done) {657 createServer(function (err, server) {658 if(err) return done(err);659 server.on('request', writeEvents([]));660 var es = new EventSource(server.url);661 es.addEventListener('open', function () {662 es.close();663 process.nextTick(function () {664 server.close(done);665 });666 });667 es.addEventListener('error', function () {668 done(new Error('error should not be emitted'));669 });670 });671 });672 it('populates message\'s lastEventId correctly when the last event has an associated id', function (done) {673 createServer(function (err, server) {674 if(err) return done(err);675 server.on('request', writeEvents(["id: 123\ndata: hello\n\n"]));676 var es = new EventSource(server.url);677 es.onmessage = function (m) {678 assert.equal(m.lastEventId, "123");679 server.close(done);680 };681 });682 });683 it('populates message\'s lastEventId correctly when the last event doesn\'t have an associated id', function (done) {684 createServer(function (err, server) {685 if(err) return done(err);686 server.on('request', writeEvents(["id: 123\ndata: Hello\n\n", "data: World\n\n"]));687 var es = new EventSource(server.url);688 es.onmessage = first;689 function first() {690 es.onmessage = second;691 }692 function second(m) {693 assert.equal(m.data, "World");694 assert.equal(m.lastEventId, "123"); //expect to get back the previous event id695 server.close(done);696 }697 });698 });699 it('populates messages with enumerable properties so they can be inspected via console.log().', function (done) {700 createServer(function (err, server) {701 if(err) return done(err);702 server.on('request', writeEvents(["data: World\n\n"]));703 var es = new EventSource(server.url);704 es.onmessage = function (m) {705 var enumerableAttributes = Object.keys(m);706 assert.notEqual(enumerableAttributes.indexOf("data"), -1);707 assert.notEqual(enumerableAttributes.indexOf("type"), -1);708 server.close(done);709 };710 });711 });...

Full Screen

Full Screen

base.test.js

Source:base.test.js Github

copy

Full Screen

...17 })18 .then((data) => {19 t.deepEqual(data, { data: 'hello world' })20 t.end()21 server.close()22 })23 .catch((err) => {24 t.falsy(err)25 server.close()26 })27 })28})29test.cb('Should handle get request where options is the url as string', t => {30 t.plan(3)31 const server = http.createServer((req, res) => {32 t.is(req.url, '/test')33 t.is(req.method, 'GET')34 res.statusCode = 20035 res.end('{"data":"hello world"}')36 })37 server.listen(0, () => {38 const port = server.address().port39 jsonRequest.get(`http://localhost:${port}/test`)40 .then((data) => {41 t.deepEqual(data, { data: 'hello world' })42 t.end()43 server.close()44 })45 .catch((err) => {46 t.falsy(err)47 server.close()48 })49 })50})51test.cb('Should handle request where options is the url as string', t => {52 t.plan(3)53 const server = http.createServer((req, res) => {54 t.is(req.url, '/test')55 t.is(req.method, 'GET')56 res.statusCode = 20057 res.end('{"data":"hello world"}')58 })59 server.listen(0, () => {60 const port = server.address().port61 jsonRequest.request(`http://localhost:${port}/test`)62 .then((data) => {63 t.deepEqual(data, { data: 'hello world' })64 t.end()65 server.close()66 })67 .catch((err) => {68 t.falsy(err)69 server.close()70 })71 })72})73test.cb('Should handle get request with headers', t => {74 t.plan(3)75 const server = http.createServer((req, res) => {76 t.is(req.url, '/test')77 t.is(req.method, 'GET')78 res.statusCode = 20079 res.end('{"data":"hello world"}')80 })81 server.listen(0, () => {82 const port = server.address().port83 jsonRequest.get({84 url: `http://localhost:${port}/test`,85 headers: {86 header: 'value'87 }88 })89 .then((data) => {90 t.deepEqual(data, { data: 'hello world' })91 t.end()92 server.close()93 })94 .catch((err) => {95 t.falsy(err)96 server.close()97 })98 })99})100test.cb('Should use custom json parser', t => {101 t.plan(3)102 const server = http.createServer((req, res) => {103 t.is(req.url, '/test')104 t.is(req.method, 'GET')105 res.statusCode = 200106 res.end('{"data":"hello world"}')107 })108 server.listen(0, () => {109 const port = server.address().port110 jsonRequest.get({111 url: `http://localhost:${port}/test`,112 parser: () => {113 return { hello: 'world' }114 }115 })116 .then((data) => {117 t.deepEqual(data, { hello: 'world' })118 t.end()119 server.close()120 })121 .catch((err) => {122 t.falsy(err)123 server.close()124 })125 })126})127test.cb('Should set accept header', t => {128 t.plan(1)129 const server = http.createServer((req, res) => {130 t.is(req.headers.accept, 'application/json')131 res.statusCode = 200132 res.end('{"data":"hello world"}')133 })134 server.listen(0, () => {135 const port = server.address().port136 jsonRequest.get({137 url: `http://localhost:${port}/test`138 })139 .then((data) => {140 t.end()141 server.close()142 })143 .catch((err) => {144 t.falsy(err)145 server.close()146 })147 })148})149test.cb('Should set read timeout', t => {150 t.plan(2)151 const server = http.createServer((req, res) => {152 setTimeout(() => {153 res.statusCode = 200154 res.end('{"data":"hello world"}')155 }, 250)156 })157 server.listen(0, () => {158 const port = server.address().port159 jsonRequest.get({160 url: `http://localhost:${port}/test`,161 readTimeout: 100162 })163 .then((data) => {164 server.close()165 })166 .catch((err) => {167 t.truthy(err)168 t.is(err.code, 'ERR_READ_TIMEOUT')169 t.end()170 server.close()171 })172 })173})174test.cb('Should reject with 500 error', t => {175 t.plan(5)176 const server = http.createServer((req, res) => {177 t.is(req.url, '/test')178 res.statusCode = 500179 res.end('{"data":"hello world"}')180 })181 server.listen(0, () => {182 const port = server.address().port183 jsonRequest.get({184 url: `http://localhost:${port}/test`185 })186 .then(() => server.close())187 .catch((err) => {188 t.truthy(err)189 t.is(err.statusCode, 500)190 t.is(err.message, 'Internal Server Error')191 t.is(err.code, 'INTERNAL_SERVER_ERROR')192 t.end()193 server.close()194 })195 })196})197test.cb('Should reject with 401 error', t => {198 t.plan(5)199 const server = http.createServer((req, res) => {200 t.is(req.url, '/test')201 res.statusCode = 401202 res.end('{"data":"hello world"}')203 })204 server.listen(0, () => {205 const port = server.address().port206 jsonRequest.get({207 url: `http://localhost:${port}/test`208 })209 .then(() => server.close())210 .catch((err) => {211 t.truthy(err)212 t.is(err.statusCode, 401)213 t.is(err.message, 'Unauthorized')214 t.is(err.code, 'UNAUTHORIZED')215 t.end()216 server.close()217 })218 })219})220test.cb('Should pass data with error', t => {221 t.plan(6)222 const server = http.createServer((req, res) => {223 t.is(req.url, '/test')224 res.statusCode = 500225 res.end('{"data":"hello world"}')226 })227 server.listen(0, () => {228 const port = server.address().port229 jsonRequest.get({230 url: `http://localhost:${port}/test`231 })232 .then(() => server.close())233 .catch((err) => {234 t.truthy(err)235 t.is(err.statusCode, 500)236 t.is(err.message, 'Internal Server Error')237 t.is(err.code, 'INTERNAL_SERVER_ERROR')238 t.is(err.data.toString(), '{"data":"hello world"}')239 t.end()240 server.close()241 })242 })243})244test.cb('Should handle post request', t => {245 t.plan(3)246 const server = http.createServer((req, res) => {247 t.is(req.url, '/test')248 t.is(req.method, 'POST')249 res.statusCode = 200250 res.end('{"data":"hello world"}')251 })252 server.listen(0, () => {253 const port = server.address().port254 jsonRequest.post({255 url: `http://localhost:${port}/test`256 })257 .then((data) => {258 t.deepEqual(data, { data: 'hello world' })259 t.end()260 server.close()261 })262 .catch((err) => {263 t.falsy(err)264 server.close()265 })266 })267})268test.cb('Should handle put request', t => {269 t.plan(3)270 const server = http.createServer((req, res) => {271 t.is(req.url, '/test')272 t.is(req.method, 'PUT')273 res.statusCode = 200274 res.end('{"data":"hello world"}')275 })276 server.listen(0, () => {277 const port = server.address().port278 jsonRequest.put({279 url: `http://localhost:${port}/test`280 })281 .then((data) => {282 t.deepEqual(data, { data: 'hello world' })283 t.end()284 server.close()285 })286 .catch((err) => {287 t.falsy(err)288 server.close()289 })290 })291})292test.cb('Should handle delete request', t => {293 t.plan(3)294 const server = http.createServer((req, res) => {295 t.is(req.url, '/test')296 t.is(req.method, 'DELETE')297 res.statusCode = 200298 res.end('{"data":"hello world"}')299 })300 server.listen(0, () => {301 const port = server.address().port302 jsonRequest.delete({303 url: `http://localhost:${port}/test`304 })305 .then((data) => {306 t.deepEqual(data, { data: 'hello world' })307 t.end()308 server.close()309 })310 .catch((err) => {311 t.falsy(err)312 server.close()313 })314 })315})316test.cb('Should handle head request', t => {317 t.plan(3)318 const server = http.createServer((req, res) => {319 t.is(req.url, '/test')320 t.is(req.method, 'HEAD')321 res.statusCode = 200322 res.end('{"data":"hello world"}')323 })324 server.listen(0, () => {325 const port = server.address().port326 jsonRequest.head({327 url: `http://localhost:${port}/test`328 })329 .then((data) => {330 t.deepEqual(data, null)331 t.end()332 server.close()333 })334 .catch((err) => {335 t.falsy(err)336 server.close()337 })338 })339})340test.cb('Should handle patch request', t => {341 t.plan(3)342 const server = http.createServer((req, res) => {343 t.is(req.url, '/test')344 t.is(req.method, 'PATCH')345 res.statusCode = 200346 res.end('{"data":"hello world"}')347 })348 server.listen(0, () => {349 const port = server.address().port350 jsonRequest.patch({351 url: `http://localhost:${port}/test`352 })353 .then((data) => {354 t.deepEqual(data, { data: 'hello world' })355 t.end()356 server.close()357 })358 .catch((err) => {359 t.falsy(err)360 server.close()361 })362 })363})364test.cb('Should handle post request where options is the url as string', t => {365 t.plan(3)366 const server = http.createServer((req, res) => {367 t.is(req.url, '/test')368 t.is(req.method, 'POST')369 res.statusCode = 200370 res.end('{"data":"hello world"}')371 })372 server.listen(0, () => {373 const port = server.address().port374 jsonRequest.post(`http://localhost:${port}/test`)375 .then((data) => {376 t.deepEqual(data, { data: 'hello world' })377 t.end()378 server.close()379 })380 .catch((err) => {381 t.falsy(err)382 server.close()383 })384 })385})386test.cb('Should not follow too many redirects', t => {387 t.plan(5)388 const server = http.createServer((req, res) => {389 t.is(req.url, '/test')390 t.is(req.method, 'GET')391 res.statusCode = 302392 res.setHeader('Location', '/test')393 res.end()394 })395 server.listen(0, () => {396 const port = server.address().port397 jsonRequest.get({398 url: `http://localhost:${port}/test`,399 maxRedirects: 1400 })401 .then((data) => {402 server.close()403 })404 .catch((err) => {405 t.truthy(err)406 t.end()407 server.close()408 })409 })410})411test.cb('Should handle parse errors correctly', t => {412 t.plan(3)413 const server = http.createServer((req, res) => {414 t.is(req.url, '/test')415 t.is(req.method, 'GET')416 res.statusCode = 200417 res.end('{data":hello world"}')418 })419 server.listen(0, () => {420 const port = server.address().port421 jsonRequest.get({422 url: `http://localhost:${port}/test`423 })424 .catch((err) => {425 t.truthy(err)426 t.end()427 server.close()428 })429 })...

Full Screen

Full Screen

framing-socket-ftest.js

Source:framing-socket-ftest.js Github

copy

Full Screen

...23 function on_server_close() {24 t.end();25 }26 function on_done() {27 server.close(on_server_close);28 }29 function on_server_listen() {30 (function next(iteration) {31 if (iteration >= 10) {32 t.ok(true, 'Client can perform multiple connect/disconnect cycles');33 t.ok((client.socket === null), 'Client socket is nulled');34 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');35 t.end();36 on_done();37 return;38 }39 client.connect(host, port, function on_client_close() {40 client.close();41 next(iteration + 1);42 });43 })(0);44 }45 server.listen(port, on_server_listen);46});47test('Client connect -> client write full frame -> client disconnect', function(t) {48 var server = create_server(),49 client = create_client(),50 rpc_id = 1;51 function on_server_close() {52 t.ok((client.socket === null), 'Client socket is nulled');53 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');54 t.end();55 }56 function on_client_write(err, frame) {57 // no op58 }59 function on_client_connect(err) {60 if (err) {61 errback(t, err, server);62 return;63 }64 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);65 client.close();66 server.close(on_server_close);67 }68 function on_server_listen() {69 client.connect(host, port, on_client_connect);70 }71 server.listen(port, on_server_listen);72});73test('Client connect -> client write full frame -> server disconnect', function(t) {74 var server = create_server(),75 client = create_client(),76 rpc_id = 1;77 function on_disconnected() {78 t.ok((client.socket === null), 'Client socket is nulled');79 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');80 t.end();81 }82 function on_server_close() {83 // no op84 }85 function on_client_write(err, frame) {86 // no op87 }88 function on_client_connect(err) {89 if (err) {90 errback(t, err, server);91 return;92 }93 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);94 server.close(on_server_close);95 }96 function on_server_listen() {97 client.on('disconnected', on_disconnected);98 client.connect(host, port, on_client_connect);99 }100 server.listen(port, on_server_listen);101});102test('Client connect -> client write full frame -> server stuck -> client timeout', function(t) {103 var server = create_server({104 stuck_before_response: true105 }),106 client = create_client({107 timeout_ms: 1000108 }),109 rpc_id = 1;110 function on_server_close() {111 }112 function on_timeout() {113 client.close();114 server.close(on_server_close);115 t.ok((client.socket === null), 'Client socket is nulled');116 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');117 t.end();118 }119 function on_client_write(err, frame) {120 t.ok(false, 'Result should not have made it back to client before timeout');121 }122 function on_client_connect(err) {123 if (err) {124 errback(t, err, server);125 return;126 }127 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);128 }129 function on_server_listen() {130 client.on('timeout', on_timeout);131 client.connect(host, port, on_client_connect);132 }133 server.listen(port, on_server_listen);134});135test('Client connect -> client write full frame -> server response partial frame -> server stuck -> client timeout', function(t) {136 var server = create_server({137 stuck_partial_response: true138 }),139 client = create_client({140 timeout_ms: 1000141 }),142 rpc_id = 1;143 function on_server_close() {144 }145 function on_timeout() {146 client.close();147 server.close(on_server_close);148 t.ok((client.socket === null), 'Client socket is nulled');149 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');150 t.end();151 }152 function on_client_write(err, frame) {153 t.ok(false, 'Result should not have made it back to client before timeout');154 }155 function on_client_connect(err) {156 if (err) {157 errback(t, err, server);158 return;159 }160 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);161 }162 function on_server_listen() {163 client.on('timeout', on_timeout);164 client.connect(host, port, on_client_connect);165 }166 server.listen(port, on_server_listen);167});168test('Client connect -> client write full frame -> server response partial frame -> server disconnect', function(t) {169 var server = create_server({170 stuck_partial_response: true,171 stuck_action: on_stuck172 }),173 client = create_client(),174 rpc_id = 1;175 function on_stuck(connection) {176 return this.close();177 }178 function on_disconnected() {179 t.ok((client.socket === null), 'Client socket is nulled');180 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');181 t.end();182 }183 function on_client_write(err, frame) {184 t.ok(false, 'Result should not have made it back to client before timeout');185 }186 function on_client_connect(err) {187 if (err) {188 errback(t, err, server);189 return;190 }191 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);192 }193 function on_server_listen() {194 client.on('disconnected', on_disconnected);195 client.connect(host, port, on_client_connect);196 }197 server.listen(port, on_server_listen);198});199test('Client connect -> client write full frame -> server response partial frame -> server timeout', function(t) {200 var server = create_server({201 timeout_ms: 1000, // faster than the stuck_ms202 stuck_partial_response: true203 }),204 client = create_client(),205 rpc_id = 1;206 function on_server_close() {207 }208 function on_disconnected() {209 t.ok((client.socket === null), 'Client socket is nulled');210 t.equal(Object.keys(client.pending_callbacks).length, 0, 'No pending callbacks for this client');211 t.end();212 server.close(on_server_close);213 }214 function on_client_write(err, frame) {215 t.ok(false, 'Result should not have made it back to client before timeout');216 }217 function on_client_connect(err) {218 if (err) {219 errback(t, err, server);220 return;221 }222 client.write(rpc_id, new Buffer([0x01, 0x02, 0x03]), on_client_write);223 }224 function on_server_listen() {225 client.on('disconnected', on_disconnected);226 client.connect(host, port, on_client_connect);227 }228 server.listen(port, on_server_listen);229});230test('Client connect -> (client write full frame -> server response full frame) x 10 -> client disconnect', function(t) {231 var client = create_client(),232 server = create_server(),233 deferred = when.defer(),234 rpc_id = 1,235 buf = new Buffer([0x01, 0x02, 0x03]);236 function on_server_close() {237 }238 function on_done() {239 server.close(on_server_close);240 }241 function on_client_connect(err) {242 if (err) {243 errback(t, err, server);244 return;245 }246 (function next(iteration) {247 if (iteration >= 10) {248 t.ok(true, 'Client can perform multiple write/receive cycles');249 t.end();250 on_done();251 return;252 }253 client.write(rpc_id, buf, function on_client_write(err, frame) {254 if (err) {255 errback(t, err, server);256 return;257 }258 next(iteration + 1);259 });260 })(0);261 }262 function on_server_listen() {263 client.connect(host, port, on_client_connect);264 }265 server.listen(port, on_server_listen);266});267function errback(t, err, server) {268 t.ok(false, 'Error caught: ' + util.inspect(err));269 t.end();270 server.close();271}272function create_client(options) {273 return new FramingSocket(options);274}275function create_server(options) {276 return new TestSocketServer(options);...

Full Screen

Full Screen

socket-io.test.js

Source:socket-io.test.js Github

copy

Full Screen

...6 const socket = io('foobar');7 server.on('connection', () => {8 t.true(true);9 socket.disconnect();10 server.close();11 t.end();12 });13});14test.cb('client triggers the server connect event', t => {15 const server = new Server('foobar');16 const socket = io('foobar');17 server.on('connect', () => {18 t.true(true);19 socket.disconnect();20 server.close();21 t.end();22 });23});24test.cb('server triggers the client connect event', t => {25 const server = new Server('foobar');26 const socket = io('foobar');27 socket.on('connect', () => {28 t.true(true);29 socket.disconnect();30 server.close();31 t.end();32 });33});34test.cb('no connection triggers the client error event', t => {35 const socket = io('foobar');36 socket.on('error', () => {37 t.true(true);38 socket.disconnect();39 t.end();40 });41});42test.cb('client and server receive an event', t => {43 const server = new Server('foobar');44 server.on('client-event', data => {45 server.emit('server-response', data);46 });47 const socket = io('foobar');48 socket.on('server-response', data => {49 t.is('payload', data);50 socket.disconnect();51 server.close();52 t.end();53 });54 socket.on('connect', () => {55 socket.emit('client-event', 'payload');56 });57});58test.cb('Server closing triggers the client disconnect event', t => {59 const server = new Server('foobar');60 server.on('connect', () => {61 server.close();62 });63 const socket = io('foobar');64 socket.on('disconnect', () => {65 t.true(true);66 socket.disconnect();67 t.end();68 });69});70test.cb('Server receives disconnect when socket is closed', t => {71 const server = new Server('foobar');72 server.on('disconnect', () => {73 t.true(true);74 server.close();75 t.end();76 });77 const socket = io('foobar');78 socket.on('connect', () => {79 socket.disconnect();80 });81});82test.cb('Client can submit an event without a payload', t => {83 const server = new Server('foobar');84 server.on('client-event', () => {85 t.true(true);86 server.close();87 t.end();88 });89 const socket = io('foobar');90 socket.on('connect', () => {91 socket.emit('client-event');92 });93});94test.cb('Client also has the send method available', t => {95 const server = new Server('foobar');96 server.on('message', data => {97 t.is(data, 'hullo!');98 server.close();99 t.end();100 });101 const socket = io('foobar');102 socket.on('connect', () => {103 socket.send('hullo!');104 });105});106test.cb('a socket can join and leave a room', t => {107 const server = new Server('ws://roomy');108 const socket = io('ws://roomy');109 socket.on('good-response', () => {110 t.true(true);111 server.close();112 t.end();113 });114 socket.on('connect', () => {115 socket.join('room');116 server.to('room').emit('good-response');117 });118});119test.cb('a socket can emit to a room', t => {120 const server = new Server('ws://roomy');121 const socketFoo = io('ws://roomy');122 const socketBar = io('ws://roomy');123 socketFoo.on('connect', () => {124 socketFoo.join('room');125 });126 socketFoo.on('room-talk', () => {127 t.true(true);128 server.close();129 t.end();130 });131 socketBar.on('connect', () => {132 socketBar.join('room');133 socketBar.to('room').emit('room-talk');134 });135});136test.cb('Client can emit with multiple arguments', t => {137 const server = new Server('foobar');138 server.on('client-event', (...data) => {139 t.is(data.length, 3);140 t.is(data[0], 'foo');141 t.is(data[1], 'bar');142 t.is(data[2], 'baz');143 server.close();144 t.end();145 });146 const socket = io('foobar');147 socket.on('connect', () => {148 socket.emit('client-event', 'foo', 'bar', 'baz');149 });150});151test.cb('Server can emit with multiple arguments', t => {152 const server = new Server('foobar');153 server.on('connection', () => {154 server.emit('server-emit', 'foo', 'bar');155 });156 const socket = io('foobar');157 socket.on('server-emit', (...data) => {158 t.is(data.length, 2);159 t.is(data[0], 'foo');160 t.is(data[1], 'bar');161 server.close();162 t.end();163 });164});165test.cb('Server can emit to multiple rooms', t => {166 const server = new Server('ws://chat');167 const socket1 = io('ws://chat');168 const socket2 = io('ws://chat');169 let connectedCount = 0;170 const checkConnected = () => {171 connectedCount += 1;172 if (connectedCount === 2) {173 server.to('room1').to('room2').emit('good-response');174 }175 };176 let goodResponses = 0;177 const checkGoodResponses = socketId => {178 goodResponses += 1;179 if (goodResponses === 2) {180 t.true(true);181 server.close();182 t.end();183 }184 };185 socket1.on('good-response', checkGoodResponses.bind(null, 1));186 socket2.on('good-response', checkGoodResponses.bind(null, 2));187 socket1.on('connect', () => {188 socket1.join('room1');189 checkConnected();190 });191 socket2.on('connect', () => {192 socket2.join('room2');193 checkConnected();194 });195});

Full Screen

Full Screen

test_engine.io.js

Source:test_engine.io.js Github

copy

Full Screen

...40console.log(engine.protocol);41httpServer = http.createServer();42httpServer.listen(8000);43server = engine(httpServer);44server.close();45server = engine(httpServer, serverOptions);46server.close();47httpServer.close();48server = engine.listen(8000);49server.httpServer!.close();50server.close();51server = engine.listen(8000, serverOptions);52server.httpServer!.close();53server.close();54server = engine.listen(8000, serverOptions, () => {});55server.httpServer!.close();56server.close();57httpServer = http.createServer();58httpServer.listen(8000);59server = engine.attach(httpServer);60server.close();61httpServer.close();62httpServer = http.createServer();63httpServer.listen(8000);64server = engine.attach(httpServer, serverOptions);65server.close();66httpServer.close();67httpServer = http.createServer();68httpServer.listen(8000);69server = engine.attach(httpServer, attachOptions);70server.close();71httpServer.close();72httpServer = http.createServer();73httpServer.listen(8000);74server = engine.attach(httpServer, serverAttachOptions);75server.close();76httpServer.close();77server = new engine.Server();78server.close();79server = new engine.Server();80server.close();81httpServer = http.createServer();82httpServer.listen(8000);83server = new engine.Server(serverOptions);84server.attach(httpServer);85server.attach(httpServer, attachOptions);86server.close();87httpServer.close();88server.generateId = (req) => Math.floor(Math.random() * 100000).toString();89httpServer = http.createServer();90httpServer.listen(8000);91server = new engine.Server(serverOptions);92httpServer.on('upgrade', (req, socket, head) => {93 server.handleUpgrade(req, socket, head);94});95httpServer.on('request', (req, res) => {96 server.handleRequest(req, res);97});98console.log(server.clients);99console.log(server.clientsCount);100server.on('connection', (socket) => {101 console.log(socket.id);102 console.log(socket.server.getMaxListeners());103 console.log(socket.request.headers);104 console.log(socket.upgraded);105 console.log(socket.readyState);106 console.log(server.clients[socket.id].id);107 socket.on('close', (reason, description) => {108 console.log('CLOSE', reason, description && description.message);109 });110 socket.on('message', (message) => {111 console.log('MESSAGE', message);112 });113 socket.on('error', err => {114 console.log('ERROR', err);115 });116 socket.on('flush', buffer => {117 console.log('FLUSH', buffer);118 });119 socket.on('drain', () => {120 console.log('DRAIN');121 });122 socket.on('packet', packet => {123 console.log('PACKET', packet.type, packet.data);124 });125 socket.on('packetCreate', packet => {126 console.log('PACKETCREATE', packet.type, packet.data);127 });128 socket.send('utf 8 string', {compress: false}, () => {129 console.log("SENDCALLBACK");130 });131 socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data132});133server.once('flush', (socket, buffer) => {134 console.log(socket.id);135 console.log(buffer[0].type);136 console.log(buffer[0].options);137 console.log(buffer[0].data);138});139server.once('drain', (socket) => {140 console.log(socket.id);141});142server.close();...

Full Screen

Full Screen

portprober_test.js

Source:portprober_test.js Github

copy

Full Screen

...23 server = net.createServer(function(){});24 })25 afterEach(function(done) {26 if (!server) return done();27 server.close(function() {28 done();29 });30 });31 it('should work for INADDR_ANY', function(done) {32 server.listen(0, function() {33 var port = server.address().port;34 assertPortNotfree(port).then(function() {35 var done = promise.defer();36 server.close(function() {37 server = null;38 done.fulfill(assertPortIsFree(port));39 });40 return done.promise;41 }).then(function() { done(); }, done);42 });43 });44 it('should work for a specific host', function(done) {45 var host = '127.0.0.1';46 server.listen(0, host, function() {47 var port = server.address().port;48 assertPortNotfree(port, host).then(function() {49 var done = promise.defer();50 server.close(function() {51 server = null;52 done.fulfill(assertPortIsFree(port, host));53 });54 return done.promise;55 }).then(function() { done(); }, done);56 });57 });58});59describe('findFreePort', function() {60 var server;61 beforeEach(function() {62 server = net.createServer(function(){});63 })64 afterEach(function(done) {65 if (!server) return done();66 server.close(function() {67 done();68 });69 });70 it('should work for INADDR_ANY', function(done) {71 portprober.findFreePort().then(function(port) {72 server.listen(port, function() {73 assertPortNotfree(port).then(function() {74 var done = promise.defer();75 server.close(function() {76 server = null;77 done.fulfill(assertPortIsFree(port));78 });79 return done.promise;80 }).then(function() { done(); }, done);81 });82 });83 });84 it('should work for a specific host', function(done) {85 var host = '127.0.0.1';86 portprober.findFreePort(host).then(function(port) {87 server.listen(port, host, function() {88 assertPortNotfree(port, host).then(function() {89 var done = promise.defer();90 server.close(function() {91 server = null;92 done.fulfill(assertPortIsFree(port, host));93 });94 return done.promise;95 }).then(function() { done(); }, done);96 });97 });98 });99});100function assertPortIsFree(port, opt_host) {101 return portprober.isFree(port, opt_host).then(function(free) {102 assert.ok(free, 'port should be free');103 });104}...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...9 directory: path.join(__dirname, "fixtures"),10 port: 432111 },12 err => {13 if (err) return server.close(() => t.end(err));14 got("localhost:4321")15 .then(res => {16 t.equal(res.statusCode, 200, "root status code");17 server.close(t.end.bind(t));18 })19 .catch(err => server.close(() => t.end(err)));20 }21 );22});23test("server with multiple directories", t => {24 let server;25 server = app.start(26 {27 directories: [28 path.join(__dirname, "fixtures"),29 path.join(__dirname, "test-directory")30 ]31 },32 err => {33 if (err) return server.close(() => t.end(err));34 got("localhost:9000/test-json.json")35 .then(res => {36 t.equal(res.statusCode, 200, "response status code");37 server.close(t.end.bind(t));38 })39 .catch(err => server.close(() => t.end(err)));40 }41 );42});43test("server with a custom host", t => {44 let server;45 const host = "0.0.0.0";46 server = app.start(47 {48 host: host49 },50 (err, address) => {51 if (err) return server.close(() => t.end(err));52 got(`${address.address}:${address.port}/test-json.json`)53 .then(res => {54 t.equal(res.statusCode, 200, "response status code");55 server.close(t.end.bind(t));56 })57 .catch(err => server.close(() => t.end(err)));58 }59 );60});61test.skip("server with custom index file", t => {62 let server;63 server = app.start(64 {65 directory: path.join(__dirname, "fixtures"),66 file: "cat.js",67 port: 800068 },69 (err, address) => {70 if (err) return server.close(() => t.end(err));71 got(`localhost:${address.port}`)72 .then(res => {73 t.equal(res.statusCode, 200, "root status code");74 t.equal(res.body, "// cat.js", "body");75 server.close(t.end.bind(t));76 })77 .catch(err => server.close(() => t.end(err)));78 }79 );80});81testWithServer("serves index.html", (t, done) => {82 let base = got("localhost:9000").then(res => {83 t.equal(res.statusCode, 200, "root status code");84 t.equal(res.body, "index.html", "root response body");85 });86 let somePath = got("localhost:9000/anything/here").then(res => {87 t.equal(res.statusCode, 200, "some path status code");88 t.equal(res.body, "index.html", "some path response body");89 });90 Promise.all([base, somePath])91 .then(() => done())92 .catch(done);93});94testWithServer("serves files", (t, done) => {95 let tests = [96 ["jpg", "image/jpeg"],97 ["js", "application/javascript"],98 ["json", "application/json"]99 ].map(data =>100 got(`localhost:9000/cat.${data[0]}`).then(res => {101 t.equal(res.statusCode, 200, `${data[0]} successful`);102 t.equal(res.headers["content-type"], data[1], `${data[0]} format`);103 })104 );105 Promise.all(tests)106 .then(() => done())107 .catch(done);108});109function testWithServer(name, done) {110 test(name, t => {111 let server;112 server = app.start({ directory: path.join(__dirname, "fixtures") }, err =>113 done(t, err => server.close(() => t.end(err)))114 );115 });...

Full Screen

Full Screen

test-tls-connect-simple.js

Source:test-tls-connect-simple.js Github

copy

Full Screen

...16 cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')17};18var server = tls.Server(options, function(socket) {19 if (++serverConnected === 2) {20 server.close(function() {21 ++serverCloseCallbacks;22 });23 server.on('close', function() {24 ++serverCloseEvents;25 });26 }27});28server.listen(common.PORT, function() {29 var client1 = tls.connect({30 port: common.PORT,31 rejectUnauthorized: false32 }, function() {33 ++clientConnected;34 client1.end();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const options = {3 capabilities: {4 }5};6const client = wdio.remote(options);7 .init()8 .then(() => client.pause(5000))9 .then(() => client.end())10 .then(() => client.close())11 .catch((err) => console.log(err));12const wdio = require('webdriverio');13const options = {14 capabilities: {15 }16};17const client = wdio.remote(options);18 .init()19 .then(() => client.pause(5000))20 .then(() => client.end())21 .then(() => client.close())22 .catch((err) => console.log(err));23const wdio = require('webdriverio');24const options = {25 capabilities: {26 }27};28const client = wdio.remote(options);29 .init()30 .then(() => client.pause(5000))31 .then(() => client.end())32 .then(() => client.close())33 .catch((err) => console.log(err));34const wdio = require('webdriverio');35const options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var serverConfig = {4};5var driver = wd.promiseChainRemote(serverConfig);6driver.init({7}).then(function() {8 return driver.quit();9});10driver.on('status', function(info) {11 console.log('\x1b[36m%s\x1b[0m', info);12});13driver.on('command', function(meth, path, data) {14 console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path, data || '');15});16driver.on('http', function(meth, path, data) {17 console.log(' > \x1b[90m%s\x1b[0m %s %j', meth, path, data || '');18});19driver.quit().then(function() {20 return driver.close();21});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var serverConfig = {8}9var desiredCaps = {10}11var browser = wd.promiseChainRemote(serverConfig);12before(function () {13 browser.init(desiredCaps);14 browser.sleep(3000);15});16describe('Test Suite', function () {17 it('Test Case', function () {18 .elementByAccessibilityId('test')19 .click()20 .sleep(3000)21 .close()22 .quit();23 });24});25after(function () {26 console.log("Test Completed");27});28{29 "scripts": {30 },31 "dependencies": {32 }33}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var expect = chai.expect;6var serverConfig = {7};8var driver = wd.promiseChainRemote(serverConfig);9var desired = {10};11 .init(desired)12 .then(function () {13 })14 .then(function () {15 return driver.quit();16 })17 .then(function () {18 return driver.close();19 })20 .catch(function (err) {21 console.error(err);22 });23> [MJSONWP] at XCUITestDriver.close$ (lib/commands/general.js:37:11)24> [MJSONWP] at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)25> [MJSONWP] at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)26> [MJSONWP] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)27> [MJSONWP] at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)28> [MJSONWP] at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)29> [MJSONWP] at flush (/usr/local/lib/node_modules/appium/node

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var serverConfig = {4};5var driver = wd.promiseChainRemote(serverConfig);6driver.init({7}).then(function () {8 return driver.quit();9}).then(function () {10 return driver.close();11}).then(function () {12 console.log('Test passed');13}).catch(function (err) {14 console.log('Test failed');15 console.error(err);16});17var wd = require('wd');18var assert = require('assert');19var serverConfig = {20};21var driver = wd.promiseChainRemote(serverConfig);22driver.init({23}).then(function () {24 return driver.quit();25}).then(function () {26 return driver.closeApp();27}).then(function () {28 console.log('Test passed');29}).catch(function (err) {30 console.log('Test failed');31 console.error(err);32});

Full Screen

Using AI Code Generation

copy

Full Screen

1const appium = require('appium');2const { createServer } = require('appium-express');3const { XCUITestDriver } = require('appium-xcuitest-driver');4const server = createServer({port: 4723, basePath: ''});5const driver = new XCUITestDriver({server, sessionOverride: true});6server.route('/wd/hub/session/:sessionId/appium/device/close_app')7 .post(driver.close.bind(driver));8server.route('/wd/hub/session/:sessionId/appium/device/launch_app')9 .post(driver.launchApp.bind(driver));10server.route('/wd/hub/session/:sessionId/appium/device/terminate_app')11 .post(driver.terminateApp.bind(driver));12server.route('/wd/hub/session/:sessionId/appium/device/activate_app')13 .post(driver.activateApp.bind(driver));14server.route('/wd/hub/session/:sessionId/appium/device/deactivate_app')15 .post(driver.deactivateApp.bind(driver));16server.route('/wd/hub/session/:sessionId/appium/device/background')17 .post(driver.background.bind(driver));18server.route('/wd/hub/session/:sessionId/appium/device/reset')19 .post(driver.reset.bind(driver));20server.route('/wd/hub/session/:sessionId/appium/device/shake')21 .post(driver.shake.bind(driver));22server.route('/wd/hub/session/:sessionId/appium/device/lock')23 .post(driver.lock.bind(driver));24server.route('/wd/hub/session/:sessionId/appium/device/unlock')25 .post(driver.unlock.bind(driver));26server.route('/wd/hub/session/:sessionId/appium/device/is_locked')27 .post(driver.isLocked.bind(driver));28server.route('/wd/hub/session/:sessionId/appium/device/press_button')29 .post(driver.pressButton.bind(driver));30server.route('/wd/hub/session/:sessionId/appium/device/toggle_touch_id_enrollment')31 .post(driver.toggleTouchIdEnrollment.bind(driver));32server.route('/wd/hub/session/:sessionId/appium/device/toggle_wifi')33 .post(driver.toggleWiFi.bind(driver));34server.route('/wd/hub/session/:sessionId/appium/device/toggle_location_services')35 .post(driver.toggleLocationServices.bind(driver));36server.route('/wd/hub/session/:sessionId/appium/device/toggle_airplane_mode')37 .post(driver.toggleAirplaneMode.bind(driver));38server.route('/wd/hub/session/:sessionId/appium/device/toggle_data')39 .post(driver.toggleData.bind(driver));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumDriver } = require('appium-base-driver');2const { XCUITestDriver } = require('appium-xcuitest-driver');3(async function main() {4 const appiumDriver = new AppiumDriver();5 const xcuitestDriver = new XCUITestDriver();6 await appiumDriver.createSession({7 capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6chaiAsPromised.transferPromiseness = wd.transferPromiseness;7const path = require('path');8const desired = {9 app: path.resolve(__dirname, 'UICatalog.app'),10};11const driver = wd.promiseChainRemote('localhost', 4723);12 .init(desired)13 .sleep(10000)14 .close()15 .sleep(10000)16 .init(desired)17 .sleep(10000)18 .close()19 .sleep(10000)20 .quit();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful