Created
June 30, 2012 03:42
-
-
Save phstc/3022075 to your computer and use it in GitHub Desktop.
vows test/integration/node-static-test.js --spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vows = require('vows') | |
, request = require('request') | |
, assert = require('assert') | |
, static = require('../../lib/node-static'); | |
var fileServer = new(static.Server)(__dirname + '/../fixtures', {}); | |
var suite = vows.describe('file-server.js'); | |
var TEST_PORT = 8080; | |
var TEST_SERVER = 'http://localhost:' + TEST_PORT; | |
suite.addBatch({ | |
'Once an http server is listening': { | |
topic: function () { | |
require('http').createServer(function (request, response) { | |
request.addListener('end', function () { | |
fileServer.serve(request, response); | |
}); | |
}).listen(TEST_PORT, this.callback) | |
}, | |
'file not found': { | |
topic : function(){ | |
request.get(TEST_SERVER + '/not-found', this.callback); | |
}, | |
'should respond with 404' : function(error, response, body){ | |
assert.equal(response.statusCode, 404); | |
} | |
} | |
} | |
}).addBatch({ | |
'serving hello.txt': { | |
topic : function(){ | |
request.get(TEST_SERVER + '/hello.txt', this.callback); | |
}, | |
'should respond with 200' : function(error, response, body){ | |
assert.equal(response.statusCode, 200); | |
}, | |
'should respond with text/plain': function(error, response, body){ | |
assert.equal(response.headers['content-type'], 'text/plain'); | |
}, | |
'should respond with hello world': function(error, response, body){ | |
assert.equal(body, 'hello world'); | |
} | |
} | |
}).addBatch({ | |
'implicit serving index.html': { | |
topic : function(){ | |
request.get(TEST_SERVER, this.callback); | |
}, | |
'should respond with 200' : function(error, response, body){ | |
assert.equal(response.statusCode, 200); | |
}, | |
'should respond with text/html': function(error, response, body){ | |
assert.equal(response.headers['content-type'], 'text/html'); | |
} | |
} | |
}).addBatch({ | |
'serving index.html from the cache': { | |
topic : function(){ | |
request.get(TEST_SERVER + '/index.html', this.callback); | |
}, | |
'should respond with 200' : function(error, response, body){ | |
assert.equal(response.statusCode, 200); | |
}, | |
'should respond with text/html': function(error, response, body){ | |
assert.equal(response.headers['content-type'], 'text/html'); | |
} | |
} | |
}).addBatch({ | |
'requesting with If-None-Match': { | |
topic : function(){ | |
var _this = this; | |
request.get(TEST_SERVER + '/index.html', function(error, response, body){ | |
request({ | |
method: 'GET', | |
uri: TEST_SERVER + '/index.html', | |
headers: {'if-none-match': response.headers['etag']} | |
}, | |
_this.callback); | |
}); | |
}, | |
'should respond with 304' : function(error, response, body){ | |
assert.equal(response.statusCode, 304); | |
} | |
} | |
}).addBatch({ | |
'requesting HEAD': { | |
topic : function(){ | |
request.head(TEST_SERVER + '/index.html', this.callback); | |
}, | |
'should respond with 200' : function(error, response, body){ | |
assert.equal(response.statusCode, 200); | |
}, | |
'head must has no body' : function(error, response, body){ | |
assert.isUndefined(body); | |
} | |
} | |
}).export(module); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment