Permalink
Browse files

using request for tests now

  • Loading branch information...
substack committed Sep 15, 2010
1 parent 4f73bfa commit 18bd9e93e6e8972f5ad86046cf2b53b790e72162
Showing with 7 additions and 26 deletions.
  1. +7 −26 test/web.js
View
@@ -1,6 +1,6 @@
var Cart = require('cart');
var connect = require('connect');
-var http = require('http');
+var request = require('request');
var qs = require('querystring');
exports.webserver = function (assert) {
@@ -21,41 +21,22 @@ exports.webserver = function (assert) {
res.end();
});
app.post('/login', function (req, res) {
-console.dir(req.body);
res.writeHead(200, { 'Content-Type' : 'text/html' });
res.write('meow');
res.end();
});
}));
server.listen(port, 'localhost');
-
- var get = request.bind({}, port, 'GET', {});
- var post = request.bind({}, port, 'POST');
+ var uri = 'http://localhost:' + port + '/';
setTimeout(function () {
- get('/', function (s) {
- assert.equal('catface', s);
- });
- post({ user : 'substack', pass : 'hax' }, '/login', function (s) {
- console.log(s);
+ request({ uri : uri }, function (err, res, body) {
+ assert.equal('catface', body);
+ var cookie = res.headers['set-cookie'][0];
+ var cookies = qs.parse(cookie);
+ assert.ok(cookies.connect.sid);
});
}, 100);
setTimeout(function () { server.close() }, 500);
};
-
-function request (port, method, vars, path, cb) {
- var client = http.createClient(port);
- var opts = { host : 'localhost' };
- if (method == 'POST') {
- opts['Content-Type'] = 'application/x-www-form-urlencoded';
- }
- var req = client.request(method, path, opts);
- req.end(qs.stringify(vars));
-
- req.on('response', function (res) {
- var s = '';
- res.on('data', function (buf) { s += buf.toString() });
- res.on('end', function () { cb(s) });
- });
-}

0 comments on commit 18bd9e9

Please sign in to comment.