UNPKG

1.64 kBJavaScriptView Raw
1/**
2 * Tests windowslib's logrelay module.
3 *
4 * @copyright
5 * Copyright (c) 2014 by Appcelerator, Inc. All Rights Reserved.
6 *
7 * @license
8 * Licensed under the terms of the Apache Public License.
9 * Please see the LICENSE included with this distribution for details.
10 */
11
12const
13 net = require('net'),
14 windowslib = require('..');
15
16describe('log relay', function () {
17 it('namespace should be an object', function () {
18 should(windowslib.LogRelay).be.an.Function;
19 });
20
21 it('start log relay, receive TCP connection, get log message, shutdown', function (done) {
22 this.timeout(5000);
23 this.slow(4000);
24
25 var relay = new windowslib.LogRelay();
26 var testMsg = 'Hello World!';
27
28 relay.on('started', function () {
29 var client = net.createConnection(relay.tcpPort, function (conn) {
30 client.write(relay.serverToken + '\n');
31 client.write(testMsg);
32 client.destroy();
33 });
34 });
35
36 relay.on('message', function (msg) {
37 relay.stop();
38 should(msg).equal(testMsg);
39 done();
40 });
41
42 relay.start();
43 });
44
45 it('start log relay, receive TCP connection, get log message, wait for buffers to flush, shutdown', function (done) {
46 this.timeout(5000);
47 this.slow(4000);
48
49 var relay = new windowslib.LogRelay();
50 var testMsg = 'Hello World!';
51
52 relay.on('started', function () {
53 var client = net.createConnection(relay.tcpPort, function (conn) {
54 client.write(relay.serverToken + '\n');
55 client.write(testMsg);
56 });
57 });
58
59 relay.on('message', function (msg) {
60 relay.stop();
61 should(msg).equal(testMsg);
62 done();
63 });
64
65 relay.start();
66 });
67});
\No newline at end of file