Permalink
Browse files

Changed test structure to no longer require a server, modeled on the …

…oauth tests. This also lets me revert some of the changes I had to make to the test server and proxy tests
  • Loading branch information...
1 parent 0f24051 commit becedaaa7681b0c4ad5c0a9b9922fc950f091af2 @csainty csainty committed Feb 19, 2012
Showing with 22 additions and 47 deletions.
  1. +1 −2 tests/server.js
  2. +1 −1 tests/test-proxy.js
  3. +20 −44 tests/test-qs.js
View
@@ -5,13 +5,12 @@ var fs = require('fs')
, events = require('events')
, stream = require('stream')
, assert = require('assert')
- , url = require('url')
;
exports.createServer = function (port) {
port = port || 6767
var s = http.createServer(function (req, resp) {
- s.emit(url.parse(req.url).pathname, req, resp);
+ s.emit(req.url, req, resp);
})
s.port = port
s.url = 'http://localhost:'+port
View
@@ -15,7 +15,7 @@ var port = 6768
var s = server.createServer(port)
s.listen(port, function () {
- s.on('/', function (req, res) {
+ s.on('http://google.com/', function (req, res) {
called = true
assert.equal(req.headers.host, proxiedHost)
res.writeHeader(200)
View
@@ -1,52 +1,28 @@
var request = request = require('../main.js')
, assert = require('assert')
- , url = require('url')
- , qs = require('querystring')
- , server = require('./server')
- , s = server.createServer()
;
-s.listen(s.port, function () {
- var serverUri = 'http://localhost:' + s.port
- , numTests = 0
- , numOutstandingTests = 0
- function createTest(requestObj, query, serverAssertFn) {
- var testNumber = numTests;
- numTests += 1;
- numOutstandingTests += 1;
- s.on('/' + testNumber, function (req, res) {
- serverAssertFn(req, res);
- res.writeHead(200);
- res.end();
- });
- requestObj.url = serverUri + '/' + testNumber + query
- request(requestObj, function (err, res, body) {
- assert.ok(!err)
- assert.equal(res.statusCode, 200)
- numOutstandingTests -= 1
- if (numOutstandingTests === 0) {
- console.log(numTests + ' tests passed.')
- s.close()
- }
- })
- }
+// Test adding a querystring
+var req1 = request.get({ uri: 'http://localhost', qs: { q : 'search' }})
+setTimeout(function() {
+ assert.equal('/?q=search', req1.path)
+}, 1)
- // Test adding a querystring
- createTest({ qs: { q : 'search' } }, '', function (req, res) {
- var result = qs.parse(url.parse(req.url).query)
- assert.deepEqual({ q : 'search' }, result)
- })
+// Test replacing a querystring value
+var req2 = request.get({ uri: 'http://localhost?q=abc', qs: { q : 'search' }})
+setTimeout(function() {
+ assert.equal('/?q=search', req2.path)
+}, 1)
- // Test replacing a querystring value
- createTest({ qs: { q : 'search' } }, '?q=abc', function (req, res) {
- var result = qs.parse(url.parse(req.url).query)
- assert.deepEqual({ q : 'search' }, result)
- })
+// Test appending a querystring value to the ones present in the uri
+var req3 = request.get({ uri: 'http://localhost?x=y', qs: { q : 'search' }})
+setTimeout(function() {
+ assert.equal('/?x=y&q=search', req3.path)
+}, 1)
- // Test appending a querystring value to the ones present in the uri
- createTest({ qs: { q : 'search' } }, '?x=y', function (req, res) {
- var result = qs.parse(url.parse(req.url).query)
- assert.deepEqual({ q : 'search', x : 'y' }, result)
- })
-})
+// Test leaving a querystring alone
+var req4 = request.get({ uri: 'http://localhost?x=y'})
+setTimeout(function() {
+ assert.equal('/?x=y', req4.path)
+}, 1)

0 comments on commit becedaa

Please sign in to comment.