diff options
author | Oleg Efimov <efimovov@gmail.com> | 2010-12-06 01:33:52 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-12-05 15:42:41 -0800 |
commit | 093dfaf801a10905ba27df8cf3aa17b36ea5149a (patch) | |
tree | 27c559ae0d5c97c4671be1ed2b7d247ea6aacb34 | |
parent | 0665f0271e71270dc23ec5231b245adfe709a49f (diff) | |
download | node-new-093dfaf801a10905ba27df8cf3aa17b36ea5149a.tar.gz |
GJSLint all tests, only 3 long lines left in test-url.js
test/simple/test-url.js:31:(0110) Line too long (82 characters).
test/simple/test-url.js:39:(0110) Line too long (85 characters).
test/simple/test-url.js:40:(0110) Line too long (92 characters).
72 files changed, 1530 insertions, 1427 deletions
diff --git a/test/common.js b/test/common.js index 011f3d7a6f..1bc7d4fd35 100644 --- a/test/common.js +++ b/test/common.js @@ -1,4 +1,5 @@ var path = require('path'); +var assert = require('assert'); exports.testDir = path.dirname(__filename); exports.fixturesDir = path.join(exports.testDir, 'fixtures'); @@ -6,8 +7,6 @@ exports.libDir = path.join(exports.testDir, '../lib'); exports.tmpDir = path.join(exports.testDir, 'tmp'); exports.PORT = 12346; -exports.assert = require('assert'); - var util = require('util'); for (var i in util) exports[i] = util[i]; //for (var i in exports) global[i] = exports[i]; @@ -52,7 +51,7 @@ process.on('exit', function() { if (!found) { console.error('Unknown global: %s', x); - exports.assert.ok(false); + assert.ok(false, 'Unknown global founded'); } } }); diff --git a/test/disabled/test-cat.js b/test/disabled/test-cat.js index 7dd6baf1b0..e3784254be 100644 --- a/test/disabled/test-cat.js +++ b/test/disabled/test-cat.js @@ -1,14 +1,15 @@ -require("../common.js"); -http = require("/http.js"); +var common = require('../common.js'); +var assert = require('assert'); +var http = require('http'); -console.log("hello world"); +console.log('hello world'); -var body = "exports.A = function() { return 'A';}"; -var server = http.createServer(function (req, res) { - console.log("req?"); +var body = 'exports.A = function() { return "A";}'; +var server = http.createServer(function(req, res) { + console.log('req?'); res.sendHeader(200, { - "Content-Length": body.length, - "Content-Type": "text/plain" + 'Content-Length': body.length, + 'Content-Type': 'text/plain' }); res.sendBody(body); res.finish(); @@ -18,34 +19,34 @@ server.listen(common.PORT); var errors = 0; var successes = 0; -var promise = process.cat("http://localhost:"+common.PORT, "utf8"); +var promise = process.cat('http://localhost:' + common.PORT, 'utf8'); -promise.addCallback(function (content) { +promise.addCallback(function(content) { assert.equal(body, content); server.close(); successes += 1; }); -promise.addErrback(function () { +promise.addErrback(function() { errors += 1; }); var dirname = process.path.dirname(__filename); -var fixtures = process.path.join(dirname, "fixtures"); -var x = process.path.join(fixtures, "x.txt"); +var fixtures = process.path.join(dirname, 'fixtures'); +var x = process.path.join(fixtures, 'x.txt'); -promise = process.cat(x, "utf8"); +promise = process.cat(x, 'utf8'); -promise.addCallback(function (content) { - assert.equal("xyz", content.replace(/[\r\n]/, '')); +promise.addCallback(function(content) { + assert.equal('xyz', content.replace(/[\r\n]/, '')); successes += 1; }); -promise.addErrback(function () { +promise.addErrback(function() { errors += 1; }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(2, successes); assert.equal(0, errors); }); diff --git a/test/disabled/test-dns.js b/test/disabled/test-dns.js index f469aed0f7..318b5222d7 100644 --- a/test/disabled/test-dns.js +++ b/test/disabled/test-dns.js @@ -1,16 +1,16 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); -var dns = require("dns"), - child_process = require("child_process"); +var dns = require('dns'), + child_process = require('child_process'); // Try resolution without callback -assert.throws(function () { +assert.throws(function() { dns.resolve('google.com', 'A'); }); -assert.throws(function () { +assert.throws(function() { dns.resolve('127.0.0.1', 'PTR'); }); @@ -21,7 +21,7 @@ var hosts = ['example.com', 'google.com', // MX, multiple A records '_xmpp-client._tcp.google.com', // SRV 'oakalynhall.co.uk' // Multiple PTR replies - ]; +]; var records = ['A', 'AAAA', 'MX', 'TXT', 'SRV']; @@ -30,10 +30,10 @@ while (i--) { var j = records.length; while (j--) { - var hostCmd = "dig -t " + records[j] + " " + hosts[i] + - "| grep '^" + hosts[i] + "\\.\\W.*IN.*" + records[j] + "'" + - "| sed -E 's/[[:space:]]+/ /g' | cut -d ' ' -f 5- " + - "| sed -e 's/\\.$//'"; + var hostCmd = 'dig -t ' + records[j] + ' ' + hosts[i] + + '| grep "^' + hosts[i] + '\\.\\W.*IN.*' + records[j] + '"' + + '| sed -E "s/[[:space:]]+/ /g" | cut -d " " -f 5- ' + + '| sed -e "s/\\.$//"'; child_process.exec(hostCmd, checkDnsRecord(hosts[i], records[j])); } } @@ -53,65 +53,65 @@ function checkDnsRecord(host, record) { myRecord = record; return function(err, stdout) { var expected = []; - if(stdout.length) - expected = stdout.substr(0, stdout.length - 1).split("\n"); + if (stdout.length) + expected = stdout.substr(0, stdout.length - 1).split('\n'); switch (myRecord) { - case "A": - case "AAAA": - dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { - if(error) result = []; - cmpResults(expected, result, ttl, cname); - - // do reverse lookup check - var ll = result.length; - while (ll--) { - var ip = result[ll]; - var reverseCmd = "host " + ip + - "| cut -d \" \" -f 5-" + - "| sed -e 's/\\.$//'"; - - child_process.exec(reverseCmd, checkReverse(ip)); - } - }); + case 'A': + case 'AAAA': + dns.resolve(myHost, myRecord, function(error, result, ttl, cname) { + if (error) result = []; + cmpResults(expected, result, ttl, cname); + + // do reverse lookup check + var ll = result.length; + while (ll--) { + var ip = result[ll]; + var reverseCmd = 'host ' + ip + + '| cut -d " " -f 5-' + + '| sed -e "s/\\.$//"'; + + child_process.exec(reverseCmd, checkReverse(ip)); + } + }); break; - case "MX": - dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { - if(error) result = []; - - var strResult = []; - var ll = result.length; - while (ll--) { - strResult.push(result[ll].priority + " " + result[ll].exchange); - } - cmpResults(expected, strResult, ttl, cname); + case 'MX': + dns.resolve(myHost, myRecord, function(error, result, ttl, cname) { + if (error) result = []; + + var strResult = []; + var ll = result.length; + while (ll--) { + strResult.push(result[ll].priority + ' ' + result[ll].exchange); + } + cmpResults(expected, strResult, ttl, cname); }); break; - case "TXT": - dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { - if(error) result = []; - - var strResult = []; - var ll = result.length; - while (ll--) { - strResult.push('"' + result[ll] + '"'); - } - cmpResults(expected, strResult, ttl, cname); + case 'TXT': + dns.resolve(myHost, myRecord, function(error, result, ttl, cname) { + if (error) result = []; + + var strResult = []; + var ll = result.length; + while (ll--) { + strResult.push('"' + result[ll] + '"'); + } + cmpResults(expected, strResult, ttl, cname); }); break; - case "SRV": - dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { - if(error) result = []; - - var strResult = []; - var ll = result.length; - while (ll--) { - strResult.push(result[ll].priority + " " + - result[ll].weight + " " + - result[ll].port + " " + - result[ll].name); - } - cmpResults(expected, strResult, ttl, cname); + case 'SRV': + dns.resolve(myHost, myRecord, function(error, result, ttl, cname) { + if (error) result = []; + + var strResult = []; + var ll = result.length; + while (ll--) { + strResult.push(result[ll].priority + ' ' + + result[ll].weight + ' ' + + result[ll].port + ' ' + + result[ll].name); + } + cmpResults(expected, strResult, ttl, cname); }); break; } @@ -121,11 +121,11 @@ function checkDnsRecord(host, record) { function checkReverse(ip) { var myIp = ip; - return function (errr, stdout) { - var expected = stdout.substr(0, stdout.length - 1).split("\n"); + return function(errr, stdout) { + var expected = stdout.substr(0, stdout.length - 1).split('\n'); - reversing = dns.reverse(myIp, function (error, domains, ttl, cname) { - if(error) domains = []; + var reversing = dns.reverse(myIp, function(error, domains, ttl, cname) { + if (error) domains = []; cmpResults(expected, domains, ttl, cname); }); } @@ -133,19 +133,23 @@ function checkReverse(ip) { function cmpResults(expected, result, ttl, cname) { if (expected.length != result.length) { - if (expected.length == 1 && expected[0] == '3(NXDOMAIN)' && result.length == 0) { + if (expected.length == 1 && + expected[0] == '3(NXDOMAIN)' && + result.length == 0) { // it's ok, dig returns NXDOMAIN, while dns module returns nothing } else { - console.log('---WARNING---\nexpected ' + expected + '\nresult ' + result + '\n-------------'); + console.log('---WARNING---\nexpected ' + expected + + '\nresult ' + result + '\n-------------'); } return; } expected.sort(); result.sort(); - ll = expected.length; + var ll = expected.length; while (ll--) { assert.equal(result[ll], expected[ll]); - console.log("Result " + result[ll] + " was equal to expected " + expected[ll]); + console.log('Result ' + result[ll] + + ' was equal to expected ' + expected[ll]); } } diff --git a/test/disabled/test-eio-race3.js b/test/disabled/test-eio-race3.js index 11ad5afde8..820128ae46 100644 --- a/test/disabled/test-eio-race3.js +++ b/test/disabled/test-eio-race3.js @@ -1,20 +1,19 @@ /* XXX Can this test be modified to not call the now-removed wait()? */ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); console.log('first stat ...'); fs.stat(__filename) - .addCallback( function(stats) { - console.log('second stat ...'); - fs.stat(__filename) - .timeout(1000) - .wait(); - - console.log('test passed'); - }) + .addCallback(function(stats) { + console.log('second stat ...'); + fs.stat(__filename) + .timeout(1000) + .wait(); + console.log('test passed'); + }) .addErrback(function() { - throw new Exception(); - }); + throw new Exception(); + }); diff --git a/test/disabled/test-fs-sendfile.js b/test/disabled/test-fs-sendfile.js index 9f280aa1fc..01cab5ed94 100644 --- a/test/disabled/test-fs-sendfile.js +++ b/test/disabled/test-fs-sendfile.js @@ -1,13 +1,13 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); -tcp = require("tcp"); -util = require("util"); -var x = path.join(common.fixturesDir, "x.txt"); -var expected = "xyz"; +var net = require('net'); +var util = require('util'); +var x = path.join(common.fixturesDir, 'x.txt'); +var expected = 'xyz'; -var server = tcp.createServer(function (socket) { - socket.addListener("receive", function (data) { +var server = net.createServer(function(socket) { + socket.addListener('receive', function(data) { found = data; client.close(); socket.close(); @@ -17,11 +17,12 @@ var server = tcp.createServer(function (socket) { }); server.listen(common.PORT); -var client = tcp.createConnection(common.PORT); -client.addListener("connect", function () { - fs.open(x, 'r').addCallback(function (fd) { - fs.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) { - assert.equal(expected.length, size); - }); +var client = net.createConnection(common.PORT); +client.addListener('connect', function() { + fs.open(x, 'r').addCallback(function(fd) { + fs.sendfile(client.fd, fd, 0, expected.length) + .addCallback(function(size) { + assert.equal(expected.length, size); + }); }); }); diff --git a/test/disabled/test-http-big-proxy-responses.js b/test/disabled/test-http-big-proxy-responses.js index dfbe3df802..6cf28a729c 100644 --- a/test/disabled/test-http-big-proxy-responses.js +++ b/test/disabled/test-http-big-proxy-responses.js @@ -1,18 +1,18 @@ var common = require('../common'); -var assert = require('assert');; -var util = require("util"), -fs = require("fs"), -http = require("http"), -url = require("url"); +var assert = require('assert'); +var util = require('util'), + fs = require('fs'), + http = require('http'), + url = require('url'); var chunk = '01234567890123456789'; // Produce a very large response. -var chargen = http.createServer(function (req, res) { +var chargen = http.createServer(function(req, res) { var len = parseInt(req.headers['x-len'], 10); assert.ok(len > 0); - res.writeHead(200, {"transfer-encoding":"chunked"}); - for (var i=0; i<len; i++) { + res.writeHead(200, {'transfer-encoding': 'chunked'}); + for (var i = 0; i < len; i++) { if (i % 1000 == 0) common.print(','); res.write(chunk); } @@ -21,7 +21,7 @@ var chargen = http.createServer(function (req, res) { chargen.listen(9000, ready); // Proxy to the chargen server. -var proxy = http.createServer(function (req, res) { +var proxy = http.createServer(function(req, res) { var c = http.createClient(9000, 'localhost'); var len = parseInt(req.headers['x-len'], 10); @@ -30,7 +30,7 @@ var proxy = http.createServer(function (req, res) { var sent = 0; - c.addListener('error', function (e) { + c.addListener('error', function(e) { console.log('proxy client error. sent ' + sent); throw e; }); @@ -45,7 +45,7 @@ var proxy = http.createServer(function (req, res) { if (count++ % 1000 == 0) common.print('.'); res.write(d); sent += d.length; - assert.ok(sent <= (len*chunk.length)); + assert.ok(sent <= (len * chunk.length)); }); proxy_res.addListener('end', function() { @@ -64,7 +64,7 @@ function call_chargen(list) { if (list.length > 0) { var len = list.shift(); - common.debug("calling chargen for " + len + " chunks."); + common.debug('calling chargen for ' + len + ' chunks.'); var recved = 0; @@ -74,12 +74,12 @@ function call_chargen(list) { res.addListener('data', function(d) { recved += d.length; - assert.ok(recved <= (len*chunk.length)); + assert.ok(recved <= (len * chunk.length)); }); res.addListener('end', function() { - assert.ok(recved <= (len*chunk.length)); - common.debug("end for " + len + " chunks."); + assert.ok(recved <= (len * chunk.length)); + common.debug('end for ' + len + ' chunks.'); call_chargen(list); }); @@ -87,7 +87,7 @@ function call_chargen(list) { req.end(); } else { - console.log("End of list. closing servers"); + console.log('End of list. closing servers'); proxy.close(); chargen.close(); done = true; @@ -95,11 +95,11 @@ function call_chargen(list) { } serversRunning = 0; -function ready () { +function ready() { if (++serversRunning < 2) return; - call_chargen([ 100, 1000, 10000, 100000, 1000000 ]); + call_chargen([100, 1000, 10000, 100000, 1000000]); } -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(done); }); diff --git a/test/disabled/test-http-head-request.js b/test/disabled/test-http-head-request.js index 57fe371242..e2ad9ef277 100644 --- a/test/disabled/test-http-head-request.js +++ b/test/disabled/test-http-head-request.js @@ -1,16 +1,17 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); -var assert = require("assert"); -var http = require("http"); -var util = require("util"); +var assert = require('assert'); +var http = require('http'); +var util = require('util'); -var body = "hello world"; +var body = 'hello world'; -server = http.createServer(function (req, res) { - res.writeHeader(200 , { 'Content-Length': body.length.toString() - , 'Content-Type': 'text/plain' - }); +var server = http.createServer(function(req, res) { + res.writeHeader(200, + {'Content-Length': body.length.toString(), + 'Content-Type': 'text/plain' + }); console.log('method: ' + req.method); if (req.method != 'HEAD') res.write(body); res.end(); @@ -21,13 +22,13 @@ var gotEnd = false; server.addListener('listening', function() { var client = http.createClient(common.PORT); - var request = client.request("HEAD", "/"); - request.addListener('response', function (response) { + var request = client.request('HEAD', '/'); + request.addListener('response', function(response) { console.log('got response'); - response.addListener("data", function () { + response.addListener('data', function() { process.exit(2); }); - response.addListener("end", function () { + response.addListener('end', function() { process.exit(0); }); }); diff --git a/test/disabled/test-http-stress.js b/test/disabled/test-http-stress.js index 0b86a3f4da..d424554bf3 100644 --- a/test/disabled/test-http-stress.js +++ b/test/disabled/test-http-stress.js @@ -1,41 +1,42 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); -http = require("http"); +var http = require('http'); var request_count = 1000; var body = '{"ok": true}'; var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/javascript'}); - res.write(body); - res.end(); + res.writeHead(200, {'Content-Type': 'text/javascript'}); + res.write(body); + res.end(); }); server.listen(common.PORT); var requests_ok = 0; var requests_complete = 0; -server.addListener('listening', function () { - for (var i = 0; i < request_count; i++) { - http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) { - requests_complete++; - if (err) { - common.print("-"); - } else { - assert.equal(body, content); - common.print("."); - requests_ok++; - } - if (requests_complete == request_count) { - console.log("\nrequests ok: " + requests_ok); - server.close(); - } - }); - } +server.addListener('listening', function() { + for (var i = 0; i < request_count; i++) { + http.cat('http://localhost:' + common.PORT + '/', 'utf8', + function(err, content) { + requests_complete++; + if (err) { + common.print('-'); + } else { + assert.equal(body, content); + common.print('.'); + requests_ok++; + } + if (requests_complete == request_count) { + console.log('\nrequests ok: ' + requests_ok); + server.close(); + } + }); + } }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(request_count, requests_complete); assert.equal(request_count, requests_ok); }); diff --git a/test/disabled/test-http-tls.js b/test/disabled/test-http-tls.js index b222b0003a..4c720b42d0 100644 --- a/test/disabled/test-http-tls.js +++ b/test/disabled/test-http-tls.js @@ -1,77 +1,84 @@ var common = require('../common'); var assert = require('assert'); -net = require("net"); -http = require("http"); -url = require("url"); -qs = require("querystring"); + +var net = require('net'); +var http = require('http'); +var url = require('url'); +var qs = require('querystring'); var fs = require('fs'); var have_openssl; try { var crypto = require('crypto'); - var dummy_server = http.createServer(function(){}); + var dummy_server = http.createServer(function() {}); dummy_server.setSecure(); - have_openssl=true; + have_openssl = true; } catch (e) { - have_openssl=false; - console.log("Not compiled with OPENSSL support."); + have_openssl = false; + console.log('Not compiled with OPENSSL support.'); process.exit(); } var request_number = 0; var requests_sent = 0; -var server_response = ""; +var server_response = ''; var client_got_eof = false; -var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem", 'ascii'); -var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem", 'ascii'); -var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem", 'ascii'); +var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem', 'ascii'); +var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); +var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -try{ - var credentials = crypto.createCredentials({key:keyPem, cert:certPem, ca:caPem}); +try { + var credentials = crypto.createCredentials( + { key: keyPem, + cert: certPem, + ca: caPem + }); } catch (e) { - console.log("Not compiled with OPENSSL support."); + console.log('Not compiled with OPENSSL support.'); process.exit(); } -var https_server = http.createServer(function (req, res) { +var https_server = http.createServer(function(req, res) { res.id = request_number; req.id = request_number++; var verified = res.connection.verifyPeer(); var peerDN = JSON.stringify(req.connection.getPeerCertificate()); assert.equal(verified, true); - assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' - + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' - + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' - + '/OU=Test TLS Certificate/CN=localhost","valid_from":' - + '"Nov 11 09:52:22 2009 GMT","valid_to":' - + '"Nov 6 09:52:22 2029 GMT",' - + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF"}'); + assert.equal(peerDN, + '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' + + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + + '/OU=Test TLS Certificate/CN=localhost",' + + '"valid_from":"Nov 11 09:52:22 2009 GMT",' + + '"valid_to":"Nov 6 09:52:22 2029 GMT",' + + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:' + + '5A:71:38:52:EC:8A:DF"}'); if (req.id == 0) { - assert.equal("GET", req.method); - assert.equal("/hello", url.parse(req.url).pathname); - assert.equal("world", qs.parse(url.parse(req.url).query).hello); - assert.equal("b==ar", qs.parse(url.parse(req.url).query).foo); + assert.equal('GET', req.method); + assert.equal('/hello', url.parse(req.url).pathname); + assert.equal('world', qs.parse(url.parse(req.url).query).hello); + assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo); } if (req.id == 1) { - assert.equal("POST", req.method); - assert.equal("/quit", url.parse(req.url).pathname); + assert.equal('POST', req.method); + assert.equal('/quit', url.parse(req.url).pathname); } if (req.id == 2) { - assert.equal("foo", req.headers['x-x']); + assert.equal('foo', req.headers['x-x']); } if (req.id == 3) { - assert.equal("bar", req.headers['x-x']); + assert.equal('bar', req.headers['x-x']); this.close(); - //console.log("server closed"); + //console.log('server closed'); } - setTimeout(function () { - res.writeHead(200, {"Content-Type": "text/plain"}); + setTimeout(function() { + res.writeHead(200, {'Content-Type': 'text/plain'}); res.write(url.parse(req.url).pathname); res.end(); }, 1); @@ -80,65 +87,67 @@ var https_server = http.createServer(function (req, res) { https_server.setSecure(credentials); https_server.listen(common.PORT); -https_server.addListener("listening", function() { +https_server.addListener('listening', function() { var c = net.createConnection(common.PORT); - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { + c.addListener('connect', function() { c.setSecure(credentials); }); - c.addListener("secure", function () { - var verified = c.verifyPeer(); - var peerDN = JSON.stringify(c.getPeerCertificate()); - assert.equal(verified, true); - assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' - + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' - + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' - + '/OU=Test TLS Certificate/CN=localhost","valid_from":' - + '"Nov 11 09:52:22 2009 GMT","valid_to":' - + '"Nov 6 09:52:22 2029 GMT",' - + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF"}'); - c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" ); + c.addListener('secure', function() { + var verified = c.verifyPeer(); + var peerDN = JSON.stringify(c.getPeerCertificate()); + assert.equal(verified, true); + assert.equal(peerDN, + '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' + + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + + '/OU=Test TLS Certificate/CN=localhost",' + + '"valid_from":"Nov 11 09:52:22 2009 GMT",' + + '"valid_to":"Nov 6 09:52:22 2029 GMT",' + + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:' + + '5A:71:38:52:EC:8A:DF"}'); + c.write('GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n'); requests_sent += 1; }); - c.addListener("data", function (chunk) { + c.addListener('data', function(chunk) { server_response += chunk; if (requests_sent == 1) { - c.write("POST /quit HTTP/1.1\r\n\r\n"); + c.write('POST /quit HTTP/1.1\r\n\r\n'); requests_sent += 1; } if (requests_sent == 2) { - c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" - +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); + c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' + + 'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n'); c.end(); - assert.equal(c.readyState, "readOnly"); + assert.equal(c.readyState, 'readOnly'); requests_sent += 2; } }); - c.addListener("end", function () { + c.addListener('end', function() { client_got_eof = true; }); - c.addListener("close", function () { - assert.equal(c.readyState, "closed"); + c.addListener('close', function() { + assert.equal(c.readyState, 'closed'); }); }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(4, request_number); assert.equal(4, requests_sent); - var hello = new RegExp("/hello"); + var hello = new RegExp('/hello'); assert.equal(true, hello.exec(server_response) != null); - var quit = new RegExp("/quit"); + var quit = new RegExp('/quit'); assert.equal(true, quit.exec(server_response) != null); assert.equal(true, client_got_eof); diff --git a/test/disabled/test-idle-watcher.js b/test/disabled/test-idle-watcher.js index 6273bd408d..00a4f2928f 100644 --- a/test/disabled/test-idle-watcher.js +++ b/test/disabled/test-idle-watcher.js @@ -1,15 +1,15 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var complete = false; var idle = new process.IdleWatcher(); -idle.callback = function () { +idle.callback = function() { complete = true; idle.stop(); }; idle.setPriority(process.EVMAXPRI); idle.start(); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(complete); }); diff --git a/test/disabled/test-net-fd-passing.js b/test/disabled/test-net-fd-passing.js index fcffa9311d..18d685366d 100644 --- a/test/disabled/test-net-fd-passing.js +++ b/test/disabled/test-net-fd-passing.js @@ -1,34 +1,37 @@ -process.mixin(require("../common")); -net = require("net"); +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); var tests_run = 0; function fdPassingTest(path, port) { - var greeting = "howdy"; - var message = "beep toot"; - var expectedData = ["[greeting] " + greeting, "[echo] " + message]; + var greeting = 'howdy'; + var message = 'beep toot'; + var expectedData = ['[greeting] ' + greeting, '[echo] ' + message]; - var receiverArgs = [common.fixturesDir + "/net-fd-passing-receiver.js", path, greeting]; + var receiverArgs = [common.fixturesDir + '/net-fd-passing-receiver.js', + path, + greeting]; var receiver = process.createChildProcess(process.ARGV[0], receiverArgs); var initializeSender = function() { var fdHighway = new net.Socket(); - fdHighway.addListener("connect", function() { + fdHighway.addListener('connect', function() { var sender = net.createServer(function(socket) { fdHighway.sendFD(socket); socket.flush(); socket.forceClose(); // want to close() the fd, not shutdown() }); - sender.addListener("listening", function() { + sender.addListener('listening', function() { var client = net.createConnection(port); - client.addListener("connect", function() { + client.addListener('connect', function() { client.write(message); }); - client.addListener("data", function(data) { + client.addListener('data', function(data) { assert.equal(expectedData[0], data); if (expectedData.length > 1) { expectedData.shift(); @@ -51,17 +54,17 @@ function fdPassingTest(path, port) { }; - receiver.addListener("output", function(data) { + receiver.addListener('output', function(data) { var initialized = false; - if ((! initialized) && (data == "ready")) { + if ((! initialized) && (data == 'ready')) { initializeSender(); initialized = true; } }); } -fdPassingTest("/tmp/passing-socket-test", 31075); +fdPassingTest('/tmp/passing-socket-test', 31075); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(1, tests_run); }); diff --git a/test/disabled/test-net-tls-pummel.js b/test/disabled/test-net-tls-pummel.js index e8f05d4476..c3ba57fdb4 100644 --- a/test/disabled/test-net-tls-pummel.js +++ b/test/disabled/test-net-tls-pummel.js @@ -1,49 +1,51 @@ var common = require('../common'); var assert = require('assert'); -net = require("net"); -fs=require("fs"); + +var net = require('net'); +var fs = require('fs'); var tests_run = 0; -function tlsTest (port, host, caPem, keyPem, certPem) { +function tlsTest(port, host, caPem, keyPem, certPem) { var N = 50; var count = 0; var sent_final_ping = false; - var server = net.createServer(function (socket) { + var server = net.createServer(function(socket) { assert.equal(true, socket.remoteAddress !== null); assert.equal(true, socket.remoteAddress !== undefined); - if (host === "127.0.0.1") - assert.equal(socket.remoteAddress, "127.0.0.1"); + if (host === '127.0.0.1') + assert.equal(socket.remoteAddress, '127.0.0.1'); else if (host == null) - assert.equal(socket.remoteAddress, "127.0.0.1"); + assert.equal(socket.remoteAddress, '127.0.0.1'); - socket.setEncoding("utf8"); + socket.setEncoding('utf8'); socket.setNoDelay(); socket.timeout = 0; - socket.addListener("data", function (data) { + socket.addListener('data', function(data) { var verified = socket.verifyPeer(); - var peerDN = socket.getPeerCertificate("DNstring"); + var peerDN = socket.getPeerCertificate('DNstring'); assert.equal(verified, 1); - assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," - + "OU=Test TLS Certificate,CN=localhost"); - console.log("server got: " + JSON.stringify(data)); - assert.equal("open", socket.readyState); + assert.equal(peerDN, + 'C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,' + + 'OU=Test TLS Certificate,CN=localhost'); + console.log('server got: ' + JSON.stringify(data)); + assert.equal('open', socket.readyState); assert.equal(true, count <= N); if (/PING/.exec(data)) { - socket.write("PONG"); + socket.write('PONG'); } }); - socket.addListener("end", function () { - assert.equal("writeOnly", socket.readyState); + socket.addListener('end', function() { + assert.equal('writeOnly', socket.readyState); socket.end(); }); - socket.addListener("close", function (had_error) { + socket.addListener('close', function(had_error) { assert.equal(false, had_error); - assert.equal("closed", socket.readyState); + assert.equal('closed', socket.readyState); socket.server.close(); }); }); @@ -53,43 +55,44 @@ function tlsTest (port, host, caPem, keyPem, certPem) { var client = net.createConnection(port, host); - client.setEncoding("utf8"); + client.setEncoding('utf8'); client.setSecure('X509_PEM', caPem, 0, keyPem, caPem); - client.addListener("connect", function () { - assert.equal("open", client.readyState); + client.addListener('connect', function() { + assert.equal('open', client.readyState); var verified = client.verifyPeer(); - var peerDN = client.getPeerCertificate("DNstring"); + var peerDN = client.getPeerCertificate('DNstring'); assert.equal(verified, 1); - assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," - + "OU=Test TLS Certificate,CN=localhost"); - client.write("PING"); + assert.equal(peerDN, + 'C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,' + + 'OU=Test TLS Certificate,CN=localhost'); + client.write('PING'); }); - client.addListener("data", function (data) { - assert.equal("PONG", data); + client.addListener('data', function(data) { + assert.equal('PONG', data); count += 1; - console.log("client got PONG"); + console.log('client got PONG'); if (sent_final_ping) { - assert.equal("readOnly", client.readyState); + assert.equal('readOnly', client.readyState); return; } else { - assert.equal("open", client.readyState); + assert.equal('open', client.readyState); } if (count < N) { - client.write("PING"); + client.write('PING'); } else { sent_final_ping = true; - client.write("PING"); + client.write('PING'); client.end(); } }); - client.addListener("close", function () { - assert.equal(N+1, count); + client.addListener('close', function() { + assert.equal(N + 1, count); assert.equal(true, sent_final_ping); tests_run += 1; }); @@ -100,24 +103,24 @@ var have_tls; try { var dummy_server = net.createServer(); dummy_server.setSecure(); - have_tls=true; + have_tls = true; } catch (e) { - have_tls=false; + have_tls = false; } if (have_tls) { - var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem"); - var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem"); - var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem"); + var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem'); + var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem'); + var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem'); /* All are run at once, so run on different ports */ - tlsTest(common.PORT, "localhost", caPem, keyPem, certPem); - tlsTest(common.PORT+1, null, caPem, keyPem, certPem); + tlsTest(common.PORT, 'localhost', caPem, keyPem, certPem); + tlsTest(common.PORT + 1, null, caPem, keyPem, certPem); - process.addListener("exit", function () { + process.addListener('exit', function() { assert.equal(2, tests_run); }); } else { - console.log("Not compiled with TLS support -- skipping test"); + console.log('Not compiled with TLS support -- skipping test'); process.exit(0); } diff --git a/test/disabled/test-net-tls.js b/test/disabled/test-net-tls.js index c40adfd3d0..ff1b819ce1 100644 --- a/test/disabled/test-net-tls.js +++ b/test/disabled/test-net-tls.js @@ -6,56 +6,62 @@ var net = require('net'); var have_openssl; try { var crypto = require('crypto'); - have_openssl=true; + have_openssl = true; } catch (e) { - have_openssl=false; - console.log("Not compiled with OPENSSL support."); + have_openssl = false; + console.log('Not compiled with OPENSSL support.'); process.exit(); } -var caPem = fs.readFileSync(common.fixturesDir+"/test_ca.pem", 'ascii'); -var certPem = fs.readFileSync(common.fixturesDir+"/test_cert.pem", 'ascii'); -var keyPem = fs.readFileSync(common.fixturesDir+"/test_key.pem", 'ascii'); +var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem', 'ascii'); +var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); +var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -try{ - var credentials = crypto.createCredentials({key:keyPem, cert:certPem, ca:caPem}); +try { + var credentials = crypto.createCredentials( + { key: keyPem, + cert: certPem, + ca: caPem + }); } catch (e) { - console.log("Not compiled with OPENSSL support."); + console.log('Not compiled with OPENSSL support.'); process.exit(); } -var testData = "TEST123"; +var testData = 'TEST123'; var serverData = ''; var clientData = ''; var gotSecureServer = false; var gotSecureClient = false; -var secureServer = net.createServer(function (connection) { +var secureServer = net.createServer(function(connection) { var self = this; connection.setSecure(credentials); - connection.setEncoding("UTF8"); + connection.setEncoding('UTF8'); - connection.addListener("secure", function () { + connection.addListener('secure', function() { gotSecureServer = true; var verified = connection.verifyPeer(); var peerDN = JSON.stringify(connection.getPeerCertificate()); assert.equal(verified, true); - assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' - + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' - + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' - + '/OU=Test TLS Certificate/CN=localhost","valid_from":' - + '"Nov 11 09:52:22 2009 GMT","valid_to":' - + '"Nov 6 09:52:22 2029 GMT",' - + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF"}'); + assert.equal(peerDN, + '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' + + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + + '/OU=Test TLS Certificate/CN=localhost",' + + '"valid_from":"Nov 11 09:52:22 2009 GMT",' + + '"valid_to":"Nov 6 09:52:22 2029 GMT",' + + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:' + + '5A:71:38:52:EC:8A:DF"}'); }); - connection.addListener("data", function (chunk) { + connection.addListener('data', function(chunk) { serverData += chunk; connection.write(chunk); }); - connection.addListener("end", function () { + connection.addListener('end', function() { assert.equal(serverData, testData); connection.end(); self.close(); @@ -63,41 +69,43 @@ var secureServer = net.createServer(function (connection) { }); secureServer.listen(common.PORT); -secureServer.addListener("listening", function() { +secureServer.addListener('listening', function() { var secureClient = net.createConnection(common.PORT); - secureClient.setEncoding("UTF8"); - secureClient.addListener("connect", function () { + secureClient.setEncoding('UTF8'); + secureClient.addListener('connect', function() { secureClient.setSecure(credentials); }); - secureClient.addListener("secure", function () { + secureClient.addListener('secure', function() { gotSecureClient = true; var verified = secureClient.verifyPeer(); var peerDN = JSON.stringify(secureClient.getPeerCertificate()); assert.equal(verified, true); - assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' - + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' - + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' - + '/OU=Test TLS Certificate/CN=localhost","valid_from":' - + '"Nov 11 09:52:22 2009 GMT","valid_to":' - + '"Nov 6 09:52:22 2029 GMT",' - + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF"}'); + assert.equal(peerDN, + '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' + + '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + + '/OU=Test TLS Certificate/CN=localhost",' + + '"valid_from":"Nov 11 09:52:22 2009 GMT",' + + '"valid_to":"Nov 6 09:52:22 2029 GMT",' + + '"fingerprint":"2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:' + + '5A:71:38:52:EC:8A:DF"}'); secureClient.write(testData); secureClient.end(); }); - secureClient.addListener("data", function (chunk) { + secureClient.addListener('data', function(chunk) { clientData += chunk; }); - secureClient.addListener("end", function () { + secureClient.addListener('end', function() { assert.equal(clientData, testData); }); }); -process.addListener("exit", function () { - assert.ok(gotSecureServer, "Did not get secure event for server"); - assert.ok(gotSecureClient, "Did not get secure event for clientr"); +process.addListener('exit', function() { + assert.ok(gotSecureServer, 'Did not get secure event for server'); + assert.ok(gotSecureClient, 'Did not get secure event for client'); }); diff --git a/test/disabled/test-process-title.js b/test/disabled/test-process-title.js index d09bd60d1d..c7c96687f7 100644 --- a/test/disabled/test-process-title.js +++ b/test/disabled/test-process-title.js @@ -1,5 +1,5 @@ -var common = require("../common"); -var assert = common.assert; +var common = require('../common'); +var assert = require('assert'); var spawn = require('child_process').spawn; if (process.title === '') { @@ -16,11 +16,11 @@ function verifyProcessName(str, callback) { var buf = ''; ps = spawn('ps'); ps.stdout.setEncoding('utf8'); - ps.stdout.addListener("data", function (s) { buf += s; }); - ps.addListener("exit", function (c) { + ps.stdout.addListener('data', function(s) { buf += s; }); + ps.addListener('exit', function(c) { try { assert.equal(0, c); - assert.ok(new RegExp(process.pid+' ', 'm').test(buf)); + assert.ok(new RegExp(process.pid + ' ', 'm').test(buf)); assert.ok(new RegExp(str, 'm').test(buf)); callback(); } catch (err) { @@ -29,10 +29,10 @@ function verifyProcessName(str, callback) { }); } -verifyProcessName("3kd023mslkfp--unique-string--sksdf", function(err){ +verifyProcessName('3kd023mslkfp--unique-string--sksdf', function(err) { if (err) throw err; console.log('title is now %j', process.title); - verifyProcessName("3kd023mslxxx--unique-string--xxx", function(err){ + verifyProcessName('3kd023mslxxx--unique-string--xxx', function(err) { if (err) throw err; console.log('title is now %j', process.title); }); diff --git a/test/disabled/test-readline.js b/test/disabled/test-readline.js index 23b4595b3e..05a8e800fd 100644 --- a/test/disabled/test-readline.js +++ b/test/disabled/test-readline.js @@ -1,8 +1,8 @@ // Can't test this when 'make test' doesn't assign a tty to the stdout. // Yet another use-case for require('tty').spawn ? var common = require('../common'); -var assert = require('assert');; -var readline = require("readline"); +var assert = require('assert'); +var readline = require('readline'); var key = { xterm: { @@ -28,13 +28,15 @@ var key = { var readlineFakeStream = function() { var written_bytes = []; - var rl = readline.createInterface({ - fd: 1, - write: function(b) { - written_bytes.push(b); - }}, function (text) { - return [[], ""]; - }); + var rl = readline.createInterface( + { fd: 1, + write: function(b) { + written_bytes.push(b); + } + }, + function(text) { + return [[], '']; + }); rl.written_bytes = written_bytes; return rl; }; @@ -68,7 +70,7 @@ written_bytes_length = rl.written_bytes.length; rl.write(key.xterm.metaf); assert.equal(3, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; -assert.equal(true, refreshed); +assert.equal(true, refreshed); rl.write(key.xterm.metaf); assert.equal(7, rl.cursor); rl.write(key.xterm.metaf); @@ -77,12 +79,12 @@ written_bytes_length = rl.written_bytes.length; rl.write(key.xterm.metaf); assert.equal(15, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; -assert.equal(true, refreshed); +assert.equal(true, refreshed); written_bytes_length = rl.written_bytes.length; rl.write(key.xterm.metab); assert.equal(12, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; -assert.equal(true, refreshed); +assert.equal(true, refreshed); rl.write(key.xterm.metab); assert.equal(8, rl.cursor); rl.write(key.xterm.metab); @@ -91,7 +93,7 @@ written_bytes_length = rl.written_bytes.length; rl.write(key.xterm.metab); assert.equal(0, rl.cursor); refreshed = written_bytes_length !== rl.written_bytes.length; -assert.equal(true, refreshed); +assert.equal(true, refreshed); rl = readlineFakeStream(); rl.write('foo bar.hop/zoo'); diff --git a/test/disabled/test-remote-module-loading.js b/test/disabled/test-remote-module-loading.js index 073e487bf0..f5bb11c8db 100644 --- a/test/disabled/test-remote-module-loading.js +++ b/test/disabled/test-remote-module-loading.js @@ -1,32 +1,32 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var http = require('http'); var util = require('util'); -var url = require("url"); +var url = require('url'); var modulesLoaded = 0; var server = http.createServer(function(req, res) { - var body = 'exports.httpPath = function() {'+ - 'return '+JSON.stringify(url.parse(req.url).pathname)+';'+ + var body = 'exports.httpPath = function() {' + + 'return ' + JSON.stringify(url.parse(req.url).pathname) + ';' + '};'; - res.writeHead(200, {'Content-Type': 'text/javascript'}); res.write(body); res.end(); }); server.listen(common.PORT); -assert.throws(function () { - var httpModule = require('http://localhost:'+common.PORT+'/moduleA.js'); +assert.throws(function() { + var httpModule = require('http://localhost:' + common.PORT + '/moduleA.js'); assert.equal('/moduleA.js', httpModule.httpPath()); modulesLoaded++; }); var nodeBinary = process.ARGV[0]; -var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+common.PORT+'/moduleB.js'; +var cmd = 'NODE_PATH=' + common.libDir + ' ' + nodeBinary + + ' http://localhost:' + common.PORT + '/moduleB.js'; -util.exec(cmd, function (err, stdout, stderr) { +util.exec(cmd, function(err, stdout, stderr) { if (err) throw err; console.log('success!'); modulesLoaded++; diff --git a/test/disabled/test-setuidgid.js b/test/disabled/test-setuidgid.js index 54cb20285a..a2d24ae913 100644 --- a/test/disabled/test-setuidgid.js +++ b/test/disabled/test-setuidgid.js @@ -1,6 +1,5 @@ // Requires special privlages var common = require('../common'); -var assert = require('assert');; var assert = require('assert'); var oldgid = process.getgid(); @@ -16,9 +15,8 @@ assert.notEqual(newuid, olduid, 'uids expected to be different'); try { process.setuid('nobody1234'); } catch (e) { - assert.equal( - e.message, - 'failed to resolve group', - 'unexpected error message' + assert.equal(e.message, + 'failed to resolve group', + 'unexpected error message' ); } diff --git a/test/disabled/test-tls-server.js b/test/disabled/test-tls-server.js index 394bc9201b..1e6594db88 100644 --- a/test/disabled/test-tls-server.js +++ b/test/disabled/test-tls-server.js @@ -1,29 +1,31 @@ // Example of new TLS API. Test with: // -// openssl s_client -connect localhost:12346 -key test/fixtures/agent.key -cert test/fixtures/agent.crt -// openssl s_client -connect localhost:12346 +// $> openssl s_client -connect localhost:12346 \ +// -key test/fixtures/agent.key -cert test/fixtures/agent.crt +// +// $> openssl s_client -connect localhost:12346 // var common = require('../common'); var tls = require('tls'); var fs = require('fs'); var join = require('path').join; -var key = fs.readFileSync(join(common.fixturesDir, "agent.key")).toString(); -var cert = fs.readFileSync(join(common.fixturesDir, "agent.crt")).toString(); +var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); +var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); -s = tls.Server({ key: key, cert: cert, unauthorizedPeers: false }); +s = tls.Server({key: key, cert: cert, unauthorizedPeers: false}); -s.listen(common.PORT, function () { - console.log("TLS server on 127.0.0.1:%d", common.PORT); +s.listen(common.PORT, function() { + console.log('TLS server on 127.0.0.1:%d', common.PORT); }); -s.on('authorized', function (c) { - console.log("authed connection"); - c.end("bye authorized friend.\n"); +s.on('authorized', function(c) { + console.log('authed connection'); + c.end('bye authorized friend.\n'); }); -s.on('unauthorized', function (c, e) { - console.log("unauthed connection: %s", e); - c.end("bye unauthorized person.\n"); +s.on('unauthorized', function(c, e) { + console.log('unauthed connection: %s', e); + c.end('bye unauthorized person.\n'); }); diff --git a/test/disabled/tls_client.js b/test/disabled/tls_client.js index 903999dfdb..81b10f556f 100644 --- a/test/disabled/tls_client.js +++ b/test/disabled/tls_client.js @@ -1,42 +1,43 @@ var common = require('../common'); -var assert = require('assert');; -var util=require('util'); -var net=require('net'); -var fs=require('fs'); -var crypto=require('crypto'); +var assert = require('assert'); -//var client = net.createConnection(4443, "localhost"); -var client = net.createConnection(443, "www.microsoft.com"); -//var client = net.createConnection(443, "www.google.com"); +var util = require('util'); +var net = require('net'); +var fs = require('fs'); +var crypto = require('crypto'); -var caPem = fs.readFileSync(common.fixturesDir+"/msca.pem"); -//var caPem = fs.readFileSync("ca.pem"); +//var client = net.createConnection(4443, 'localhost'); +var client = net.createConnection(443, 'www.microsoft.com'); +//var client = net.createConnection(443, 'www.google.com'); -try{ - var credentials = crypto.createCredentials({ca:caPem}); +var caPem = fs.readFileSync(common.fixturesDir + '/msca.pem'); +//var caPem = fs.readFileSync('ca.pem'); + +try { + var credentials = crypto.createCredentials({ca: caPem}); } catch (e) { - console.log("Not compiled with OPENSSL support."); + console.log('Not compiled with OPENSSL support.'); process.exit(); } -client.setEncoding("UTF8"); -client.addListener("connect", function () { - console.log("client connected."); +client.setEncoding('UTF8'); +client.addListener('connect', function() { + console.log('client connected.'); client.setSecure(credentials); }); -client.addListener("secure", function () { - console.log("client secure : "+JSON.stringify(client.getCipher())); +client.addListener('secure', function() { + console.log('client secure : ' + JSON.stringify(client.getCipher())); console.log(JSON.stringify(client.getPeerCertificate())); - console.log("verifyPeer : "+client.verifyPeer()); - client.write("GET / HTTP/1.0\r\n\r\n"); + console.log('verifyPeer : ' + client.verifyPeer()); + client.write('GET / HTTP/1.0\r\n\r\n'); }); -client.addListener("data", function (chunk) { +client.addListener('data', function(chunk) { common.error(chunk); }); -client.addListener("end", function () { - console.log("client disconnected."); +client.addListener('end', function() { + console.log('client disconnected.'); }); diff --git a/test/disabled/tls_server.js b/test/disabled/tls_server.js index 0dc5e7f662..899c0cc789 100644 --- a/test/disabled/tls_server.js +++ b/test/disabled/tls_server.js @@ -1,37 +1,42 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); -var util=require('util'); -var net=require('net'); -var fs=require('fs'); -var crypto=require('crypto'); +var util = require('util'); +var net = require('net'); +var fs = require('fs'); +var crypto = require('crypto'); -var keyPem = fs.readFileSync(common.fixturesDir + "/cert.pem"); -var certPem = fs.readFileSync(common.fixturesDir + "/cert.pem"); +var keyPem = fs.readFileSync(common.fixturesDir + '/cert.pem'); +var certPem = fs.readFileSync(common.fixturesDir + '/cert.pem'); -try{ - var credentials = crypto.createCredentials({key:keyPem, cert:certPem}); +try { + var credentials = crypto.createCredentials({key: keyPem, cert: certPem}); } catch (e) { - console.log("Not compiled with OPENSSL support."); + console.log('Not compiled with OPENSSL support.'); process.exit(); } var i = 0; -var server = net.createServer(function (connection) { +var server = net.createServer(function(connection) { connection.setSecure(credentials); - connection.setEncoding("binary"); + connection.setEncoding('binary'); - connection.addListener("secure", function () { - //console.log("Secure"); + connection.addListener('secure', function() { + //console.log('Secure'); }); - connection.addListener("data", function (chunk) { - console.log("recved: " + JSON.stringify(chunk)); - connection.write("HTTP/1.0 200 OK\r\nContent-type: text/plain\r\nContent-length: 9\r\n\r\nOK : "+i+"\r\n\r\n"); - i=i+1; + connection.addListener('data', function(chunk) { + console.log('recved: ' + JSON.stringify(chunk)); + connection.write('HTTP/1.0 200 OK\r\n' + + 'Content-type: text/plain\r\n' + + 'Content-length: 9\r\n' + + '\r\n' + + 'OK : ' + i + + '\r\n\r\n'); + i = i + 1; connection.end(); }); - connection.addListener("end", function () { + connection.addListener('end', function() { connection.end(); }); diff --git a/test/fixtures/echo.js b/test/fixtures/echo.js index 748b83bf22..bcc2ddfe09 100644 --- a/test/fixtures/echo.js +++ b/test/fixtures/echo.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); common.print('hello world\r\n'); diff --git a/test/fixtures/print-chars-from-buffer.js b/test/fixtures/print-chars-from-buffer.js index e742e6e36f..e3b5647d6e 100644 --- a/test/fixtures/print-chars-from-buffer.js +++ b/test/fixtures/print-chars-from-buffer.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var n = parseInt(process.argv[2]); diff --git a/test/message/undefined_reference_in_new_context.js b/test/message/undefined_reference_in_new_context.js index 67fe9be494..f8f6938806 100644 --- a/test/message/undefined_reference_in_new_context.js +++ b/test/message/undefined_reference_in_new_context.js @@ -1,5 +1,5 @@ -common = require('../common'); -assert = common.assert; +var common = require('../common'); +var assert = require('assert'); common.error('before'); diff --git a/test/pummel/test-child-process-spawn-loop.js b/test/pummel/test-child-process-spawn-loop.js index b36a132083..d619151347 100644 --- a/test/pummel/test-child-process-spawn-loop.js +++ b/test/pummel/test-child-process-spawn-loop.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var spawn = require('child_process').spawn; diff --git a/test/pummel/test-http-client-reconnect-bug.js b/test/pummel/test-http-client-reconnect-bug.js index a85e1e93b3..3b102fc0f6 100644 --- a/test/pummel/test-http-client-reconnect-bug.js +++ b/test/pummel/test-http-client-reconnect-bug.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'), util = require('util'), diff --git a/test/pummel/test-keep-alive.js b/test/pummel/test-keep-alive.js index d39ddc24c8..0a9dc980d8 100644 --- a/test/pummel/test-keep-alive.js +++ b/test/pummel/test-keep-alive.js @@ -1,6 +1,6 @@ // This test requires the program 'ab' var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var http = require('http'); var exec = require('child_process').exec; diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js index b59808e2e8..1fd2bd13f9 100644 --- a/test/pummel/test-net-many-clients.js +++ b/test/pummel/test-net-many-clients.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'); // settings diff --git a/test/pummel/test-net-pause.js b/test/pummel/test-net-pause.js index de101d0ba2..2ecb5285cd 100644 --- a/test/pummel/test-net-pause.js +++ b/test/pummel/test-net-pause.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = common.assert; +var assert = require('assert'); var net = require('net'); var N = 200; diff --git a/test/pummel/test-net-pingpong-delay.js b/test/pummel/test-net-pingpong-delay.js index a30a6942e4..215d712f47 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'); diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index f2d8903d26..208e69b573 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'); var tests_run = 0; diff --git a/test/pummel/test-net-throttle.js b/test/pummel/test-net-throttle.js index 02005d0e9a..e1e0eb8a30 100644 --- a/test/pummel/test-net-throttle.js +++ b/test/pummel/test-net-throttle.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'); var N = 160 * 1024; // 30kb diff --git a/test/pummel/test-net-timeout.js b/test/pummel/test-net-timeout.js index 68650f178e..9a5f6f470a 100644 --- a/test/pummel/test-net-timeout.js +++ b/test/pummel/test-net-timeout.js @@ -1,5 +1,5 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var net = require('net'); var exchanges = 0; @@ -18,8 +18,9 @@ var echo_server = net.createServer(function(socket) { }); socket.addListener('error', function(e) { - throw new Error('Server side socket should not get error. We disconnect willingly.'); - }) + throw new Error('Server side socket should not get error. ' + + 'We disconnect willingly.'); + }); socket.addListener('data', function(d) { console.log(d); diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 3cc8777e2a..2a752adf30 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -46,33 +46,33 @@ setInterval(function() { // Single param: -setTimeout(function(param){ +setTimeout(function(param) { assert.equal('test param', param); }, 1000, 'test param'); var interval_count2 = 0; -setInterval(function(param){ +setInterval(function(param) { ++interval_count2; assert.equal('test param', param); - if(interval_count2 == 3) + if (interval_count2 == 3) clearInterval(this); }, 1000, 'test param'); // Multiple param -setTimeout(function(param1, param2){ +setTimeout(function(param1, param2) { assert.equal('param1', param1); assert.equal('param2', param2); }, 1000, 'param1', 'param2'); var interval_count3 = 0; -setInterval(function(param1, param2){ +setInterval(function(param1, param2) { ++interval_count3; assert.equal('param1', param1); assert.equal('param2', param2); - if(interval_count3 == 3) + if (interval_count3 == 3) clearInterval(this); }, 1000, 'param1', 'param2'); @@ -86,7 +86,7 @@ var interval4 = setInterval(function() { // we should be able to clearTimeout multiple times without breakage. var expectedTimeouts = 3; -function t () { +function t() { expectedTimeouts--; } diff --git a/test/pummel/test-watch-file.js b/test/pummel/test-watch-file.js index f38e660e06..05eb60ed6e 100644 --- a/test/pummel/test-watch-file.js +++ b/test/pummel/test-watch-file.js @@ -10,7 +10,7 @@ var f2 = path.join(common.fixturesDir, 'x2.txt'); console.log('watching for changes of ' + f); var changes = 0; -function watchFile () { +function watchFile() { fs.watchFile(f, function(curr, prev) { console.log(f + ' change'); changes++; diff --git a/test/simple/test-http-1.0.js b/test/simple/test-http-1.0.js index c3ab565ff0..43c3f7535d 100644 --- a/test/simple/test-http-1.0.js +++ b/test/simple/test-http-1.0.js @@ -1,44 +1,44 @@ var common = require('../common'); var assert = require('assert'); -var net = require("net"); -var http = require("http"); +var net = require('net'); +var http = require('http'); -var body = "hello world\n"; -var server_response = ""; +var body = 'hello world\n'; +var server_response = ''; var client_got_eof = false; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { assert.equal('1.0', req.httpVersion); assert.equal(1, req.httpVersionMajor); assert.equal(0, req.httpVersionMinor); - res.writeHead(200, {"Content-Type": "text/plain"}); + res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(body); -}) +}); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { - c.write( "GET / HTTP/1.0\r\n\r\n" ); + c.addListener('connect', function() { + c.write('GET / HTTP/1.0\r\n\r\n'); }); - c.addListener("data", function (chunk) { + c.addListener('data', function(chunk) { console.log(chunk); server_response += chunk; }); - c.addListener("end", function () { + c.addListener('end', function() { client_got_eof = true; c.end(); server.close(); }); }); -process.addListener("exit", function () { - var m = server_response.split("\r\n\r\n"); +process.addListener('exit', function() { + var m = server_response.split('\r\n\r\n'); assert.equal(m[1], body); assert.equal(true, client_got_eof); }); diff --git a/test/simple/test-http-304.js b/test/simple/test-http-304.js index 563da13b5f..a2cc95e57d 100644 --- a/test/simple/test-http-304.js +++ b/test/simple/test-http-304.js @@ -4,18 +4,19 @@ var assert = require('assert'); var http = require('http'); var childProcess = require('child_process'); -var s = http.createServer(function (request, response) { +var s = http.createServer(function(request, response) { response.writeHead(304); response.end(); }); -s.listen(common.PORT, function () { - childProcess.exec('curl -i http://127.0.0.1:'+common.PORT+'/', function (err, stdout, stderr) { - if (err) throw err; - s.close(); - common.error('curled response correctly'); - common.error(common.inspect(stdout)); - }); +s.listen(common.PORT, function() { + childProcess.exec('curl -i http://127.0.0.1:' + common.PORT + '/', + function(err, stdout, stderr) { + if (err) throw err; + s.close(); + common.error('curled response correctly'); + common.error(common.inspect(stdout)); + }); }); -console.log('Server running at http://127.0.0.1:'+common.PORT+'/') +console.log('Server running at http://127.0.0.1:' + common.PORT + '/'); diff --git a/test/simple/test-http-allow-req-after-204-res.js b/test/simple/test-http-allow-req-after-204-res.js index 6139c6f489..c7882610d6 100644 --- a/test/simple/test-http-allow-req-after-204-res.js +++ b/test/simple/test-http-allow-req-after-204-res.js @@ -3,12 +3,12 @@ var http = require('http'); var assert = require('assert'); // first 204 or 304 works, subsequent anything fails -var codes = [ 204, 200 ]; +var codes = [204, 200]; // Methods don't really matter, but we put in something realistic. var methods = ['DELETE', 'DELETE']; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { var code = codes.shift(); assert.equal('number', typeof code); assert.ok(code > 0); @@ -21,13 +21,13 @@ var client = http.createClient(common.PORT); function nextRequest() { var method = methods.shift(); - console.error("writing request: %s", method); + console.error('writing request: %s', method); var request = client.request(method, '/'); - request.on('response', function (response) { + request.on('response', function(response) { response.on('end', function() { if (methods.length == 0) { - console.error("close server"); + console.error('close server'); server.close(); } else { // throws error: diff --git a/test/simple/test-http-blank-header.js b/test/simple/test-http-blank-header.js index 3cc4d190d6..dd8091fecb 100644 --- a/test/simple/test-http-blank-header.js +++ b/test/simple/test-http-blank-header.js @@ -5,43 +5,43 @@ var net = require('net'); var gotReq = false; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { common.error('got req'); gotReq = true; assert.equal('GET', req.method); assert.equal('/blah', req.url); assert.deepEqual({ - host: "mapdevel.trolologames.ru:443", - origin: "http://mapdevel.trolologames.ru", - cookie: "", + host: 'mapdevel.trolologames.ru:443', + origin: 'http://mapdevel.trolologames.ru', + cookie: '' }, req.headers); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var c = net.createConnection(common.PORT); - c.addListener('connect', function () { + c.addListener('connect', function() { common.error('client wrote message'); - c.write( "GET /blah HTTP/1.1\r\n" - + "Host: mapdevel.trolologames.ru:443\r\n" - + "Cookie:\r\n" - + "Origin: http://mapdevel.trolologames.ru\r\n" - + "\r\n\r\nhello world" - ); + c.write('GET /blah HTTP/1.1\r\n' + + 'Host: mapdevel.trolologames.ru:443\r\n' + + 'Cookie:\r\n' + + 'Origin: http://mapdevel.trolologames.ru\r\n' + + '\r\n\r\nhello world' + ); }); - c.addListener('end', function () { + c.addListener('end', function() { c.end(); }); - c.addListener('close', function () { + c.addListener('close', function() { common.error('client close'); server.close(); }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(gotReq); }); diff --git a/test/simple/test-http-buffer-sanity.js b/test/simple/test-http-buffer-sanity.js index c25a79d5c6..57a813f8a3 100644 --- a/test/simple/test-http-buffer-sanity.js +++ b/test/simple/test-http-buffer-sanity.js @@ -12,15 +12,15 @@ for (var i = 0; i < buffer.length; i++) { } -var web = http.Server(function (req, res) { +var web = http.Server(function(req, res) { web.close(); console.log(req.headers); var i = 0; - req.on('data', function (d) { - process.stdout.write(","); + req.on('data', function(d) { + process.stdout.write(','); measuredSize += d.length; for (var j = 0; j < d.length; j++) { assert.equal(buffer[i], d[j]); @@ -29,40 +29,40 @@ var web = http.Server(function (req, res) { }); - req.on('end', function () { + req.on('end', function() { res.writeHead(200); - res.write("thanks"); + res.write('thanks'); res.end(); - console.log("response with 'thanks'"); + console.log('response with \'thanks\''); }); - req.connection.on('error', function (e) { - console.log("http server-side error: " + e.message); + req.connection.on('error', function(e) { + console.log('http server-side error: ' + e.message); process.exit(1); }); }); var gotThanks = false; -web.listen(common.PORT, function () { - console.log("Making request"); +web.listen(common.PORT, function() { + console.log('Making request'); var client = http.createClient(common.PORT); var req = client.request('GET', '/', { 'content-length': buffer.length }); req.end(buffer); - req.on('response', function (res) { + req.on('response', function(res) { console.log('Got response'); res.setEncoding('utf8'); - res.on('data', function (string) { - assert.equal("thanks", string); + res.on('data', function(string) { + assert.equal('thanks', string); gotThanks = true; }); }); }); -process.on('exit', function () { +process.on('exit', function() { assert.equal(bufferSize, measuredSize); assert.ok(gotThanks); }); diff --git a/test/simple/test-http-cat.js b/test/simple/test-http-cat.js index f967b2ed2e..2ab7618606 100644 --- a/test/simple/test-http-cat.js +++ b/test/simple/test-http-cat.js @@ -1,13 +1,13 @@ -var common = require("../common"); +var common = require('../common'); var assert = require('assert'); -var http = require("http"); +var http = require('http'); -var body = "exports.A = function() { return 'A';}"; -var server = http.createServer(function (req, res) { - console.log("got request"); +var body = 'exports.A = function() { return "A";}'; +var server = http.createServer(function(req, res) { + console.log('got request'); res.writeHead(200, [ - ["Content-Length", body.length], - ["Content-Type", "text/plain"] + ['Content-Length', body.length], + ['Content-Type', 'text/plain'] ]); res.end(body); }); @@ -15,28 +15,29 @@ var server = http.createServer(function (req, res) { var got_good_server_content = false; var bad_server_got_error = false; -server.listen(common.PORT, function () { - http.cat("http://localhost:"+common.PORT+"/", "utf8", function (err, content) { - if (err) { - throw err; - } else { - console.log("got response"); - got_good_server_content = true; - assert.equal(body, content); - server.close(); - } - }); +server.listen(common.PORT, function() { + http.cat('http://localhost:' + common.PORT + '/', 'utf8', + function(err, content) { + if (err) { + throw err; + } else { + console.log('got response'); + got_good_server_content = true; + assert.equal(body, content); + server.close(); + } + }); - http.cat("http://localhost:12312/", "utf8", function (err, content) { + http.cat('http://localhost:12312/', 'utf8', function(err, content) { if (err) { - console.log("got error (this should happen)"); + console.log('got error (this should happen)'); bad_server_got_error = true; } }); }); -process.addListener("exit", function () { - console.log("exit"); +process.addListener('exit', function() { + console.log('exit'); assert.equal(true, got_good_server_content); assert.equal(true, bad_server_got_error); }); diff --git a/test/simple/test-http-chunked.js b/test/simple/test-http-chunked.js index eb8c7ab63a..4801d54d58 100644 --- a/test/simple/test-http-chunked.js +++ b/test/simple/test-http-chunked.js @@ -1,22 +1,31 @@ var common = require('../common'); var assert = require('assert'); -var http = require("http"); +var http = require('http'); -var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、经济现状。"; +var UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' + + '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' + + '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + + '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + + '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + + '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' + + '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + + '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + + '有效的改善了岭南地区落后的政治、经济现状。'; var server = http.createServer(function(req, res) { - res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"}); + res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'}); res.end(UTF8_STRING, 'utf8'); }); server.listen(common.PORT); -server.addListener("listening", function() { - http.cat("http://127.0.0.1:"+common.PORT+"/", "utf8", function (err, data) { - if (err) throw err; - assert.equal('string', typeof data); - console.log('here is the response:'); - assert.equal(UTF8_STRING, data); - console.log(data); - server.close(); - }); +server.addListener('listening', function() { + http.cat('http://127.0.0.1:' + common.PORT + '/', 'utf8', + function(err, data) { + if (err) throw err; + assert.equal('string', typeof data); + console.log('here is the response:'); + assert.equal(UTF8_STRING, data); + console.log(data); + server.close(); + }); }); diff --git a/test/simple/test-http-client-parse-error.js b/test/simple/test-http-client-parse-error.js index d598b31d51..9468bde441 100644 --- a/test/simple/test-http-client-parse-error.js +++ b/test/simple/test-http-client-parse-error.js @@ -1,4 +1,4 @@ -var common = require("../common"); +var common = require('../common'); var assert = require('assert'); var http = require('http'); @@ -8,21 +8,21 @@ var net = require('net'); var srv = net.createServer(function(c) { c.write('bad http - should trigger parse error\r\n'); - console.log("connection"); + console.log('connection'); c.addListener('end', function() { c.end(); }); }); var parseError = false; -srv.listen(common.PORT, '127.0.0.1', function () { +srv.listen(common.PORT, '127.0.0.1', function() { var hc = http.createClient(common.PORT, '127.0.0.1'); hc.request('GET', '/').end(); - hc.on('error', function (e) { - console.log("got error from client"); + hc.on('error', function(e) { + console.log('got error from client'); srv.close(); - assert.ok(e.message.indexOf("Parse Error") >= 0); + assert.ok(e.message.indexOf('Parse Error') >= 0); parseError = true; }); }); diff --git a/test/simple/test-http-client-race-2.js b/test/simple/test-http-client-race-2.js index 97df9ef547..136c02c1ab 100644 --- a/test/simple/test-http-client-race-2.js +++ b/test/simple/test-http-client-race-2.js @@ -1,59 +1,58 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var url = require("url"); +var url = require('url'); // // Slight variation on test-http-client-race to test for another race // condition involving the parsers FreeList used internally by http.Client. // -var body1_s = "1111111111111111"; -var body2_s = "22222"; -var body3_s = "3333333333333333333"; +var body1_s = '1111111111111111'; +var body2_s = '22222'; +var body3_s = '3333333333333333333'; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { var pathname = url.parse(req.url).pathname; var body; switch (pathname) { - case "/1": body = body1_s; break; - case "/2": body = body2_s; break; + case '/1': body = body1_s; break; + case '/2': body = body2_s; break; default: body = body3_s; - }; + } - res.writeHead(200, { "Content-Type": "text/plain" - , "Content-Length": body.length - }); + res.writeHead(200, + {'Content-Type': 'text/plain', 'Content-Length': body.length}); res.end(body); }); server.listen(common.PORT); -var body1 = ""; -var body2 = ""; -var body3 = ""; +var body1 = ''; +var body2 = ''; +var body3 = ''; -server.addListener("listening", function() { +server.addListener('listening', function() { var client = http.createClient(common.PORT); // // Client #1 is assigned Parser #1 // - var req1 = client.request("/1") + var req1 = client.request('/1'); req1.end(); - req1.addListener('response', function (res1) { - res1.setEncoding("utf8"); + req1.addListener('response', function(res1) { + res1.setEncoding('utf8'); - res1.addListener('data', function (chunk) { + res1.addListener('data', function(chunk) { body1 += chunk; }); - res1.addListener('end', function () { + res1.addListener('end', function() { // - // Delay execution a little to allow the "close" event to be processed + // Delay execution a little to allow the 'close' event to be processed // (required to trigger this bug!) // - setTimeout(function () { + setTimeout(function() { // // The bug would introduce itself here: Client #2 would be allocated the // parser that previously belonged to Client #1. But we're not finished @@ -63,24 +62,24 @@ server.addListener("listening", function() { // // At this point, the bug would manifest itself and crash because the - // internal state of the parser was no longer valid for use by Client #1. + // internal state of the parser was no longer valid for use by Client #1 // - var req2 = client.request("/2"); + var req2 = client.request('/2'); req2.end(); - req2.addListener('response', function (res2) { - res2.setEncoding("utf8"); - res2.addListener('data', function (chunk) { body2 += chunk; }); - res2.addListener('end', function () { + req2.addListener('response', function(res2) { + res2.setEncoding('utf8'); + res2.addListener('data', function(chunk) { body2 += chunk; }); + res2.addListener('end', function() { // // Just to be really sure we've covered all our bases, execute a // request using client2. // - var req3 = client2.request("/3"); + var req3 = client2.request('/3'); req3.end(); - req3.addListener('response', function (res3) { - res3.setEncoding("utf8"); - res3.addListener('data', function (chunk) { body3 += chunk }); + req3.addListener('response', function(res3) { + res3.setEncoding('utf8'); + res3.addListener('data', function(chunk) { body3 += chunk }); res3.addListener('end', function() { server.close(); }); }); }); @@ -90,7 +89,7 @@ server.addListener("listening", function() { }); }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(body1_s, body1); assert.equal(body2_s, body2); assert.equal(body3_s, body3); diff --git a/test/simple/test-http-client-race.js b/test/simple/test-http-client-race.js index 6d93201a54..627905e78e 100644 --- a/test/simple/test-http-client-race.js +++ b/test/simple/test-http-client-race.js @@ -1,48 +1,47 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var url = require("url"); +var url = require('url'); -var body1_s = "1111111111111111"; -var body2_s = "22222"; +var body1_s = '1111111111111111'; +var body2_s = '22222'; -var server = http.createServer(function (req, res) { - var body = url.parse(req.url).pathname === "/1" ? body1_s : body2_s; - res.writeHead(200, { "Content-Type": "text/plain" - , "Content-Length": body.length - }); +var server = http.createServer(function(req, res) { + var body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s; + res.writeHead(200, + {'Content-Type': 'text/plain', 'Content-Length': body.length}); res.end(body); }); server.listen(common.PORT); -var body1 = ""; -var body2 = ""; +var body1 = ''; +var body2 = ''; -server.addListener("listening", function() { +server.addListener('listening', function() { var client = http.createClient(common.PORT); - var req1 = client.request("/1") + var req1 = client.request('/1'); req1.end(); - req1.addListener('response', function (res1) { - res1.setEncoding("utf8"); + req1.addListener('response', function(res1) { + res1.setEncoding('utf8'); - res1.addListener('data', function (chunk) { + res1.addListener('data', function(chunk) { body1 += chunk; }); - res1.addListener('end', function () { - var req2 = client.request("/2"); + res1.addListener('end', function() { + var req2 = client.request('/2'); req2.end(); - req2.addListener('response', function (res2) { - res2.setEncoding("utf8"); - res2.addListener('data', function (chunk) { body2 += chunk; }); - res2.addListener('end', function () { server.close(); }); + req2.addListener('response', function(res2) { + res2.setEncoding('utf8'); + res2.addListener('data', function(chunk) { body2 += chunk; }); + res2.addListener('end', function() { server.close(); }); }); }); }); }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(body1_s, body1); assert.equal(body2_s, body2); }); diff --git a/test/simple/test-http-client-upload.js b/test/simple/test-http-client-upload.js index b49235e291..3bd9bed0a9 100644 --- a/test/simple/test-http-client-upload.js +++ b/test/simple/test-http-client-upload.js @@ -2,22 +2,22 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var sent_body = ""; +var sent_body = ''; var server_req_complete = false; var client_res_complete = false; var server = http.createServer(function(req, res) { - assert.equal("POST", req.method); - req.setEncoding("utf8"); + assert.equal('POST', req.method); + req.setEncoding('utf8'); - req.addListener('data', function (chunk) { - console.log("server got: " + JSON.stringify(chunk)); + req.addListener('data', function(chunk) { + console.log('server got: ' + JSON.stringify(chunk)); sent_body += chunk; }); - req.addListener('end', function () { + req.addListener('end', function() { server_req_complete = true; - console.log("request complete from server"); + console.log('request complete from server'); res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello\n'); res.end(); @@ -25,7 +25,7 @@ var server = http.createServer(function(req, res) { }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var client = http.createClient(common.PORT); var req = client.request('POST', '/'); req.write('1\n'); @@ -33,10 +33,10 @@ server.addListener("listening", function() { req.write('3\n'); req.end(); - common.error("client finished sending request"); + common.error('client finished sending request'); req.addListener('response', function(res) { - res.setEncoding("utf8"); + res.setEncoding('utf8'); res.addListener('data', function(chunk) { console.log(chunk); }); @@ -47,8 +47,8 @@ server.addListener("listening", function() { }); }); -process.addListener("exit", function () { - assert.equal("1\n2\n3\n", sent_body); +process.addListener('exit', function() { + assert.equal('1\n2\n3\n', sent_body); assert.equal(true, server_req_complete); assert.equal(true, client_res_complete); }); diff --git a/test/simple/test-http-contentLength0.js b/test/simple/test-http-contentLength0.js index 7e3dca5409..a7e2b5acdc 100644 --- a/test/simple/test-http-contentLength0.js +++ b/test/simple/test-http-contentLength0.js @@ -1,12 +1,13 @@ var common = require('../common'); -var http = require("http"); +var http = require('http'); -// Simple test of Node's HTTP Client choking on a response with a "Content-Length: 0 " response header. -// I.E. a space character after the "Content-Length" throws an `error` event. +// Simple test of Node's HTTP Client choking on a response +// with a 'Content-Length: 0 ' response header. +// I.E. a space character after the 'Content-Length' throws an `error` event. -var s = http.createServer(function(req, res) { - res.writeHead(200, { "Content-Length": "0 " }); +var s = http.createServer(function(req, res) { + res.writeHead(200, {'Content-Length': '0 '}); res.end(); }); s.listen(common.PORT, function() { @@ -14,7 +15,7 @@ s.listen(common.PORT, function() { var r = http.createClient(common.PORT); var request = r.request('GET', '/'); - request.on('response', function (response) { + request.on('response', function(response) { console.log('STATUS: ' + response.statusCode); s.close(); }); diff --git a/test/simple/test-http-curl-chunk-problem.js b/test/simple/test-http-curl-chunk-problem.js index 8c42e152e8..30b8a981f1 100644 --- a/test/simple/test-http-curl-chunk-problem.js +++ b/test/simple/test-http-curl-chunk-problem.js @@ -2,45 +2,46 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'), - cp = require('child_process'); + cp = require('child_process'); var filename = require('path').join(common.tmpDir || '/tmp', 'big'); var count = 0; -function maybeMakeRequest () { +function maybeMakeRequest() { if (++count < 2) return; - console.log("making curl request"); + console.log('making curl request'); cp.exec('curl http://127.0.0.1:' + common.PORT + '/ | shasum', - function (err, stdout, stderr) { - if (err) throw err; - assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', stdout.slice(0, 40)); - console.log("got the correct response"); - server.close(); - }); + function(err, stdout, stderr) { + if (err) throw err; + assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', + stdout.slice(0, 40)); + console.log('got the correct response'); + server.close(); + }); } cp.exec('dd if=/dev/zero of=' + filename + ' bs=1024 count=10240', - function (err, stdout, stderr) { - if (err) throw err; - maybeMakeRequest(); - }); + function(err, stdout, stderr) { + if (err) throw err; + maybeMakeRequest(); + }); -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { res.writeHead(200); // Create the subprocess var cat = cp.spawn('cat', [filename]); // Stream the data through to the response as binary chunks - cat.stdout.on('data', function (data) { + cat.stdout.on('data', function(data) { res.write(data); }); // End the response on exit (and log errors) - cat.on('exit', function (code) { + cat.on('exit', function(code) { if (code !== 0) { console.error('subprocess exited with code ' + code); exit(1); diff --git a/test/simple/test-http-eof-on-connect.js b/test/simple/test-http-eof-on-connect.js index 4a23659faa..9bb5bbb8f0 100644 --- a/test/simple/test-http-eof-on-connect.js +++ b/test/simple/test-http-eof-on-connect.js @@ -7,13 +7,13 @@ var http = require('http'); // It is separate from test-http-malformed-request.js because it is only // reproduceable on the first packet on the first connection to a server. -var server = http.createServer(function (req, res) {}); +var server = http.createServer(function(req, res) {}); server.listen(common.PORT); -server.addListener("listening", function() { - net.createConnection(common.PORT).addListener("connect", function () { +server.addListener('listening', function() { + net.createConnection(common.PORT).addListener('connect', function() { this.destroy(); - }).addListener("close", function () { + }).addListener('close', function() { server.close(); }); }); diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js index 4e711d7ff8..e723496e54 100644 --- a/test/simple/test-http-exceptions.js +++ b/test/simple/test-http-exceptions.js @@ -1,17 +1,17 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var http = require('http'); -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { intentionally_not_defined(); - res.writeHead(200, {"Content-Type": "text/plain"}); - res.write("Thank you, come again."); + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('Thank you, come again.'); res.end(); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var req; - for (var i = 0; i < 4 ; i += 1) { + for (var i = 0; i < 4; i += 1) { req = http.createClient(common.PORT).request('GET', '/busy/' + i); req.end(); } @@ -19,9 +19,9 @@ server.listen(common.PORT, function () { var exception_count = 0; -process.addListener("uncaughtException", function (err) { - console.log("Caught an exception: " + err); - if (err.name === "AssertionError") throw err; +process.addListener('uncaughtException', function(err) { + console.log('Caught an exception: ' + err); + if (err.name === 'AssertionError') throw err; if (++exception_count == 4) process.exit(0); }); diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js index 5b64cee8de..e15918fbfe 100644 --- a/test/simple/test-http-expect-continue.js +++ b/test/simple/test-http-expect-continue.js @@ -1,65 +1,63 @@ -var common = require("../common"); +var common = require('../common'); var assert = require('assert'); -var http = require("http"); +var http = require('http'); var outstanding_reqs = 0; -var test_req_body = "some stuff...\n"; -var test_res_body = "other stuff!\n"; +var test_req_body = 'some stuff...\n'; +var test_res_body = 'other stuff!\n'; var sent_continue = false; var got_continue = false; function handler(req, res) { - assert.equal(sent_continue, true, "Full response sent before 100 Continue"); - common.debug("Server sending full response..."); + assert.equal(sent_continue, true, 'Full response sent before 100 Continue'); + common.debug('Server sending full response...'); res.writeHead(200, { - 'Content-Type' : 'text/plain', - "ABCD" : "1" + 'Content-Type' : 'text/plain', + 'ABCD' : '1' }); res.end(test_res_body); } var server = http.createServer(handler); -server.addListener("checkContinue", function(req, res) { - common.debug("Server got Expect: 100-continue..."); - res.writeContinue(); - sent_continue = true; - handler(req, res); -}); +server.addListener('checkContinue', function(req, res) { + common.debug('Server got Expect: 100-continue...'); + res.writeContinue(); + sent_continue = true; + handler(req, res); +}); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var client = http.createClient(common.PORT); - var req = client.request("POST", "/world", { - "Expect": "100-continue", + var req = client.request('POST', '/world', { + 'Expect': '100-continue' }); - common.debug("Client sending request..."); + common.debug('Client sending request...'); outstanding_reqs++; - var body = ""; - req.addListener('continue', function () { - common.debug("Client got 100 Continue..."); - got_continue = true; - req.end(test_req_body); + var body = ''; + req.addListener('continue', function() { + common.debug('Client got 100 Continue...'); + got_continue = true; + req.end(test_req_body); }); - req.addListener('response', function (res) { - assert.equal(got_continue, true, - "Full response received before 100 Continue" - ); - assert.equal(200, res.statusCode, - "Final status code was " + res.statusCode + ", not 200." - ); - res.setEncoding("utf8"); - res.addListener('data', function (chunk) { body += chunk; }); - res.addListener('end', function () { - common.debug("Got full response."); - assert.equal(body, test_res_body, "Response body doesn't match."); - assert.ok("abcd" in res.headers, "Response headers missing."); + req.addListener('response', function(res) { + assert.equal(got_continue, true, + 'Full response received before 100 Continue'); + assert.equal(200, res.statusCode, + 'Final status code was ' + res.statusCode + ', not 200.'); + res.setEncoding('utf8'); + res.addListener('data', function(chunk) { body += chunk; }); + res.addListener('end', function() { + common.debug('Got full response.'); + assert.equal(body, test_res_body, 'Response body doesn\'t match.'); + assert.ok('abcd' in res.headers, 'Response headers missing.'); outstanding_reqs--; if (outstanding_reqs == 0) { server.close(); process.exit(); - } + } }); }); }); diff --git a/test/simple/test-http-full-response.js b/test/simple/test-http-full-response.js index 6a7d77ff63..90c8332821 100644 --- a/test/simple/test-http-full-response.js +++ b/test/simple/test-http-full-response.js @@ -1,20 +1,20 @@ var common = require('../common'); var assert = require('assert'); -// This test requires the program "ab" +// This test requires the program 'ab' var http = require('http'); -var exec = require("child_process").exec; +var exec = require('child_process').exec; var bodyLength = 12345; -var body = ""; +var body = ''; for (var i = 0; i < bodyLength; i++) { body += 'c'; } -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { res.writeHead(200, { - "Content-Length": bodyLength, - "Content-Type": "text/plain" + 'Content-Length': bodyLength, + 'Content-Type': 'text/plain' }); res.end(body); }); @@ -22,11 +22,11 @@ var server = http.createServer(function (req, res) { var runs = 0; function runAb(opts, callback) { - var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/"; - exec(command, function (err, stdout, stderr) { + var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/'; + exec(command, function(err, stdout, stderr) { if (err) { - if (stderr.indexOf("ab") >= 0) { - console.log("ab not installed? skipping test.\n" + stderr); + if (stderr.indexOf('ab') >= 0) { + console.log('ab not installed? skipping test.\n' + stderr); process.reallyExit(0); } process.exit(); @@ -47,19 +47,19 @@ function runAb(opts, callback) { runs++; - if (callback) callback() + if (callback) callback(); }); } -server.listen(common.PORT, function () { - runAb("-c 1 -n 10", function () { - console.log("-c 1 -n 10 okay"); +server.listen(common.PORT, function() { + runAb('-c 1 -n 10', function() { + console.log('-c 1 -n 10 okay'); - runAb("-c 1 -n 100", function () { - console.log("-c 1 -n 100 okay"); + runAb('-c 1 -n 100', function() { + console.log('-c 1 -n 100 okay'); - runAb("-c 1 -n 1000", function () { - console.log("-c 1 -n 1000 okay"); + runAb('-c 1 -n 1000', function() { + console.log('-c 1 -n 1000 okay'); server.close(); }); }); @@ -67,6 +67,6 @@ server.listen(common.PORT, function () { }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(3, runs); }); diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js index 57878d4550..627ede43ce 100644 --- a/test/simple/test-http-head-request.js +++ b/test/simple/test-http-head-request.js @@ -4,30 +4,30 @@ var http = require('http'); var util = require('util'); -var body = "hello world\n"; +var body = 'hello world\n'; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { common.error('req: ' + req.method); - res.writeHead(200, {"Content-Length": body.length}); + res.writeHead(200, {'Content-Length': body.length}); res.end(); server.close(); }); var gotEnd = false; -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var client = http.createClient(common.PORT); - var request = client.request("HEAD", "/"); + var request = client.request('HEAD', '/'); request.end(); - request.addListener('response', function (response) { + request.addListener('response', function(response) { common.error('response start'); - response.addListener("end", function () { + response.addListener('end', function() { common.error('response end'); gotEnd = true; }); }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(gotEnd); }); diff --git a/test/simple/test-http-head-response-has-no-body.js b/test/simple/test-http-head-response-has-no-body.js index 270a5e73e9..17ef4ac95e 100644 --- a/test/simple/test-http-head-response-has-no-body.js +++ b/test/simple/test-http-head-response-has-no-body.js @@ -15,11 +15,11 @@ server.listen(common.PORT); var responseComplete = false; -server.addListener("listening", function() { - var req = http.createClient(common.PORT).request('HEAD', '/') +server.addListener('listening', function() { + var req = http.createClient(common.PORT).request('HEAD', '/'); common.error('req'); req.end(); - req.addListener('response', function (res) { + req.addListener('response', function(res) { common.error('response'); res.addListener('end', function() { common.error('response end'); @@ -29,6 +29,6 @@ server.addListener("listening", function() { }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(responseComplete); }); diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js index 03538b5047..4afe9e2db0 100644 --- a/test/simple/test-http-keep-alive-close-on-header.js +++ b/test/simple/test-http-keep-alive-close-on-header.js @@ -3,45 +3,45 @@ var assert = require('assert'); var http = require('http'); var util = require('util'); -var body = "hello world\n"; -var headers = {'connection':'keep-alive'} +var body = 'hello world\n'; +var headers = {'connection': 'keep-alive'}; -var server = http.createServer(function (req, res) { - res.writeHead(200, {"Content-Length": body.length, "Connection":"close"}); +var server = http.createServer(function(req, res) { + res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'}); res.write(body); res.end(); }); var connectCount = 0; -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var client = http.createClient(common.PORT); - client.addListener("connect", function () { - common.error("CONNECTED") + client.addListener('connect', function() { + common.error('CONNECTED'); connectCount++; - }) + }); - var request = client.request("GET", "/", headers); + var request = client.request('GET', '/', headers); request.end(); - request.addListener('response', function (response) { + request.addListener('response', function(response) { common.error('response start'); - response.addListener("end", function () { + response.addListener('end', function() { common.error('response end'); - var req = client.request("GET", "/", headers); - req.addListener('response', function (response) { - response.addListener("end", function () { + var req = client.request('GET', '/', headers); + req.addListener('response', function(response) { + response.addListener('end', function() { client.end(); server.close(); - }) - }) + }); + }); req.end(); }); }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal(2, connectCount); }); diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js index b44f4d41b9..10e7e8824e 100644 --- a/test/simple/test-http-keep-alive.js +++ b/test/simple/test-http-keep-alive.js @@ -3,45 +3,44 @@ var assert = require('assert'); var http = require('http'); var util = require('util'); -var body = "hello world\n"; -var headers = {'connection':'keep-alive'} +var body = 'hello world\n'; +var headers = {'connection': 'keep-alive'}; -var server = http.createServer(function (req, res) { - res.writeHead(200, {"Content-Length": body.length}); +var server = http.createServer(function(req, res) { + res.writeHead(200, {'Content-Length': body.length}); res.write(body); res.end(); }); var connectCount = 0; -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var client = http.createClient(common.PORT); - client.addListener("connect", function () { - common.error("CONNECTED") + client.addListener('connect', function() { + common.error('CONNECTED'); connectCount++; - }) + }); - var request = client.request("GET", "/", headers); + var request = client.request('GET', '/', headers); request.end(); - request.addListener('response', function (response) { + request.addListener('response', function(response) { common.error('response start'); - - response.addListener("end", function () { + response.addListener('end', function() { common.error('response end'); - var req = client.request("GET", "/", headers); - req.addListener('response', function (response) { - response.addListener("end", function () { + var req = client.request('GET', '/', headers); + req.addListener('response', function(response) { + response.addListener('end', function() { client.end(); server.close(); - }) - }) + }); + }); req.end(); }); }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal(1, connectCount); }); diff --git a/test/simple/test-http-malformed-request.js b/test/simple/test-http-malformed-request.js index db571ac558..cabd328719 100644 --- a/test/simple/test-http-malformed-request.js +++ b/test/simple/test-http-malformed-request.js @@ -2,7 +2,7 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); var http = require('http'); -var url = require("url"); +var url = require('url'); // Make sure no exceptions are thrown when receiving malformed HTTP // requests. @@ -10,27 +10,27 @@ var url = require("url"); var nrequests_completed = 0; var nrequests_expected = 1; -var server = http.createServer(function (req, res) { - console.log("req: " + JSON.stringify(url.parse(req.url))); +var server = http.createServer(function(req, res) { + console.log('req: ' + JSON.stringify(url.parse(req.url))); - res.writeHead(200, {"Content-Type": "text/plain"}); - res.write("Hello World"); + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('Hello World'); res.end(); if (++nrequests_completed == nrequests_expected) server.close(); }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - c.addListener("connect", function () { - c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); + c.addListener('connect', function() { + c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n'); c.end(); }); // TODO add more! }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(nrequests_expected, nrequests_completed); }); diff --git a/test/simple/test-http-parser.js b/test/simple/test-http-parser.js index aa5551a8e6..d9e9cf0a44 100644 --- a/test/simple/test-http-parser.js +++ b/test/simple/test-http-parser.js @@ -8,39 +8,39 @@ var assert = require('assert'); var HTTPParser = process.binding('http_parser').HTTPParser; -var parser = new HTTPParser("request"); +var parser = new HTTPParser('request'); var Buffer = require('buffer').Buffer; var buffer = new Buffer(1024); -var request = "GET /hello HTTP/1.1\r\n\r\n"; +var request = 'GET /hello HTTP/1.1\r\n\r\n'; buffer.write(request, 0, 'ascii'); var callbacks = 0; -parser.onMessageBegin = function () { - console.log("message begin"); +parser.onMessageBegin = function() { + console.log('message begin'); callbacks++; }; -parser.onHeadersComplete = function (info) { - console.log("headers complete: " + JSON.stringify(info)); +parser.onHeadersComplete = function(info) { + console.log('headers complete: ' + JSON.stringify(info)); assert.equal('GET', info.method); assert.equal(1, info.versionMajor); assert.equal(1, info.versionMinor); callbacks++; }; -parser.onURL = function (b, off, len) { - //throw new Error("hello world"); +parser.onURL = function(b, off, len) { + //throw new Error('hello world'); callbacks++; }; -parser.onPath = function (b, off, length) { - console.log("path [" + off + ", " + length + "]"); - var path = b.toString('ascii', off, off+length); - console.log("path = '" + path + "'"); +parser.onPath = function(b, off, length) { + console.log('path [' + off + ', ' + length + ']'); + var path = b.toString('ascii', off, off + length); + console.log('path = "' + path + '"'); assert.equal('/hello', path); callbacks++; }; @@ -53,11 +53,11 @@ assert.equal(4, callbacks); // thrown from parser.execute() // -parser.onURL = function (b, off, len) { - throw new Error("hello world"); +parser.onURL = function(b, off, len) { + throw new Error('hello world'); }; -assert.throws(function () { +assert.throws(function() { parser.execute(buffer, 0, request.length); -}, Error, "hello world"); +}, Error, 'hello world'); diff --git a/test/simple/test-http-proxy.js b/test/simple/test-http-proxy.js index b8e9462885..4e4e38a8a4 100644 --- a/test/simple/test-http-proxy.js +++ b/test/simple/test-http-proxy.js @@ -1,33 +1,35 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var url = require("url"); +var url = require('url'); var PROXY_PORT = common.PORT; -var BACKEND_PORT = common.PORT+1; +var BACKEND_PORT = common.PORT + 1; -var cookies = [ "session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT", - "prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" ]; +var cookies = [ + 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT', + 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT' +]; -var headers = {"content-type": "text/plain", - "set-cookie": cookies, - "hello": "world" }; +var headers = {'content-type': 'text/plain', + 'set-cookie': cookies, + 'hello': 'world' }; -var backend = http.createServer(function (req, res) { - common.debug("backend request"); +var backend = http.createServer(function(req, res) { + common.debug('backend request'); res.writeHead(200, headers); - res.write("hello world\n"); + res.write('hello world\n'); res.end(); }); var proxy_client = http.createClient(BACKEND_PORT); -var proxy = http.createServer(function (req, res) { - common.debug("proxy req headers: " + JSON.stringify(req.headers)); +var proxy = http.createServer(function(req, res) { + common.debug('proxy req headers: ' + JSON.stringify(req.headers)); var proxy_req = proxy_client.request(url.parse(req.url).pathname); proxy_req.end(); proxy_req.addListener('response', function(proxy_res) { - common.debug("proxy res headers: " + JSON.stringify(proxy_res.headers)); + common.debug('proxy res headers: ' + JSON.stringify(proxy_res.headers)); assert.equal('world', proxy_res.headers['hello']); assert.equal('text/plain', proxy_res.headers['content-type']); @@ -35,52 +37,52 @@ var proxy = http.createServer(function (req, res) { res.writeHead(proxy_res.statusCode, proxy_res.headers); - proxy_res.addListener("data", function(chunk) { + proxy_res.addListener('data', function(chunk) { res.write(chunk); }); - proxy_res.addListener("end", function() { + proxy_res.addListener('end', function() { res.end(); - common.debug("proxy res"); + common.debug('proxy res'); }); }); }); -var body = ""; +var body = ''; var nlistening = 0; -function startReq () { +function startReq() { nlistening++; if (nlistening < 2) return; var client = http.createClient(PROXY_PORT); - var req = client.request("/test"); - common.debug("client req") - req.addListener('response', function (res) { - common.debug("got res"); + var req = client.request('/test'); + common.debug('client req'); + req.addListener('response', function(res) { + common.debug('got res'); assert.equal(200, res.statusCode); assert.equal('world', res.headers['hello']); assert.equal('text/plain', res.headers['content-type']); assert.deepEqual(cookies, res.headers['set-cookie']); - res.setEncoding("utf8"); - res.addListener('data', function (chunk) { body += chunk; }); - res.addListener('end', function () { + res.setEncoding('utf8'); + res.addListener('data', function(chunk) { body += chunk; }); + res.addListener('end', function() { proxy.close(); backend.close(); - common.debug("closed both"); + common.debug('closed both'); }); }); req.end(); } -common.debug("listen proxy") +common.debug('listen proxy'); proxy.listen(PROXY_PORT, startReq); -common.debug("listen backend") +common.debug('listen backend'); backend.listen(BACKEND_PORT, startReq); -process.addListener("exit", function () { - assert.equal(body, "hello world\n"); +process.addListener('exit', function() { + assert.equal(body, 'hello world\n'); }); diff --git a/test/simple/test-http-server-multiheaders.js b/test/simple/test-http-server-multiheaders.js index ad609c6ce3..f1fb09e84a 100644 --- a/test/simple/test-http-server-multiheaders.js +++ b/test/simple/test-http-server-multiheaders.js @@ -18,20 +18,19 @@ var srv = http.createServer(function(req, res) { srv.close(); }); -srv.listen(common.PORT, function () { +srv.listen(common.PORT, function() { var hc = http.createClient(common.PORT, 'localhost'); var hr = hc.request('/', - [ - ['accept', 'abc'], - ['accept', 'def'], - ['Accept', 'ghijklmnopqrst'], - ['host', 'foo'], - ['Host', 'bar'], - ['hOst', 'baz'], - ['x-foo', 'bingo'], - ['x-bar', 'banjo'], - ['x-bar', 'bango'] - ] - ); + [ + ['accept', 'abc'], + ['accept', 'def'], + ['Accept', 'ghijklmnopqrst'], + ['host', 'foo'], + ['Host', 'bar'], + ['hOst', 'baz'], + ['x-foo', 'bingo'], + ['x-bar', 'banjo'], + ['x-bar', 'bango'] + ]); hr.end(); }); diff --git a/test/simple/test-http-server.js b/test/simple/test-http-server.js index 1a1525b4fc..969b6d35d6 100644 --- a/test/simple/test-http-server.js +++ b/test/simple/test-http-server.js @@ -2,45 +2,45 @@ var common = require('../common'); var assert = require('assert'); var net = require('net'); var http = require('http'); -var url = require("url"); -var qs = require("querystring"); +var url = require('url'); +var qs = require('querystring'); var request_number = 0; var requests_sent = 0; -var server_response = ""; +var server_response = ''; var client_got_eof = false; -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { res.id = request_number; req.id = request_number++; if (req.id == 0) { - assert.equal("GET", req.method); - assert.equal("/hello", url.parse(req.url).pathname); - assert.equal("world", qs.parse(url.parse(req.url).query).hello); - assert.equal("b==ar", qs.parse(url.parse(req.url).query).foo); + assert.equal('GET', req.method); + assert.equal('/hello', url.parse(req.url).pathname); + assert.equal('world', qs.parse(url.parse(req.url).query).hello); + assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo); } if (req.id == 1) { - common.error("req 1"); - assert.equal("POST", req.method); - assert.equal("/quit", url.parse(req.url).pathname); + common.error('req 1'); + assert.equal('POST', req.method); + assert.equal('/quit', url.parse(req.url).pathname); } if (req.id == 2) { - common.error("req 2"); - assert.equal("foo", req.headers['x-x']); + common.error('req 2'); + assert.equal('foo', req.headers['x-x']); } if (req.id == 3) { - common.error("req 3"); - assert.equal("bar", req.headers['x-x']); + common.error('req 3'); + assert.equal('bar', req.headers['x-x']); this.close(); - common.error("server closed"); + common.error('server closed'); } - setTimeout(function () { - res.writeHead(200, {"Content-Type": "text/plain"}); + setTimeout(function() { + res.writeHead(200, {'Content-Type': 'text/plain'}); res.write(url.parse(req.url).pathname); res.end(); }, 1); @@ -48,51 +48,51 @@ var server = http.createServer(function (req, res) { }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { - c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" ); + c.addListener('connect', function() { + c.write('GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n'); requests_sent += 1; }); - c.addListener("data", function (chunk) { + c.addListener('data', function(chunk) { server_response += chunk; if (requests_sent == 1) { - c.write("POST /quit HTTP/1.1\r\n\r\n"); + c.write('POST /quit HTTP/1.1\r\n\r\n'); requests_sent += 1; } if (requests_sent == 2) { - c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" - +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); + c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' + + 'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n'); c.end(); - assert.equal(c.readyState, "readOnly"); + assert.equal(c.readyState, 'readOnly'); requests_sent += 2; } }); - c.addListener("end", function () { + c.addListener('end', function() { client_got_eof = true; }); - c.addListener("close", function () { - assert.equal(c.readyState, "closed"); + c.addListener('close', function() { + assert.equal(c.readyState, 'closed'); }); }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(4, request_number); assert.equal(4, requests_sent); - var hello = new RegExp("/hello"); + var hello = new RegExp('/hello'); assert.equal(true, hello.exec(server_response) != null); - var quit = new RegExp("/quit"); + var quit = new RegExp('/quit'); assert.equal(true, quit.exec(server_response) != null); assert.equal(true, client_got_eof); diff --git a/test/simple/test-http-set-cookies.js b/test/simple/test-http-set-cookies.js index b99bf05a76..748f96bd25 100644 --- a/test/simple/test-http-set-cookies.js +++ b/test/simple/test-http-set-cookies.js @@ -1,24 +1,24 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var http = require('http'); var nresponses = 0; var server = http.createServer(function(req, res) { if (req.url == '/one') { - res.writeHead(200, [ ['set-cookie', 'A'], - ['content-type', 'text/plain'] ]); - res.end("one\n"); + res.writeHead(200, [['set-cookie', 'A'], + ['content-type', 'text/plain']]); + res.end('one\n'); } else { - res.writeHead(200, [ ['set-cookie', 'A'], - ['set-cookie', 'B'], - ['content-type', 'text/plain'] ]); - res.end("two\n"); + res.writeHead(200, [['set-cookie', 'A'], + ['set-cookie', 'B'], + ['content-type', 'text/plain']]); + res.end('two\n'); } }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { // // one set-cookie header // @@ -66,6 +66,6 @@ server.addListener("listening", function() { }); -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(2, nresponses); }); diff --git a/test/simple/test-http-set-timeout.js b/test/simple/test-http-set-timeout.js index 5e0bae5214..1ae3229cae 100644 --- a/test/simple/test-http-set-timeout.js +++ b/test/simple/test-http-set-timeout.js @@ -1,26 +1,27 @@ var common = require('../common'); -var assert = require('assert');; +var assert = require('assert'); var http = require('http'); -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { console.log('got request. setting 1 second timeout'); req.connection.setTimeout(500); - req.connection.addListener('timeout', function(){ - common.debug("TIMEOUT"); + req.connection.addListener('timeout', function() { + common.debug('TIMEOUT'); server.close(); }); }); -server.listen(common.PORT, function () { - console.log('Server running at http://127.0.0.1:'+common.PORT+'/'); +server.listen(common.PORT, function() { + console.log('Server running at http://127.0.0.1:' + common.PORT + '/'); - var errorTimer = setTimeout(function () { + var errorTimer = setTimeout(function() { throw new Error('Timeout was not sucessful'); }, 2000); - http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) { - clearTimeout(errorTimer); - console.log('HTTP REQUEST COMPLETE (this is good)'); - }); + http.cat('http://localhost:' + common.PORT + '/', 'utf8', + function(err, content) { + clearTimeout(errorTimer); + console.log('HTTP REQUEST COMPLETE (this is good)'); + }); }); diff --git a/test/simple/test-http-set-trailers.js b/test/simple/test-http-set-trailers.js index 35d2b9ede5..67fe567f67 100644 --- a/test/simple/test-http-set-trailers.js +++ b/test/simple/test-http-set-trailers.js @@ -6,69 +6,69 @@ var net = require('net'); var outstanding_reqs = 0; var server = http.createServer(function(req, res) { - res.writeHead(200, [ ['content-type', 'text/plain'] ]); - res.addTrailers({"x-foo": "bar"}); - res.end("stuff" + "\n"); + res.writeHead(200, [['content-type', 'text/plain']]); + res.addTrailers({'x-foo': 'bar'}); + res.end('stuff' + '\n'); }); server.listen(common.PORT); // first, we test an HTTP/1.0 request. -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - var res_buffer = ""; + var res_buffer = ''; - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { + c.addListener('connect', function() { outstanding_reqs++; - c.write( "GET / HTTP/1.0\r\n\r\n" ); + c.write('GET / HTTP/1.0\r\n\r\n'); }); - c.addListener("data", function (chunk) { -// console.log(chunk); + c.addListener('data', function(chunk) { + //console.log(chunk); res_buffer += chunk; }); - c.addListener("end", function () { + c.addListener('end', function() { c.end(); - assert.ok(! /x-foo/.test(res_buffer), "Trailer in HTTP/1.0 response."); + assert.ok(! /x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.'); outstanding_reqs--; if (outstanding_reqs == 0) { - server.close(); - process.exit(); + server.close(); + process.exit(); } }); }); // now, we test an HTTP/1.1 request. -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - var res_buffer = ""; + var res_buffer = ''; var tid; - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { + c.addListener('connect', function() { outstanding_reqs++; - c.write( "GET / HTTP/1.1\r\n\r\n" ); - tid = setTimeout(assert.fail, 2000, "Couldn't find last chunk."); + c.write('GET / HTTP/1.1\r\n\r\n'); + tid = setTimeout(assert.fail, 2000, 'Couldn\'t find last chunk.'); }); - c.addListener("data", function (chunk) { -// console.log(chunk); + c.addListener('data', function(chunk) { + //console.log(chunk); res_buffer += chunk; if (/0\r\n/.test(res_buffer)) { // got the end. - outstanding_reqs--; - clearTimeout(tid); - assert.ok( - /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer), - "No trailer in HTTP/1.1 response." - ); - if (outstanding_reqs == 0) { - server.close(); - process.exit(); - } + outstanding_reqs--; + clearTimeout(tid); + assert.ok( + /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer), + 'No trailer in HTTP/1.1 response.' + ); + if (outstanding_reqs == 0) { + server.close(); + process.exit(); + } } }); }); @@ -76,14 +76,13 @@ server.addListener("listening", function() { // now, see if the client sees the trailers. server.addListener('listening', function() { var client = http.createClient(common.PORT); - var req = client.request("/hello", {}); + var req = client.request('/hello', {}); req.end(); outstanding_reqs++; - req.addListener('response', function (res) { - res.addListener('end', function () { -// console.log(res.trailers); - assert.ok("x-foo" in res.trailers, - "Client doesn't see trailers."); + req.addListener('response', function(res) { + res.addListener('end', function() { + //console.log(res.trailers); + assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.'); outstanding_reqs--; if (outstanding_reqs == 0) { server.close(); diff --git a/test/simple/test-http-upgrade-client.js b/test/simple/test-http-upgrade-client.js index 84bdaf11c6..386f1a26fa 100644 --- a/test/simple/test-http-upgrade-client.js +++ b/test/simple/test-http-upgrade-client.js @@ -10,47 +10,47 @@ var net = require('net'); // Create a TCP server var srv = net.createServer(function(c) { - var data = ''; - c.addListener('data', function(d) { - data += d.toString('utf8'); - - c.write('HTTP/1.1 101\r\n'); - c.write('hello: world\r\n'); - c.write('connection: upgrade\r\n'); - c.write('upgrade: websocket\r\n'); - c.write('\r\n'); - c.write('nurtzo'); - }); - - c.addListener('end', function() { - c.end(); - }); + var data = ''; + c.addListener('data', function(d) { + data += d.toString('utf8'); + + c.write('HTTP/1.1 101\r\n'); + c.write('hello: world\r\n'); + c.write('connection: upgrade\r\n'); + c.write('upgrade: websocket\r\n'); + c.write('\r\n'); + c.write('nurtzo'); + }); + + c.addListener('end', function() { + c.end(); + }); }); var gotUpgrade = false; -srv.listen(common.PORT, '127.0.0.1', function () { +srv.listen(common.PORT, '127.0.0.1', function() { var hc = http.createClient(common.PORT, '127.0.0.1'); hc.addListener('upgrade', function(res, socket, upgradeHead) { - // XXX: This test isn't fantastic, as it assumes that the entire response - // from the server will arrive in a single data callback - assert.equal(upgradeHead, 'nurtzo'); + // XXX: This test isn't fantastic, as it assumes that the entire response + // from the server will arrive in a single data callback + assert.equal(upgradeHead, 'nurtzo'); - console.log(res.headers); - var expectedHeaders = { "hello": "world", - "connection": "upgrade", - "upgrade": "websocket" }; - assert.deepEqual(expectedHeaders, res.headers); + console.log(res.headers); + var expectedHeaders = {'hello': 'world', + 'connection': 'upgrade', + 'upgrade': 'websocket' }; + assert.deepEqual(expectedHeaders, res.headers); - socket.end(); - srv.close(); + socket.end(); + srv.close(); - gotUpgrade = true; + gotUpgrade = true; }); hc.request('GET', '/').end(); }); process.addListener('exit', function() { - assert.ok(gotUpgrade); + assert.ok(gotUpgrade); }); diff --git a/test/simple/test-http-upgrade-client2.js b/test/simple/test-http-upgrade-client2.js index 3550f70f5d..14a2fa1798 100644 --- a/test/simple/test-http-upgrade-client2.js +++ b/test/simple/test-http-upgrade-client2.js @@ -1,4 +1,4 @@ -var common = require("../common"); +var common = require('../common'); var assert = require('assert'); var http = require('http'); @@ -9,14 +9,14 @@ server.on('upgrade', function(req, socket, head) { socket.write('HTTP/1.1 101 Ok' + CRLF + 'Connection: Upgrade' + CRLF + 'Upgrade: Test' + CRLF + CRLF + 'head'); - socket.on('end', function () { + socket.on('end', function() { socket.end(); }); }); var successCount = 0; -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var client = http.createClient(common.PORT); @@ -61,6 +61,6 @@ server.listen(common.PORT, function () { }); -process.on('exit', function () { +process.on('exit', function() { assert.equal(2, successCount); }); diff --git a/test/simple/test-http-upgrade-server.js b/test/simple/test-http-upgrade-server.js index 8662df4df7..26cd133c03 100644 --- a/test/simple/test-http-upgrade-server.js +++ b/test/simple/test-http-upgrade-server.js @@ -1,149 +1,154 @@ var common = require('../common'); var assert = require('assert'); -var util = require("util"); -var net = require("net"); -var http = require("http"); +var util = require('util'); +var net = require('net'); +var http = require('http'); var requests_recv = 0; var requests_sent = 0; var request_upgradeHead = null; -function createTestServer(){ +function createTestServer() { return new testServer(); -}; +} -function testServer(){ +function testServer() { var server = this; - http.Server.call(server, function(){}); + http.Server.call(server, function() {}); - server.addListener("connection", function(){ + server.addListener('connection', function() { requests_recv++; }); - server.addListener("request", function(req, res){ - res.writeHead(200, {"Content-Type": "text/plain"}); - res.write("okay"); + server.addListener('request', function(req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('okay'); res.end(); }); - server.addListener("upgrade", function(req, socket, upgradeHead){ - socket.write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" + - "Upgrade: WebSocket\r\n" + - "Connection: Upgrade\r\n" + - "\r\n\r\n"); + server.addListener('upgrade', function(req, socket, upgradeHead) { + socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n\r\n'); request_upgradeHead = upgradeHead; - socket.ondata = function(d, start, end){ + socket.ondata = function(d, start, end) { var data = d.toString('utf8', start, end); - if(data == "kill"){ + if (data == 'kill') { socket.end(); } else { - socket.write(data, "utf8"); + socket.write(data, 'utf8'); } }; }); -}; +} util.inherits(testServer, http.Server); -function writeReq(socket, data, encoding){ +function writeReq(socket, data, encoding) { requests_sent++; socket.write(data); -}; +} /*----------------------------------------------- connection: Upgrade with listener -----------------------------------------------*/ -function test_upgrade_with_listener(_server){ +function test_upgrade_with_listener(_server) { var conn = net.createConnection(common.PORT); - conn.setEncoding("utf8"); + conn.setEncoding('utf8'); var state = 0; - conn.addListener("connect", function () { - writeReq(conn, "GET / HTTP/1.1\r\n" + - "Upgrade: WebSocket\r\n" + - "Connection: Upgrade\r\n" + - "\r\n" + - "WjN}|M(6"); + conn.addListener('connect', function() { + writeReq(conn, + 'GET / HTTP/1.1\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n' + + 'WjN}|M(6'); }); - conn.addListener("data", function (data) { + conn.addListener('data', function(data) { state++; assert.equal('string', typeof data); - if(state == 1) { - assert.equal("HTTP/1.1 101", data.substr(0, 12)); - assert.equal("WjN}|M(6", request_upgradeHead.toString("utf8")); - conn.write("test", "utf8"); - } else if(state == 2) { - assert.equal("test", data); - conn.write("kill", "utf8"); + if (state == 1) { + assert.equal('HTTP/1.1 101', data.substr(0, 12)); + assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8')); + conn.write('test', 'utf8'); + } else if (state == 2) { + assert.equal('test', data); + conn.write('kill', 'utf8'); } }); - conn.addListener("end", function(){ + conn.addListener('end', function() { assert.equal(2, state); conn.end(); - _server.removeAllListeners("upgrade"); + _server.removeAllListeners('upgrade'); test_upgrade_no_listener(); }); -}; +} /*----------------------------------------------- connection: Upgrade, no listener -----------------------------------------------*/ var test_upgrade_no_listener_ended = false; -function test_upgrade_no_listener(){ +function test_upgrade_no_listener() { var conn = net.createConnection(common.PORT); - conn.setEncoding("utf8"); - - conn.addListener("connect", function () { - writeReq(conn, "GET / HTTP/1.1\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\n\r\n"); + conn.setEncoding('utf8'); + + conn.addListener('connect', function() { + writeReq(conn, + 'GET / HTTP/1.1\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n'); }); - conn.addListener("end", function(){ + conn.addListener('end', function() { test_upgrade_no_listener_ended = true; conn.end(); }); - conn.addListener("close", function(){ + conn.addListener('close', function() { test_standard_http(); }); -}; +} /*----------------------------------------------- connection: normal -----------------------------------------------*/ -function test_standard_http(){ +function test_standard_http() { var conn = net.createConnection(common.PORT); - conn.setEncoding("utf8"); + conn.setEncoding('utf8'); - conn.addListener("connect", function () { - writeReq(conn, "GET / HTTP/1.1\r\n\r\n"); + conn.addListener('connect', function() { + writeReq(conn, 'GET / HTTP/1.1\r\n\r\n'); }); - conn.addListener("data", function(data){ - assert.equal("string", typeof data); - assert.equal("HTTP/1.1 200", data.substr(0, 12)); + conn.addListener('data', function(data) { + assert.equal('string', typeof data); + assert.equal('HTTP/1.1 200', data.substr(0, 12)); conn.end(); }); - conn.addListener("close", function(){ + conn.addListener('close', function() { server.close(); }); -}; +} var server = createTestServer(); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { // All tests get chained after this: test_upgrade_with_listener(server); }); @@ -152,7 +157,7 @@ server.listen(common.PORT, function () { /*----------------------------------------------- Fin. -----------------------------------------------*/ -process.addListener("exit", function () { +process.addListener('exit', function() { assert.equal(3, requests_recv); assert.equal(3, requests_sent); assert.ok(test_upgrade_no_listener_ended); diff --git a/test/simple/test-http-upgrade-server2.js b/test/simple/test-http-upgrade-server2.js index d80768ca37..fd84ebe8ca 100644 --- a/test/simple/test-http-upgrade-server2.js +++ b/test/simple/test-http-upgrade-server2.js @@ -3,12 +3,12 @@ var assert = require('assert'); var http = require('http'); var net = require('net'); -var server = http.createServer(function (req, res) { +var server = http.createServer(function(req, res) { common.error('got req'); - throw new Error("This shouldn't happen."); + throw new Error('This shouldn\'t happen.'); }); -server.addListener('upgrade', function (req, socket, upgradeHead) { +server.addListener('upgrade', function(req, socket, upgradeHead) { common.error('got upgrade event'); // test that throwing an error from upgrade gets // is uncaught @@ -17,35 +17,35 @@ server.addListener('upgrade', function (req, socket, upgradeHead) { var gotError = false; -process.addListener('uncaughtException', function (e) { - common.error('got "clientError" event'); +process.addListener('uncaughtException', function(e) { + common.error('got \'clientError\' event'); assert.equal('upgrade error', e.message); gotError = true; process.exit(0); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var c = net.createConnection(common.PORT); - c.addListener('connect', function () { + c.addListener('connect', function() { common.error('client wrote message'); - c.write("GET /blah HTTP/1.1\r\n" + - "Upgrade: WebSocket\r\n" + - "Connection: Upgrade\r\n" + - "\r\n\r\nhello world"); + c.write('GET /blah HTTP/1.1\r\n' + + 'Upgrade: WebSocket\r\n' + + 'Connection: Upgrade\r\n' + + '\r\n\r\nhello world'); }); - c.addListener('end', function () { + c.addListener('end', function() { c.end(); }); - c.addListener('close', function () { + c.addListener('close', function() { common.error('client close'); server.close(); }); }); -process.addListener('exit', function () { +process.addListener('exit', function() { assert.ok(gotError); }); diff --git a/test/simple/test-http-wget.js b/test/simple/test-http-wget.js index 1fa970bd9c..3a977ae8ee 100644 --- a/test/simple/test-http-wget.js +++ b/test/simple/test-http-wget.js @@ -18,49 +18,49 @@ var http = require('http'); // content-length is not provided, that the connection is in fact // closed. -var server_response = ""; +var server_response = ''; var client_got_eof = false; var connection_was_closed = false; -var server = http.createServer(function (req, res) { - res.writeHead(200, {"Content-Type": "text/plain"}); - res.write("hello "); - res.write("world\n"); +var server = http.createServer(function(req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('hello '); + res.write('world\n'); res.end(); }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var c = net.createConnection(common.PORT); - c.setEncoding("utf8"); + c.setEncoding('utf8'); - c.addListener("connect", function () { - c.write("GET / HTTP/1.0\r\n" + - "Connection: Keep-Alive\r\n\r\n"); + c.addListener('connect', function() { + c.write('GET / HTTP/1.0\r\n' + + 'Connection: Keep-Alive\r\n\r\n'); }); - c.addListener("data", function (chunk) { + c.addListener('data', function(chunk) { console.log(chunk); server_response += chunk; }); - c.addListener("end", function () { + c.addListener('end', function() { client_got_eof = true; console.log('got end'); c.end(); }); - c.addListener("close", function () { + c.addListener('close', function() { connection_was_closed = true; console.log('got close'); server.close(); }); }); -process.addListener("exit", function () { - var m = server_response.split("\r\n\r\n"); - assert.equal(m[1], "hello world\n"); +process.addListener('exit', function() { + var m = server_response.split('\r\n\r\n'); + assert.equal(m[1], 'hello world\n'); assert.ok(client_got_eof); assert.ok(connection_was_closed); }); diff --git a/test/simple/test-http-write-empty-string.js b/test/simple/test-http-write-empty-string.js index 5378d81777..39c2f613d9 100644 --- a/test/simple/test-http-write-empty-string.js +++ b/test/simple/test-http-write-empty-string.js @@ -3,7 +3,7 @@ var assert = require('assert'); var http = require('http'); -var server = http.createServer(function (request, response) { +var server = http.createServer(function(request, response) { console.log('responding to ' + request.url); response.writeHead(200, {'Content-Type': 'text/plain'}); @@ -14,26 +14,26 @@ var server = http.createServer(function (request, response) { response.end('3\n'); this.close(); -}) +}); -var response=""; +var response = ''; -process.addListener('exit', function () { +process.addListener('exit', function() { assert.equal('1\n2\n3\n', response); }); -server.listen(common.PORT, function () { +server.listen(common.PORT, function() { var client = http.createClient(common.PORT); - var req = client.request("/"); + var req = client.request('/'); req.end(); - req.addListener('response', function (res) { + req.addListener('response', function(res) { assert.equal(200, res.statusCode); - res.setEncoding("ascii"); - res.addListener('data', function (chunk) { + res.setEncoding('ascii'); + res.addListener('data', function(chunk) { response += chunk; }); - common.error("Got /hello response"); + common.error('Got /hello response'); }); }); diff --git a/test/simple/test-http.js b/test/simple/test-http.js index 824f722e1e..0e2a420fad 100644 --- a/test/simple/test-http.js +++ b/test/simple/test-http.js @@ -1,80 +1,80 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var url = require("url"); +var url = require('url'); -function p (x) { +function p(x) { common.error(common.inspect(x)); } var responses_sent = 0; var responses_recvd = 0; -var body0 = ""; -var body1 = ""; +var body0 = ''; +var body1 = ''; -var server = http.Server(function (req, res) { +var server = http.Server(function(req, res) { if (responses_sent == 0) { - assert.equal("GET", req.method); - assert.equal("/hello", url.parse(req.url).pathname); + assert.equal('GET', req.method); + assert.equal('/hello', url.parse(req.url).pathname); console.dir(req.headers); - assert.equal(true, "accept" in req.headers); - assert.equal("*/*", req.headers["accept"]); + assert.equal(true, 'accept' in req.headers); + assert.equal('*/*', req.headers['accept']); - assert.equal(true, "foo" in req.headers); - assert.equal("bar", req.headers["foo"]); + assert.equal(true, 'foo' in req.headers); + assert.equal('bar', req.headers['foo']); } if (responses_sent == 1) { - assert.equal("POST", req.method); - assert.equal("/world", url.parse(req.url).pathname); + assert.equal('POST', req.method); + assert.equal('/world', url.parse(req.url).pathname); this.close(); } - req.addListener('end', function () { - res.writeHead(200, {"Content-Type": "text/plain"}); - res.write("The path was " + url.parse(req.url).pathname); + req.addListener('end', function() { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('The path was ' + url.parse(req.url).pathname); res.end(); responses_sent += 1; }); - //assert.equal("127.0.0.1", res.connection.remoteAddress); + //assert.equal('127.0.0.1', res.connection.remoteAddress); }); server.listen(common.PORT); -server.addListener("listening", function() { +server.addListener('listening', function() { var client = http.createClient(common.PORT); - var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"}); + var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); req.end(); - req.addListener('response', function (res) { + req.addListener('response', function(res) { assert.equal(200, res.statusCode); responses_recvd += 1; - res.setEncoding("utf8"); - res.addListener('data', function (chunk) { body0 += chunk; }); - common.debug("Got /hello response"); + res.setEncoding('utf8'); + res.addListener('data', function(chunk) { body0 += chunk; }); + common.debug('Got /hello response'); }); - setTimeout(function () { - req = client.request("POST", "/world"); + setTimeout(function() { + req = client.request('POST', '/world'); req.end(); - req.addListener('response',function (res) { + req.addListener('response', function(res) { assert.equal(200, res.statusCode); responses_recvd += 1; - res.setEncoding("utf8"); - res.addListener('data', function (chunk) { body1 += chunk; }); - common.debug("Got /world response"); + res.setEncoding('utf8'); + res.addListener('data', function(chunk) { body1 += chunk; }); + common.debug('Got /world response'); }); }, 1); }); -process.addListener("exit", function () { - common.debug("responses_recvd: " + responses_recvd); +process.addListener('exit', function() { + common.debug('responses_recvd: ' + responses_recvd); assert.equal(2, responses_recvd); - common.debug("responses_sent: " + responses_sent); + common.debug('responses_sent: ' + responses_sent); assert.equal(2, responses_sent); - assert.equal("The path was /hello", body0); - assert.equal("The path was /world", body1); + assert.equal('The path was /hello', body0); + assert.equal('The path was /world', body1); }); diff --git a/test/simple/test-path.js b/test/simple/test-path.js index cb78071c2c..5a9b936ba7 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -41,75 +41,79 @@ assert.equal(path.extname('file.'), '.'); // path.join tests var failures = []; var joinTests = - // arguments result - [[['.', 'x/b', '..', '/b/c.js' ], 'x/b/c.js' ] - ,[['/.', 'x/b', '..', '/b/c.js' ], '/x/b/c.js' ] - ,[['/foo', '../../../bar' ], '/bar' ] - ,[['foo', '../../../bar' ], '../../bar' ] - ,[['foo/', '../../../bar' ], '../../bar' ] - ,[['foo/x', '../../../bar' ], '../bar' ] - ,[['foo/x', './bar' ], 'foo/x/bar' ] - ,[['foo/x/', './bar' ], 'foo/x/bar' ] - ,[['foo/x/', '.', 'bar' ], 'foo/x/bar' ] - ,[['./' ], './' ] - ,[['.', './' ], './' ] - ,[['.', '.', '.' ], '.' ] - ,[['.', './', '.' ], '.' ] - ,[['.', '/./', '.' ], '.' ] - ,[['.', '/////./', '.' ], '.' ] - ,[['.' ], '.' ] - ,[['','.' ], '.' ] - ,[['', 'foo' ], 'foo' ] - ,[['foo', '/bar' ], 'foo/bar' ] - ,[['', '/foo' ], '/foo' ] - ,[['', '', '/foo' ], '/foo' ] - ,[['', '', 'foo' ], 'foo' ] - ,[['foo', '' ], 'foo' ] - ,[['foo/', '' ], 'foo/' ] - ,[['foo', '', '/bar' ], 'foo/bar' ] - ,[['./', '..', '/foo' ], '../foo' ] - ,[['./', '..', '..', '/foo' ], '../../foo' ] - ,[['.', '..', '..', '/foo' ], '../../foo' ] - ,[['', '..', '..', '/foo' ], '../../foo' ] - ,[['/' ], '/' ] - ,[['/', '.' ], '/' ] - ,[['/', '..' ], '/' ] - ,[['/', '..', '..' ], '/' ] - ,[['' ], '.' ] - ,[['', '' ], '.' ] - ,[[' /foo' ], ' /foo' ] - ,[[' ', 'foo' ], ' /foo' ] - ,[[' ', '.' ], ' ' ] - ,[[' ', '/' ], ' /' ] - ,[[' ', '' ], ' ' ] - // preserving empty path parts, for url resolution case - // pass boolean true as LAST argument. - ,[['', '', true ], '/' ] - ,[['foo', '', true ], 'foo/' ] - ,[['foo', '', 'bar', true ], 'foo//bar' ] - ,[['foo/', '', 'bar', true ], 'foo///bar' ] - ,[['', true ], '.' ] - // filtration of non-strings. - ,[['x', true, 7, 'y', null, {} ], 'x/y' ] - ]; + // arguments result + [[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'], + [['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'], + [['/foo', '../../../bar'], '/bar'], + [['foo', '../../../bar'], '../../bar'], + [['foo/', '../../../bar'], '../../bar'], + [['foo/x', '../../../bar'], '../bar'], + [['foo/x', './bar'], 'foo/x/bar'], + [['foo/x/', './bar'], 'foo/x/bar'], + [['foo/x/', '.', 'bar'], 'foo/x/bar'], + [['./'], './'], + [['.', './'], './'], + [['.', '.', '.'], '.'], + [['.', './', '.'], '.'], + [['.', '/./', '.'], '.'], + [['.', '/////./', '.'], '.'], + [['.'], '.'], + [['', '.'], '.'], + [['', 'foo'], 'foo'], + [['foo', '/bar'], 'foo/bar'], + [['', '/foo'], '/foo'], + [['', '', '/foo'], '/foo'], + [['', '', 'foo'], 'foo'], + [['foo', ''], 'foo'], + [['foo/', ''], 'foo/'], + [['foo', '', '/bar'], 'foo/bar'], + [['./', '..', '/foo'], '../foo'], + [['./', '..', '..', '/foo'], '../../foo'], + [['.', '..', '..', '/foo'], '../../foo'], + [['', '..', '..', '/foo'], '../../foo'], + [['/'], '/'], + [['/', '.'], '/'], + [['/', '..'], '/'], + [['/', '..', '..'], '/'], + [[''], '.'], + [['', ''], '.'], + [[' /foo'], ' /foo'], + [[' ', 'foo'], ' /foo'], + [[' ', '.'], ' '], + [[' ', '/'], ' /'], + [[' ', ''], ' '], + // preserving empty path parts, for url resolution case + // pass boolean true as LAST argument. + [['', '', true], '/'], + [['foo', '', true], 'foo/'], + [['foo', '', 'bar', true], 'foo//bar'], + [['foo/', '', 'bar', true], 'foo///bar'], + [['', true], '.'], + // filtration of non-strings. + [['x', true, 7, 'y', null, {}], 'x/y'] + ]; joinTests.forEach(function(test) { var actual = path.join.apply(path, test[0]); var expected = test[1]; - var message = 'path.join('+test[0].map(JSON.stringify).join(',')+')' - + '\n expect='+JSON.stringify(expected) - + '\n actual='+JSON.stringify(actual); - if (actual !== expected) failures.push('\n'+message); + var message = 'path.join(' + test[0].map(JSON.stringify).join(',') + ')' + + '\n expect=' + JSON.stringify(expected) + + '\n actual=' + JSON.stringify(actual); + if (actual !== expected) failures.push('\n' + message); // assert.equal(actual, expected, message); }); -assert.equal(failures.length, 0, failures.join('')) +assert.equal(failures.length, 0, failures.join('')); -assert.equal(path.normalize('./fixtures///b/../b/c.js'), 'fixtures/b/c.js'); -assert.equal(path.normalize('./fixtures///b/../b/c.js',true), 'fixtures///b/c.js'); +assert.equal(path.normalize('./fixtures///b/../b/c.js'), + 'fixtures/b/c.js'); +assert.equal(path.normalize('./fixtures///b/../b/c.js', true), + 'fixtures///b/c.js'); assert.equal(path.normalize('/foo/../../../bar'), '/bar'); -assert.deepEqual(path.normalizeArray(['fixtures','b','','..','b','c.js']), ['fixtures','b','c.js']); -assert.deepEqual(path.normalizeArray(['fixtures','','b','..','b','c.js'], true), ['fixtures','','b','c.js']); +assert.deepEqual(path.normalizeArray(['fixtures', 'b', '', '..', 'b', 'c.js']), + ['fixtures', 'b', 'c.js']); +assert.deepEqual(path.normalizeArray(['fixtures', '', 'b', '..', 'b', 'c.js'], + true), ['fixtures', '', 'b', 'c.js']); assert.equal(path.normalize('a//b//../b', true), 'a//b/b'); assert.equal(path.normalize('a//b//../b'), 'a/b'); diff --git a/test/simple/test-url.js b/test/simple/test-url.js index dd01e3a163..c59e92bec3 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -7,251 +7,273 @@ var url = require('url'), // URLs to parse, and expected data // { url : parsed } var parseTests = { - "//some_path" : { - "href": "//some_path", - "pathname": "//some_path" + '//some_path' : { + 'href': '//some_path', + 'pathname': '//some_path' }, - "http://www.narwhaljs.org/blog/categories?id=news" : { - "href": "http://www.narwhaljs.org/blog/categories?id=news", - "protocol": "http:", - "host": "www.narwhaljs.org", - "hostname": "www.narwhaljs.org", - "search": "?id=news", - "query": "id=news", - "pathname": "/blog/categories" + 'http://www.narwhaljs.org/blog/categories?id=news' : { + 'href': 'http://www.narwhaljs.org/blog/categories?id=news', + 'protocol': 'http:', + 'host': 'www.narwhaljs.org', + 'hostname': 'www.narwhaljs.org', + 'search': '?id=news', + 'query': 'id=news', + 'pathname': '/blog/categories' }, - "http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=" : { - "href": "http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=", - "protocol": "http:", - "host": "mt0.google.com", - "hostname": "mt0.google.com", - "pathname": "/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=" + 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' : { + 'href': 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=', + 'protocol': 'http:', + 'host': 'mt0.google.com', + 'hostname': 'mt0.google.com', + 'pathname': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' }, - "http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=" : { - "href": "http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=", - "protocol": "http:", - "host": "mt0.google.com", - "hostname": "mt0.google.com", - "search": "???&hl=en&src=api&x=2&y=2&z=3&s=", - "query": "??&hl=en&src=api&x=2&y=2&z=3&s=", - "pathname": "/vt/lyrs=m@114" + 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : { + 'href': 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=', + 'protocol': 'http:', + 'host': 'mt0.google.com', + 'hostname': 'mt0.google.com', + 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=', + 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=', + 'pathname': '/vt/lyrs=m@114' }, - "http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=" : { - "href": "http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=", - "protocol": "http:", - "host": "user:pass@mt0.google.com", - "auth": "user:pass", - "hostname": "mt0.google.com", - "search": "???&hl=en&src=api&x=2&y=2&z=3&s=", - "query": "??&hl=en&src=api&x=2&y=2&z=3&s=", - "pathname": "/vt/lyrs=m@114" + 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : { + 'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=', + 'protocol': 'http:', + 'host': 'user:pass@mt0.google.com', + 'auth': 'user:pass', + 'hostname': 'mt0.google.com', + 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=', + 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=', + 'pathname': '/vt/lyrs=m@114' }, - "file:///etc/passwd" : { - "href": "file:///etc/passwd", - "protocol": "file:", - "pathname": "///etc/passwd" + 'file:///etc/passwd' : { + 'href': 'file:///etc/passwd', + 'protocol': 'file:', + 'pathname': '///etc/passwd' }, - "file:///etc/node/" : { - "href": "file:///etc/node/", - "protocol": "file:", - "pathname": "///etc/node/" + 'file:///etc/node/' : { + 'href': 'file:///etc/node/', + 'protocol': 'file:', + 'pathname': '///etc/node/' }, - "http:/baz/../foo/bar" : { - "href": "http:/baz/../foo/bar", - "protocol": "http:", - "pathname": "/baz/../foo/bar" + 'http:/baz/../foo/bar' : { + 'href': 'http:/baz/../foo/bar', + 'protocol': 'http:', + 'pathname': '/baz/../foo/bar' }, - "http://user:pass@example.com:8000/foo/bar?baz=quux#frag" : { - "href": "http://user:pass@example.com:8000/foo/bar?baz=quux#frag", - "protocol": "http:", - "host": "user:pass@example.com:8000", - "auth": "user:pass", - "port": "8000", - "hostname": "example.com", - "hash": "#frag", - "search": "?baz=quux", - "query": "baz=quux", - "pathname": "/foo/bar" + 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag' : { + 'href': 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag', + 'protocol': 'http:', + 'host': 'user:pass@example.com:8000', + 'auth': 'user:pass', + 'port': '8000', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?baz=quux', + 'query': 'baz=quux', + 'pathname': '/foo/bar' }, - "//user:pass@example.com:8000/foo/bar?baz=quux#frag" : { - "href": "//user:pass@example.com:8000/foo/bar?baz=quux#frag", - "host": "user:pass@example.com:8000", - "auth": "user:pass", - "port": "8000", - "hostname": "example.com", - "hash": "#frag", - "search": "?baz=quux", - "query": "baz=quux", - "pathname": "/foo/bar" + '//user:pass@example.com:8000/foo/bar?baz=quux#frag' : { + 'href': '//user:pass@example.com:8000/foo/bar?baz=quux#frag', + 'host': 'user:pass@example.com:8000', + 'auth': 'user:pass', + 'port': '8000', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?baz=quux', + 'query': 'baz=quux', + 'pathname': '/foo/bar' }, - "http://example.com?foo=bar#frag" : { - "href": "http://example.com?foo=bar#frag", - "protocol": "http:", - "host": "example.com", - "hostname": "example.com", - "hash": "#frag", - "search": "?foo=bar", - "query": "foo=bar" + 'http://example.com?foo=bar#frag' : { + 'href': 'http://example.com?foo=bar#frag', + 'protocol': 'http:', + 'host': 'example.com', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?foo=bar', + 'query': 'foo=bar' }, - "http://example.com?foo=@bar#frag" : { - "href": "http://example.com?foo=@bar#frag", - "protocol": "http:", - "host": "example.com", - "hostname": "example.com", - "hash": "#frag", - "search": "?foo=@bar", - "query": "foo=@bar" + 'http://example.com?foo=@bar#frag' : { + 'href': 'http://example.com?foo=@bar#frag', + 'protocol': 'http:', + 'host': 'example.com', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?foo=@bar', + 'query': 'foo=@bar' }, - "http://example.com?foo=/bar/#frag" : { - "href": "http://example.com?foo=/bar/#frag", - "protocol": "http:", - "host": "example.com", - "hostname": "example.com", - "hash": "#frag", - "search": "?foo=/bar/", - "query": "foo=/bar/" + 'http://example.com?foo=/bar/#frag' : { + 'href': 'http://example.com?foo=/bar/#frag', + 'protocol': 'http:', + 'host': 'example.com', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?foo=/bar/', + 'query': 'foo=/bar/' }, - "http://example.com?foo=?bar/#frag" : { - "href": "http://example.com?foo=?bar/#frag", - "protocol": "http:", - "host": "example.com", - "hostname": "example.com", - "hash": "#frag", - "search": "?foo=?bar/", - "query": "foo=?bar/" + 'http://example.com?foo=?bar/#frag' : { + 'href': 'http://example.com?foo=?bar/#frag', + 'protocol': 'http:', + 'host': 'example.com', + 'hostname': 'example.com', + 'hash': '#frag', + 'search': '?foo=?bar/', + 'query': 'foo=?bar/' }, - "http://example.com#frag=?bar/#frag" : { - "href": "http://example.com#frag=?bar/#frag", - "protocol": "http:", - "host": "example.com", - "hostname": "example.com", - "hash": "#frag=?bar/#frag" + 'http://example.com#frag=?bar/#frag' : { + 'href': 'http://example.com#frag=?bar/#frag', + 'protocol': 'http:', + 'host': 'example.com', + 'hostname': 'example.com', + 'hash': '#frag=?bar/#frag' }, - "/foo/bar?baz=quux#frag" : { - "href": "/foo/bar?baz=quux#frag", - "hash": "#frag", - "search": "?baz=quux", - "query": "baz=quux", - "pathname": "/foo/bar" + '/foo/bar?baz=quux#frag' : { + 'href': '/foo/bar?baz=quux#frag', + 'hash': '#frag', + 'search': '?baz=quux', + 'query': 'baz=quux', + 'pathname': '/foo/bar' }, - "http:/foo/bar?baz=quux#frag" : { - "href": "http:/foo/bar?baz=quux#frag", - "protocol": "http:", - "hash": "#frag", - "search": "?baz=quux", - "query": "baz=quux", - "pathname": "/foo/bar" + 'http:/foo/bar?baz=quux#frag' : { + 'href': 'http:/foo/bar?baz=quux#frag', + 'protocol': 'http:', + 'hash': '#frag', + 'search': '?baz=quux', + 'query': 'baz=quux', + 'pathname': '/foo/bar' }, - "mailto:foo@bar.com?subject=hello" : { - "href": "mailto:foo@bar.com?subject=hello", - "protocol": "mailto:", - "host": "foo@bar.com", - "auth" : "foo", - "hostname" : "bar.com", - "search": "?subject=hello", - "query": "subject=hello" + 'mailto:foo@bar.com?subject=hello' : { + 'href': 'mailto:foo@bar.com?subject=hello', + 'protocol': 'mailto:', + 'host': 'foo@bar.com', + 'auth' : 'foo', + 'hostname' : 'bar.com', + 'search': '?subject=hello', + 'query': 'subject=hello' }, - "javascript:alert('hello');" : { - "href": "javascript:alert('hello');", - "protocol": "javascript:", - "host": "alert('hello')", - "hostname": "alert('hello')", - "pathname" : ";" + 'javascript:alert(\'hello\');' : { + 'href': 'javascript:alert(\'hello\');', + 'protocol': 'javascript:', + 'host': 'alert(\'hello\')', + 'hostname': 'alert(\'hello\')', + 'pathname' : ';' }, - "xmpp:isaacschlueter@jabber.org" : { - "href": "xmpp:isaacschlueter@jabber.org", - "protocol": "xmpp:", - "host": "isaacschlueter@jabber.org", - "auth": "isaacschlueter", - "hostname": "jabber.org" + 'xmpp:isaacschlueter@jabber.org' : { + 'href': 'xmpp:isaacschlueter@jabber.org', + 'protocol': 'xmpp:', + 'host': 'isaacschlueter@jabber.org', + 'auth': 'isaacschlueter', + 'hostname': 'jabber.org' } }; for (var u in parseTests) { var actual = url.parse(u), - expected = parseTests[u]; + expected = parseTests[u]; for (var i in expected) { var e = JSON.stringify(expected[i]), - a = JSON.stringify(actual[i]); - assert.equal(e, a, "parse(" + u + ")."+i+" == "+e+"\nactual: "+a); + a = JSON.stringify(actual[i]); + assert.equal(e, a, + 'parse(' + u + ').' + i + ' == ' + e + '\nactual: ' + a); } var expected = u, - actual = url.format(parseTests[u]); + actual = url.format(parseTests[u]); - assert.equal(expected, actual, "format("+u+") == "+u+"\nactual:"+actual); + assert.equal(expected, actual, + 'format(' + u + ') == ' + u + '\nactual:' + actual); } var parseTestsWithQueryString = { - "/foo/bar?baz=quux#frag" : { - "href": "/foo/bar?baz=quux#frag", - "hash": "#frag", - "search": "?baz=quux", - "query": { - "baz": "quux" - }, - "pathname": "/foo/bar" - }, + '/foo/bar?baz=quux#frag' : { + 'href': '/foo/bar?baz=quux#frag', + 'hash': '#frag', + 'search': '?baz=quux', + 'query': { + 'baz': 'quux' + }, + 'pathname': '/foo/bar' + } }; for (var u in parseTestsWithQueryString) { - var actual = url.parse(u,true); + var actual = url.parse(u, true); var expected = parseTestsWithQueryString[u]; for (var i in expected) { var e = JSON.stringify(expected[i]), - a = JSON.stringify(actual[i]); - assert.equal(e, a, "parse(" + u + ")."+i+" == "+e+"\nactual: "+a); + a = JSON.stringify(actual[i]); + assert.equal(e, a, + 'parse(' + u + ').' + i + ' == ' + e + '\nactual: ' + a); } } -// some extra formatting tests, just to verify that it'll format slightly wonky content to a valid url. +// some extra formatting tests, just to verify +// that it'll format slightly wonky content to a valid url. var formatTests = { - "http://a.com/a/b/c?s#h" : { - "protocol": "http", - "host": "a.com", - "pathname": "a/b/c", - "hash": "h", - "search": "s" + 'http://a.com/a/b/c?s#h' : { + 'protocol': 'http', + 'host': 'a.com', + 'pathname': 'a/b/c', + 'hash': 'h', + 'search': 's' }, - "xmpp:isaacschlueter@jabber.org" : { - "href": "xmpp://isaacschlueter@jabber.org", - "protocol": "xmpp:", - "host": "isaacschlueter@jabber.org", - "auth": "isaacschlueter", - "hostname": "jabber.org" + 'xmpp:isaacschlueter@jabber.org' : { + 'href': 'xmpp://isaacschlueter@jabber.org', + 'protocol': 'xmpp:', + 'host': 'isaacschlueter@jabber.org', + 'auth': 'isaacschlueter', + 'hostname': 'jabber.org' } }; for (var u in formatTests) { var actual = url.format(formatTests[u]); - assert.equal(actual, u, "wonky format("+u+") == "+u+"\nactual:"+actual); + assert.equal(actual, u, + 'wonky format(' + u + ') == ' + u + '\nactual:' + actual); } -[ - // [from, path, expected] - ["/foo/bar/baz", "quux", "/foo/bar/quux"], - ["/foo/bar/baz", "quux/asdf", "/foo/bar/quux/asdf"], - ["/foo/bar/baz", "quux/baz", "/foo/bar/quux/baz"], - ["/foo/bar/baz", "../quux/baz", "/foo/quux/baz"], - ["/foo/bar/baz", "/bar", "/bar"], - ["/foo/bar/baz/", "quux", "/foo/bar/baz/quux"], - ["/foo/bar/baz/", "quux/baz", "/foo/bar/baz/quux/baz"], - ["/foo/bar/baz", "../../../../../../../../quux/baz", "/quux/baz"], - ["/foo/bar/baz", "../../../../../../../quux/baz", "/quux/baz"], - ["foo/bar", "../../../baz", "../../baz"], - ["foo/bar/", "../../../baz", "../baz"], - ["http://example.com/b//c//d;p?q#blarg","https:#hash2","https:///#hash2" ], - ["http://example.com/b//c//d;p?q#blarg","https:/p/a/t/h?s#hash2","https://p/a/t/h?s#hash2" ], - ["http://example.com/b//c//d;p?q#blarg","https://u:p@h.com/p/a/t/h?s#hash2","https://u:p@h.com/p/a/t/h?s#hash2"], - ["http://example.com/b//c//d;p?q#blarg","https:/a/b/c/d","https://a/b/c/d"], - ["http://example.com/b//c//d;p?q#blarg","http:#hash2","http://example.com/b//c//d;p?q#hash2" ], - ["http://example.com/b//c//d;p?q#blarg","http:/p/a/t/h?s#hash2","http://example.com/p/a/t/h?s#hash2" ], - ["http://example.com/b//c//d;p?q#blarg","http://u:p@h.com/p/a/t/h?s#hash2","http://u:p@h.com/p/a/t/h?s#hash2" ], - ["http://example.com/b//c//d;p?q#blarg","http:/a/b/c/d","http://example.com/a/b/c/d"], - ["/foo/bar/baz", "/../etc/passwd", "/etc/passwd"] -].forEach(function (relativeTest) { +/* + [from, path, expected] +*/ +var relativeTests = [ + ['/foo/bar/baz', 'quux', '/foo/bar/quux'], + ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'], + ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'], + ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'], + ['/foo/bar/baz', '/bar', '/bar'], + ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'], + ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'], + ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'], + ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'], + ['foo/bar', '../../../baz', '../../baz'], + ['foo/bar/', '../../../baz', '../baz'], + ['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'https:/p/a/t/h?s#hash2', + 'https://p/a/t/h?s#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'https://u:p@h.com/p/a/t/h?s#hash2', + 'https://u:p@h.com/p/a/t/h?s#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'https:/a/b/c/d', + 'https://a/b/c/d'], + ['http://example.com/b//c//d;p?q#blarg', + 'http:#hash2', + 'http://example.com/b//c//d;p?q#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'http:/p/a/t/h?s#hash2', + 'http://example.com/p/a/t/h?s#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'http://u:p@h.com/p/a/t/h?s#hash2', + 'http://u:p@h.com/p/a/t/h?s#hash2'], + ['http://example.com/b//c//d;p?q#blarg', + 'http:/a/b/c/d', + 'http://example.com/a/b/c/d'], + ['/foo/bar/baz', '/../etc/passwd', '/etc/passwd'] +]; +relativeTests.forEach(function(relativeTest) { var a = url.resolve(relativeTest[0], relativeTest[1]), - e = relativeTest[2]; + e = relativeTest[2]; assert.equal(e, a, - "resolve("+[relativeTest[0], relativeTest[1]]+") == "+e+ - "\n actual="+a); + 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e + + '\n actual=' + a); }); @@ -273,50 +295,51 @@ var bases = [ ]; //[to, from, result] -[ +var relativeTests2 = [ // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html - ['../c', 'foo:a/b', 'foo:c'], - ['foo:.', 'foo:a', 'foo:'], + ['../c', 'foo:a/b', 'foo:c'], + ['foo:.', 'foo:a', 'foo:'], ['/foo/../../../bar', 'zz:abc', 'zz:/bar'], - ['/foo/../bar', 'zz:abc', 'zz:/bar'], - ['foo/../../../bar', 'zz:abc', 'zz:bar'], // @isaacs Disagree. Not how web browsers resolve this. + ['/foo/../bar', 'zz:abc', 'zz:/bar'], + // @isaacs Disagree. Not how web browsers resolve this. + ['foo/../../../bar', 'zz:abc', 'zz:bar'], // ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added - ['foo/../bar', 'zz:abc', 'zz:bar'], - ['zz:.', 'zz:abc', 'zz:'], - ['/.' , bases[0], 'http://a/'], - ['/.foo' , bases[0], 'http://a/.foo'], - ['.foo' , bases[0], 'http://a/b/c/.foo'], + ['foo/../bar', 'zz:abc', 'zz:bar'], + ['zz:.', 'zz:abc', 'zz:'], + ['/.', bases[0], 'http://a/'], + ['/.foo', bases[0], 'http://a/.foo'], + ['.foo', bases[0], 'http://a/b/c/.foo'], // http://gbiv.com/protocols/uri/test/rel_examples1.html // examples from RFC 2396 - ['g:h' , bases[0], 'g:h'], - ['g' , bases[0], 'http://a/b/c/g'], - ['./g' , bases[0], 'http://a/b/c/g'], - ['g/' , bases[0], 'http://a/b/c/g/'], - ['/g' , bases[0], 'http://a/g'], - ['//g' , bases[0], 'http://g'], + ['g:h', bases[0], 'g:h'], + ['g', bases[0], 'http://a/b/c/g'], + ['./g', bases[0], 'http://a/b/c/g'], + ['g/', bases[0], 'http://a/b/c/g/'], + ['/g', bases[0], 'http://a/g'], + ['//g', bases[0], 'http://g'], // changed with RFC 2396bis - //('?y' , bases[0], 'http://a/b/c/d;p?y'], - ['?y' , bases[0], 'http://a/b/c/d;p?y'], - ['g?y' , bases[0], 'http://a/b/c/g?y'], + //('?y', bases[0], 'http://a/b/c/d;p?y'], + ['?y', bases[0], 'http://a/b/c/d;p?y'], + ['g?y', bases[0], 'http://a/b/c/g?y'], // changed with RFC 2396bis - //('#s' , bases[0], CURRENT_DOC_URI + '#s'], - ['#s' , bases[0], 'http://a/b/c/d;p?q#s'], - ['g#s' , bases[0], 'http://a/b/c/g#s'], - ['g?y#s' , bases[0], 'http://a/b/c/g?y#s'], - [';x' , bases[0], 'http://a/b/c/;x'], - ['g;x' , bases[0], 'http://a/b/c/g;x'], + //('#s', bases[0], CURRENT_DOC_URI + '#s'], + ['#s', bases[0], 'http://a/b/c/d;p?q#s'], + ['g#s', bases[0], 'http://a/b/c/g#s'], + ['g?y#s', bases[0], 'http://a/b/c/g?y#s'], + [';x', bases[0], 'http://a/b/c/;x'], + ['g;x', bases[0], 'http://a/b/c/g;x'], ['g;x?y#s' , bases[0], 'http://a/b/c/g;x?y#s'], // changed with RFC 2396bis - //('' , bases[0], CURRENT_DOC_URI], - ['' , bases[0], 'http://a/b/c/d;p?q'], - ['.' , bases[0], 'http://a/b/c/'], - ['./' , bases[0], 'http://a/b/c/'], - ['..' , bases[0], 'http://a/b/'], - ['../' , bases[0], 'http://a/b/'], - ['../g' , bases[0], 'http://a/b/g'], - ['../..' , bases[0], 'http://a/'], - ['../../' , bases[0], 'http://a/'], + //('', bases[0], CURRENT_DOC_URI], + ['', bases[0], 'http://a/b/c/d;p?q'], + ['.', bases[0], 'http://a/b/c/'], + ['./', bases[0], 'http://a/b/c/'], + ['..', bases[0], 'http://a/b/'], + ['../', bases[0], 'http://a/b/'], + ['../g', bases[0], 'http://a/b/g'], + ['../..', bases[0], 'http://a/'], + ['../../', bases[0], 'http://a/'], ['../../g' , bases[0], 'http://a/g'], ['../../../g', bases[0], ('http://a/../g', 'http://a/g')], ['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')], @@ -347,82 +370,85 @@ var bases = [ // http://gbiv.com/protocols/uri/test/rel_examples2.html // slashes in base URI's query args - ['g' , bases[1], 'http://a/b/c/g'], - ['./g' , bases[1], 'http://a/b/c/g'], - ['g/' , bases[1], 'http://a/b/c/g/'], - ['/g' , bases[1], 'http://a/g'], - ['//g' , bases[1], 'http://g'], + ['g', bases[1], 'http://a/b/c/g'], + ['./g', bases[1], 'http://a/b/c/g'], + ['g/', bases[1], 'http://a/b/c/g/'], + ['/g', bases[1], 'http://a/g'], + ['//g', bases[1], 'http://g'], // changed in RFC 2396bis - //('?y' , bases[1], 'http://a/b/c/?y'], - ['?y' , bases[1], 'http://a/b/c/d;p?y'], - ['g?y' , bases[1], 'http://a/b/c/g?y'], + //('?y', bases[1], 'http://a/b/c/?y'], + ['?y', bases[1], 'http://a/b/c/d;p?y'], + ['g?y', bases[1], 'http://a/b/c/g?y'], ['g?y/./x' , bases[1], 'http://a/b/c/g?y/./x'], ['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'], - ['g#s' , bases[1], 'http://a/b/c/g#s'], + ['g#s', bases[1], 'http://a/b/c/g#s'], ['g#s/./x' , bases[1], 'http://a/b/c/g#s/./x'], ['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'], - ['./' , bases[1], 'http://a/b/c/'], - ['../' , bases[1], 'http://a/b/'], - ['../g' , bases[1], 'http://a/b/g'], - ['../../' , bases[1], 'http://a/'], + ['./', bases[1], 'http://a/b/c/'], + ['../', bases[1], 'http://a/b/'], + ['../g', bases[1], 'http://a/b/g'], + ['../../', bases[1], 'http://a/'], ['../../g' , bases[1], 'http://a/g'], // http://gbiv.com/protocols/uri/test/rel_examples3.html // slashes in path params // all of these changed in RFC 2396bis - ['g' , bases[2], 'http://a/b/c/d;p=1/g'], - ['./g' , bases[2], 'http://a/b/c/d;p=1/g'], - ['g/' , bases[2], 'http://a/b/c/d;p=1/g/'], - ['g?y' , bases[2], 'http://a/b/c/d;p=1/g?y'], - [';x' , bases[2], 'http://a/b/c/d;p=1/;x'], - ['g;x' , bases[2], 'http://a/b/c/d;p=1/g;x'], + ['g', bases[2], 'http://a/b/c/d;p=1/g'], + ['./g', bases[2], 'http://a/b/c/d;p=1/g'], + ['g/', bases[2], 'http://a/b/c/d;p=1/g/'], + ['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'], + [';x', bases[2], 'http://a/b/c/d;p=1/;x'], + ['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'], ['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'], ['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'], - ['./' , bases[2], 'http://a/b/c/d;p=1/'], - ['../' , bases[2], 'http://a/b/c/'], - ['../g' , bases[2], 'http://a/b/c/g'], - ['../../' , bases[2], 'http://a/b/'], + ['./', bases[2], 'http://a/b/c/d;p=1/'], + ['../', bases[2], 'http://a/b/c/'], + ['../g', bases[2], 'http://a/b/c/g'], + ['../../', bases[2], 'http://a/b/'], ['../../g' , bases[2], 'http://a/b/g'], // http://gbiv.com/protocols/uri/test/rel_examples4.html // double and triple slash, unknown scheme - ['g:h' , bases[3], 'g:h'], - ['g' , bases[3], 'fred:///s//a/b/g'], - ['./g' , bases[3], 'fred:///s//a/b/g'], - ['g/' , bases[3], 'fred:///s//a/b/g/'], - ['/g' , bases[3], 'fred:///g'], // may change to fred:///s//a/g - ['//g' , bases[3], 'fred://g'], // may change to fred:///s//g - ['//g/x' , bases[3], 'fred://g/x'], // may change to fred:///s//g/x - ['///g' , bases[3], 'fred:///g'], - ['./' , bases[3], 'fred:///s//a/b/'], - ['../' , bases[3], 'fred:///s//a/'], - ['../g' , bases[3], 'fred:///s//a/g'], + ['g:h', bases[3], 'g:h'], + ['g', bases[3], 'fred:///s//a/b/g'], + ['./g', bases[3], 'fred:///s//a/b/g'], + ['g/', bases[3], 'fred:///s//a/b/g/'], + ['/g', bases[3], 'fred:///g'], // may change to fred:///s//a/g + ['//g', bases[3], 'fred://g'], // may change to fred:///s//g + ['//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x + ['///g', bases[3], 'fred:///g'], + ['./', bases[3], 'fred:///s//a/b/'], + ['../', bases[3], 'fred:///s//a/'], + ['../g', bases[3], 'fred:///s//a/g'], - ['../../' , bases[3], 'fred:///s//'], + ['../../', bases[3], 'fred:///s//'], ['../../g' , bases[3], 'fred:///s//g'], ['../../../g', bases[3], 'fred:///s/g'], - ['../../../../g', bases[3], 'fred:///g'], // may change to fred:///s//a/../../../g + // may change to fred:///s//a/../../../g + ['../../../../g', bases[3], 'fred:///g'], // http://gbiv.com/protocols/uri/test/rel_examples5.html // double and triple slash, well-known scheme - ['g:h' , bases[4], 'g:h'], - ['g' , bases[4], 'http:///s//a/b/g'], - ['./g' , bases[4], 'http:///s//a/b/g'], - ['g/' , bases[4], 'http:///s//a/b/g/'], - ['/g' , bases[4], 'http:///g'], // may change to http:///s//a/g - ['//g' , bases[4], 'http://g'], // may change to http:///s//g - ['//g/x' , bases[4], 'http://g/x'], // may change to http:///s//g/x - ['///g' , bases[4], 'http:///g'], - ['./' , bases[4], 'http:///s//a/b/'], - ['../' , bases[4], 'http:///s//a/'], - ['../g' , bases[4], 'http:///s//a/g'], - ['../../' , bases[4], 'http:///s//'], + ['g:h', bases[4], 'g:h'], + ['g', bases[4], 'http:///s//a/b/g'], + ['./g', bases[4], 'http:///s//a/b/g'], + ['g/', bases[4], 'http:///s//a/b/g/'], + ['/g', bases[4], 'http:///g'], // may change to http:///s//a/g + ['//g', bases[4], 'http://g'], // may change to http:///s//g + ['//g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x + ['///g', bases[4], 'http:///g'], + ['./', bases[4], 'http:///s//a/b/'], + ['../', bases[4], 'http:///s//a/'], + ['../g', bases[4], 'http:///s//a/g'], + ['../../', bases[4], 'http:///s//'], ['../../g' , bases[4], 'http:///s//g'], - ['../../../g', bases[4], 'http:///s/g'], // may change to http:///s//a/../../g - ['../../../../g', bases[4], 'http:///g'], // may change to http:///s//a/../../../g + // may change to http:///s//a/../../g + ['../../../g', bases[4], 'http:///s/g'], + // may change to http:///s//a/../../../g + ['../../../../g', bases[4], 'http:///g'], // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py - ["bar:abc", "foo:xyz", "bar:abc"], + ['bar:abc', 'foo:xyz', 'bar:abc'], ['../abc', 'http://example/x/y/z', 'http://example/x/abc'], ['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'], ['../r', 'http://ex/x/y/z', 'http://ex/x/r'], @@ -434,7 +460,9 @@ var bases = [ ['', 'http://ex/x/y/', 'http://ex/x/y/'], ['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'], ['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'], - ['#Animal', 'file:/swap/test/animal.rdf', 'file:/swap/test/animal.rdf#Animal'], + ['#Animal', + 'file:/swap/test/animal.rdf', + 'file:/swap/test/animal.rdf#Animal'], ['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'], ['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'], ['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'], @@ -448,12 +476,16 @@ var bases = [ ['', 'file:/ex/x/y/', 'file:/ex/x/y/'], ['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'], ['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'], - ['file://meetings.example.com/cal#m1', 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3', 'file://meetings.example.com/cal#m1'], - ['file://meetings.example.com/cal#m1', 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3', 'file://meetings.example.com/cal#m1'], + ['file://meetings.example.com/cal#m1', + 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3', + 'file://meetings.example.com/cal#m1'], + ['file://meetings.example.com/cal#m1', + 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3', + 'file://meetings.example.com/cal#m1'], ['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'], ['./#', 'file:/some/dir/foo', 'file:/some/dir/#'], // Ryan Lee - ["./", "http://example/x/abc.efg", "http://example/x/"], + ['./', 'http://example/x/abc.efg', 'http://example/x/'], // Graham Klyne's tests @@ -465,11 +497,15 @@ var bases = [ ['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'], ['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'], ['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'], - ['local/qual@domain.org#frag', 'mailto:local', 'mailto:local/qual@domain.org#frag'], - ['more/qual2@domain2.org#frag', 'mailto:local/qual1@domain1.org', 'mailto:local/more/qual2@domain2.org#frag'], + ['local/qual@domain.org#frag', + 'mailto:local', + 'mailto:local/qual@domain.org#frag'], + ['more/qual2@domain2.org#frag', + 'mailto:local/qual1@domain1.org', + 'mailto:local/more/qual2@domain2.org#frag'], ['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'], ['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'], - ['c/d', 'foo:a/b', 'foo:a/c/d'], + ['c/d', 'foo:a/b', 'foo:a/c/d'], ['/c/d', 'foo:a/b', 'foo:/c/d'], ['', 'foo:a/b?c#d', 'foo:a/b?c'], ['b/c', 'foo:a', 'foo:b/c'], @@ -494,8 +530,12 @@ var bases = [ // 70-77 ['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'], - ['local2@domain2?query2', 'mailto:local1@domain1', 'mailto:local2@domain2?query2'], - ['local2@domain2?query2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2?query2'], + ['local2@domain2?query2', + 'mailto:local1@domain1', + 'mailto:local2@domain2?query2'], + ['local2@domain2?query2', + 'mailto:local1@domain1?query1', + 'mailto:local2@domain2?query2'], ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], ['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'], ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], @@ -503,19 +543,26 @@ var bases = [ ['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'], // 82-88 - // ['http:this', 'http://example.org/base/uri', 'http:this'], // @isaacs Disagree. Not how browsers do it. - ['http:this', 'http://example.org/base/uri', "http://example.org/base/this"], // @isaacs Added + // @isaacs Disagree. Not how browsers do it. + // ['http:this', 'http://example.org/base/uri', 'http:this'], + // @isaacs Added + ['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'], ['http:this', 'http:base', 'http:this'], ['.//g', 'f:/a', 'f://g'], ['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'], - ['m2@example.ord/c2@example.org', 'mid:m@example.ord/c@example.org', 'mid:m@example.ord/m2@example.ord/c2@example.org'], - ['mini1.xml', 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/', 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'], + ['m2@example.ord/c2@example.org', + 'mid:m@example.ord/c@example.org', + 'mid:m@example.ord/m2@example.ord/c2@example.org'], + ['mini1.xml', + 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/', + 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'], ['../b/c', 'foo:a/y/z', 'foo:a/b/c'] -].forEach(function (relativeTest) { +]; +relativeTests2.forEach(function(relativeTest) { var a = url.resolve(relativeTest[1], relativeTest[0]), - e = relativeTest[2]; + e = relativeTest[2]; assert.equal(e, a, - "resolve("+[relativeTest[1], relativeTest[0]]+") == "+e+ - "\n actual="+a); + 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e + + '\n actual=' + a); }); |