Skip to content

Commit b8eb39f

Browse files
committed
Linting the scripts in the test directory.
1 parent 38e26c6 commit b8eb39f

13 files changed

+172
-176
lines changed

.jshintrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// "single" : require single quotes
2626
// "double" : require double quotes
2727
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
28-
"unused" : true, // true: Require all defined variables be used
28+
"unused" : "vars", // vars: Require all defined variables be used, ignore function params
2929
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
3030
"maxparams" : false, // {int} Max number of formal params allowed per function
3131
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
@@ -82,5 +82,7 @@
8282
"yui" : false, // Yahoo User Interface
8383

8484
// Custom Globals
85-
"globals" : {} // additional predefined global variables
85+
"globals" : { // additional predefined global variables
86+
"WebSocket": true
87+
}
8688
}

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var gulp = require('gulp');
55
var jshint = require('gulp-jshint');
66

77
gulp.task('lint', function() {
8-
return gulp.src(['gulpfile.js', 'lib/**/*.js', 'test/unit/*.js'])
8+
return gulp.src(['gulpfile.js', 'lib/**/*.js', 'test/**/*.js'])
99
.pipe(jshint('.jshintrc'))
1010
.pipe(jshint.reporter('jshint-stylish', {verbose: true}))
1111
.pipe(jshint.reporter('fail'));

test/scripts/autobahn-test-client.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/************************************************************************
33
* Copyright 2010-2011 Worlize Inc.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
*
99
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
@@ -34,14 +34,14 @@ process.argv.forEach(function(value) {
3434
}
3535
});
3636

37-
args.protocol = args.secure ? 'wss:' : 'ws:'
37+
args.protocol = args.secure ? 'wss:' : 'ws:';
3838

39-
console.log("WebSocket-Node: Echo test client for running against the Autobahn test suite");
40-
console.log("Usage: ./libwebsockets-test-client.js --host=127.0.0.1 --port=9000 [--secure]");
41-
console.log("");
39+
console.log('WebSocket-Node: Echo test client for running against the Autobahn test suite');
40+
console.log('Usage: ./libwebsockets-test-client.js --host=127.0.0.1 --port=9000 [--secure]');
41+
console.log('');
4242

4343

44-
console.log("Starting test run.");
44+
console.log('Starting test run.');
4545

4646
getCaseCount(function(caseCount) {
4747
var currentCase = 1;
@@ -54,9 +54,9 @@ getCaseCount(function(caseCount) {
5454
}
5555
else {
5656
process.nextTick(function() {
57-
console.log("Test suite complete, generating report.");
57+
console.log('Test suite complete, generating report.');
5858
updateReport(function() {
59-
console.log("Report generated.");
59+
console.log('Report generated.');
6060
});
6161
});
6262
}
@@ -66,7 +66,7 @@ getCaseCount(function(caseCount) {
6666

6767

6868
function runTestCase(caseIndex, caseCount, callback) {
69-
console.log("Running test " + caseIndex + " of " + caseCount);
69+
console.log('Running test ' + caseIndex + ' of ' + caseCount);
7070
var echoClient = new WebSocketClient({
7171
maxReceivedFrameSize: 64*1024*1024, // 64MiB
7272
maxReceivedMessageSize: 64*1024*1024, // 64MiB
@@ -76,12 +76,12 @@ function runTestCase(caseIndex, caseCount, callback) {
7676
});
7777

7878
echoClient.on('connectFailed', function(error) {
79-
console.log("Connect Error: " + error.toString());
79+
console.log('Connect Error: ' + error.toString());
8080
});
8181

8282
echoClient.on('connect', function(connection) {
8383
connection.on('error', function(error) {
84-
console.log("Connection Error: " + error.toString());
84+
console.log('Connection Error: ' + error.toString());
8585
});
8686
connection.on('close', function() {
8787
callback();
@@ -98,10 +98,9 @@ function runTestCase(caseIndex, caseCount, callback) {
9898

9999
var qs = querystring.stringify({
100100
case: caseIndex,
101-
agent: "WebSocket-Node Client v" + wsVersion
101+
agent: 'WebSocket-Node Client v' + wsVersion
102102
});
103-
var url = "ws://" + args.host + ":" + args.port + "/runCase?" + qs;
104-
echoClient.connect("ws://" + args.host + ":" + args.port + "/runCase?" + qs, []);
103+
echoClient.connect('ws://' + args.host + ':' + args.port + '/runCase?' + qs, []);
105104
}
106105

107106
function getCaseCount(callback) {
@@ -113,11 +112,11 @@ function getCaseCount(callback) {
113112
});
114113
connection.on('message', function(message) {
115114
if (message.type === 'utf8') {
116-
console.log("Got case count: " + message.utf8Data);
115+
console.log('Got case count: ' + message.utf8Data);
117116
caseCount = parseInt(message.utf8Data, 10);
118117
}
119118
else if (message.type === 'binary') {
120-
throw new Error("Unexpected binary message when retrieving case count");
119+
throw new Error('Unexpected binary message when retrieving case count');
121120
}
122121
});
123122
});
@@ -127,7 +126,7 @@ function getCaseCount(callback) {
127126
function updateReport(callback) {
128127
var client = new WebSocketClient();
129128
var qs = querystring.stringify({
130-
agent: "WebSocket-Node Client v" + wsVersion
129+
agent: 'WebSocket-Node Client v' + wsVersion
131130
});
132131
client.on('connect', function(connection) {
133132
connection.on('close', callback);

test/scripts/echo-server.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
/************************************************************************
33
* Copyright 2010-2011 Worlize Inc.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
*
99
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
***********************************************************************/
1717

1818
var WebSocketServer = require('../../lib/WebSocketServer');
1919
var http = require('http');
20-
var url = require('url');
21-
var fs = require('fs');
2220

2321
var args = { /* defaults */
2422
port: '8080',
@@ -37,19 +35,19 @@ process.argv.forEach(function(value) {
3735
var port = parseInt(args.port, 10);
3836
var debug = args.debug;
3937

40-
console.log("WebSocket-Node: echo-server");
41-
console.log("Usage: ./echo-server.js [--port=8080] [--debug]");
38+
console.log('WebSocket-Node: echo-server');
39+
console.log('Usage: ./echo-server.js [--port=8080] [--debug]');
4240

4341
var server = http.createServer(function(request, response) {
44-
if (debug) console.log((new Date()) + " Received request for " + request.url);
42+
if (debug) { console.log((new Date()) + ' Received request for ' + request.url); }
4543
response.writeHead(404);
4644
response.end();
4745
});
4846
server.listen(port, function() {
49-
console.log((new Date()) + " Server is listening on port " + port);
47+
console.log((new Date()) + ' Server is listening on port ' + port);
5048
});
5149

52-
wsServer = new WebSocketServer({
50+
var wsServer = new WebSocketServer({
5351
httpServer: server,
5452
autoAcceptConnections: true,
5553
maxReceivedFrameSize: 64*1024*1024, // 64MiB
@@ -60,11 +58,11 @@ wsServer = new WebSocketServer({
6058
});
6159

6260
wsServer.on('connect', function(connection) {
63-
if (debug) console.log((new Date()) + " Connection accepted" +
64-
" - Protocol Version " + connection.webSocketVersion);
61+
if (debug) { console.log((new Date()) + ' Connection accepted' +
62+
' - Protocol Version ' + connection.webSocketVersion); }
6563
function sendCallback(err) {
6664
if (err) {
67-
console.error("send() error: " + err);
65+
console.error('send() error: ' + err);
6866
connection.drop();
6967
setTimeout(function() {
7068
process.exit(100);
@@ -73,16 +71,16 @@ wsServer.on('connect', function(connection) {
7371
}
7472
connection.on('message', function(message) {
7573
if (message.type === 'utf8') {
76-
if (debug) console.log("Received utf-8 message of " + message.utf8Data.length + " characters.");
74+
if (debug) { console.log('Received utf-8 message of ' + message.utf8Data.length + ' characters.'); }
7775
connection.sendUTF(message.utf8Data, sendCallback);
7876
}
7977
else if (message.type === 'binary') {
80-
if (debug) console.log("Received Binary Message of " + message.binaryData.length + " bytes");
78+
if (debug) { console.log('Received Binary Message of ' + message.binaryData.length + ' bytes'); }
8179
connection.sendBytes(message.binaryData, sendCallback);
8280
}
8381
});
8482
connection.on('close', function(reasonCode, description) {
85-
if (debug) console.log((new Date()) + " Peer " + connection.remoteAddress + " disconnected.");
83+
if (debug) { console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.'); }
8684
connection._debug.printOutput();
8785
});
8886
});

test/scripts/fragmentation-test-client.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
/************************************************************************
33
* Copyright 2010-2011 Worlize Inc.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
*
99
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
***********************************************************************/
1717

1818
var WebSocketClient = require('../../lib/WebSocketClient');
1919

20-
console.log("WebSocket-Node: Test client for parsing fragmented messages.");
20+
console.log('WebSocket-Node: Test client for parsing fragmented messages.');
2121

2222
var args = { /* defaults */
2323
secure: false,
24-
port: "8080",
25-
host: "127.0.0.1",
26-
"no-defragment": false,
24+
port: '8080',
25+
host: '127.0.0.1',
26+
'no-defragment': false,
2727
binary: false
2828
};
2929

@@ -36,15 +36,15 @@ process.argv.forEach(function(value) {
3636
}
3737
});
3838

39-
args.protocol = args.secure ? 'wss:' : 'ws:'
39+
args.protocol = args.secure ? 'wss:' : 'ws:';
4040

4141
if (args.help) {
42-
console.log("Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]");
43-
console.log("");
42+
console.log('Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]');
43+
console.log('');
4444
return;
4545
}
4646
else {
47-
console.log("Use --help for usage information.");
47+
console.log('Use --help for usage information.');
4848
}
4949

5050

@@ -55,7 +55,7 @@ var client = new WebSocketClient({
5555
});
5656

5757
client.on('connectFailed', function(error) {
58-
console.log("Client Error: " + error.toString())
58+
console.log('Client Error: ' + error.toString());
5959
});
6060

6161

@@ -65,36 +65,36 @@ var startTime;
6565
var byteCounter;
6666

6767
client.on('connect', function(connection) {
68-
console.log("Connected");
68+
console.log('Connected');
6969
startTime = new Date();
7070
byteCounter = 0;
7171

7272
connection.on('error', function(error) {
73-
console.log("Connection Error: " + error.toString());
73+
console.log('Connection Error: ' + error.toString());
7474
});
7575

7676
connection.on('close', function() {
77-
console.log("Connection Closed");
77+
console.log('Connection Closed');
7878
});
7979

8080
connection.on('message', function(message) {
8181
if (message.type === 'utf8') {
82-
console.log("Received utf-8 message of " + message.utf8Data.length + " characters.");
82+
console.log('Received utf-8 message of ' + message.utf8Data.length + ' characters.');
8383
logThroughput(message.utf8Data.length);
8484
requestData();
8585
}
8686
else {
87-
console.log("Received binary message of " + message.binaryData.length + " bytes.");
87+
console.log('Received binary message of ' + message.binaryData.length + ' bytes.');
8888
logThroughput(message.binaryData.length);
8989
requestData();
9090
}
9191
});
9292

9393
connection.on('frame', function(frame) {
94-
console.log("Frame: 0x" + frame.opcode.toString(16) + "; " + frame.length + " bytes; Flags: " + renderFlags(frame))
94+
console.log('Frame: 0x' + frame.opcode.toString(16) + '; ' + frame.length + ' bytes; Flags: ' + renderFlags(frame));
9595
messageSize += frame.length;
9696
if (frame.fin) {
97-
console.log("Total message size: " + messageSize + " bytes.");
97+
console.log('Total message size: ' + messageSize + ' bytes.');
9898
logThroughput(messageSize);
9999
messageSize = 0;
100100
requestData();
@@ -106,14 +106,14 @@ client.on('connect', function(connection) {
106106
var duration = (new Date()).valueOf() - startTime.valueOf();
107107
if (duration > 1000) {
108108
var kiloBytesPerSecond = Math.round((byteCounter / 1024) / (duration/1000));
109-
console.log(" Throughput: " + kiloBytesPerSecond + " KBps");
109+
console.log(' Throughput: ' + kiloBytesPerSecond + ' KBps');
110110
startTime = new Date();
111111
byteCounter = 0;
112112
}
113-
};
113+
}
114114

115115
function sendUTFCallback(err) {
116-
if (err) console.error("sendUTF() error: " + err);
116+
if (err) { console.error('sendUTF() error: ' + err); }
117117
}
118118

119119
function requestData() {
@@ -144,7 +144,7 @@ client.on('connect', function(connection) {
144144
flags.push('[MASK]');
145145
}
146146
if (flags.length === 0) {
147-
return "---";
147+
return '---';
148148
}
149149
return flags.join(' ');
150150
}
@@ -153,11 +153,11 @@ client.on('connect', function(connection) {
153153
});
154154

155155
if (args['no-defragment']) {
156-
console.log("Not automatically re-assembling fragmented messages.");
156+
console.log('Not automatically re-assembling fragmented messages.');
157157
}
158158
else {
159-
console.log("Maximum aggregate message size: " + client.config.maxReceivedMessageSize + " bytes.");
159+
console.log('Maximum aggregate message size: ' + client.config.maxReceivedMessageSize + ' bytes.');
160160
}
161-
console.log("Connecting");
161+
console.log('Connecting');
162162

163163
client.connect(args.protocol + '//' + args.host + ':' + args.port + '/', 'fragmentation-test');

0 commit comments

Comments
 (0)