|
1 |
| -"use strict"; |
| 1 | +'use strict'; |
2 | 2 |
|
3 |
| -var Server = require("mqtt/test/server"); |
| 3 | +var Server = require('mqtt/test/server'); |
4 | 4 |
|
5 |
| -var AsyncMQTT = require("./"); |
| 5 | +var AsyncMQTT = require('./'); |
6 | 6 | var AsyncClient = AsyncMQTT.AsyncClient;
|
7 | 7 |
|
8 |
| -var test = require("tape"); |
| 8 | +var test = require('tape'); |
9 | 9 |
|
10 | 10 | var SERVER_PORT = 1883;
|
11 |
| -var SERVER_URL = "mqtt://localhost:" + SERVER_PORT; |
| 11 | +var SERVER_URL = 'mqtt://localhost:' + SERVER_PORT; |
12 | 12 |
|
13 | 13 | var server = buildServer().listen(SERVER_PORT);
|
14 | 14 | server.unref();
|
15 | 15 |
|
16 |
| -server.on("listening", runTests); |
| 16 | +server.on('listening', runTests); |
17 | 17 |
|
18 | 18 | function runTests() {
|
19 |
| - test("Connect should return an instance of AsyncClient", function (t) { |
| 19 | + test('Connect should return an instance of AsyncClient', function (t) { |
20 | 20 | t.plan(1);
|
21 | 21 | var client = AsyncMQTT.connect(SERVER_URL);
|
22 | 22 |
|
23 |
| - t.ok(client instanceof AsyncClient, "Connect returned an AsyncClient"); |
| 23 | + t.ok(client instanceof AsyncClient, 'Connect returned an AsyncClient'); |
24 | 24 |
|
25 | 25 | client.end();
|
26 | 26 | });
|
27 | 27 |
|
28 |
| - test("Should be able to listen on event on client", function (t) { |
| 28 | + test('Should be able to listen on event on client', function (t) { |
29 | 29 | t.plan(1);
|
30 | 30 |
|
31 | 31 | var client = AsyncMQTT.connect(SERVER_URL);
|
32 | 32 |
|
33 |
| - client.once("connect", function () { |
34 |
| - t.pass("Connected"); |
| 33 | + client.once('connect', function () { |
| 34 | + t.pass('Connected'); |
35 | 35 | client.end();
|
36 | 36 | });
|
37 | 37 | });
|
38 | 38 |
|
39 |
| - test("Calling end() should resolve once disconnected", function (t) { |
| 39 | + test('Calling end() should resolve once disconnected', function (t) { |
40 | 40 | t.plan(2);
|
41 | 41 |
|
42 | 42 | var client = AsyncMQTT.connect(SERVER_URL);
|
43 | 43 |
|
44 |
| - client.on("close", function () { |
45 |
| - t.pass("Close event occured"); |
| 44 | + client.on('close', function () { |
| 45 | + t.pass('Close event occured'); |
46 | 46 | });
|
47 | 47 |
|
48 |
| - client.on("connect", function () { |
| 48 | + client.on('connect', function () { |
49 | 49 | // Wait for connect to emit before ending
|
50 | 50 | client.end().then(function(){
|
51 |
| - t.pass("End resolved"); |
| 51 | + t.pass('End resolved'); |
52 | 52 | });
|
53 | 53 | });
|
54 | 54 | });
|
55 | 55 |
|
56 |
| - test("Calling subscribe should resolve once subscribed", function (t) { |
| 56 | + test('Calling subscribe should resolve once subscribed', function (t) { |
57 | 57 | t.plan(1);
|
58 | 58 |
|
59 | 59 | var client = AsyncMQTT.connect(SERVER_URL);
|
60 | 60 |
|
61 |
| - client.subscribe("example", { |
| 61 | + client.subscribe('example', { |
62 | 62 | qos: 1
|
63 | 63 | }).then(function(){
|
64 |
| - t.pass("Subscribed"); |
| 64 | + t.pass('Subscribed'); |
65 | 65 | client.end();
|
66 | 66 | })
|
67 | 67 | });
|
68 | 68 |
|
69 |
| - test("Calling unsubscribe should resolve once completed", function(t){ |
| 69 | + test('Calling unsubscribe should resolve once completed', function(t){ |
70 | 70 | t.plan(1);
|
71 | 71 |
|
72 | 72 | var client = AsyncMQTT.connect(SERVER_URL);
|
73 | 73 |
|
74 |
| - client.subscribe("example", { |
| 74 | + client.subscribe('example', { |
75 | 75 | qos: 1
|
76 | 76 | }).then(function(){
|
77 |
| - return client.unsubscribe("example"); |
| 77 | + return client.unsubscribe('example'); |
78 | 78 | }).then(function(){
|
79 |
| - t.pass("Unsunbscribed"); |
| 79 | + t.pass('Unsunbscribed'); |
80 | 80 | return client.end();
|
81 | 81 | });
|
82 | 82 | });
|
83 | 83 |
|
84 |
| - test("Calling publish should resolve once completed", function (t) { |
| 84 | + test('Calling publish should resolve once completed', function (t) { |
85 | 85 | t.plan(1);
|
86 | 86 |
|
87 | 87 | var client = AsyncMQTT.connect(SERVER_URL);
|
88 | 88 |
|
89 |
| - client.publish("example", "test", { |
| 89 | + client.publish('example', 'test', { |
90 | 90 | qos: 1
|
91 | 91 | }).then(function(){
|
92 |
| - t.pass("Published"); |
| 92 | + t.pass('Published'); |
93 | 93 | return client.end();
|
94 | 94 | });
|
95 | 95 | });
|
|
0 commit comments