2010-12-06 06:33:52 +08:00
|
|
|
var common = require('../common.js');
|
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
2009-06-21 22:40:08 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
console.log('hello world');
|
2009-08-25 02:25:24 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var body = 'exports.A = function() { return "A";}';
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
console.log('req?');
|
2009-08-25 02:25:24 +08:00
|
|
|
res.sendHeader(200, {
|
2010-12-06 06:33:52 +08:00
|
|
|
'Content-Length': body.length,
|
|
|
|
'Content-Type': 'text/plain'
|
2009-08-25 02:25:24 +08:00
|
|
|
});
|
2009-06-21 22:40:08 +08:00
|
|
|
res.sendBody(body);
|
|
|
|
res.finish();
|
|
|
|
});
|
2010-07-16 02:47:25 +08:00
|
|
|
server.listen(common.PORT);
|
2009-06-21 22:40:08 +08:00
|
|
|
|
2009-06-29 01:05:58 +08:00
|
|
|
var errors = 0;
|
|
|
|
var successes = 0;
|
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var promise = process.cat('http://localhost:' + common.PORT, 'utf8');
|
2009-06-29 01:05:58 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
promise.addCallback(function(content) {
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal(body, content);
|
2009-08-27 00:22:00 +08:00
|
|
|
server.close();
|
|
|
|
successes += 1;
|
|
|
|
});
|
2009-06-29 01:05:58 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
promise.addErrback(function() {
|
2009-08-27 00:22:00 +08:00
|
|
|
errors += 1;
|
|
|
|
});
|
|
|
|
|
2009-10-30 06:59:35 +08:00
|
|
|
var dirname = process.path.dirname(__filename);
|
2010-12-06 06:33:52 +08:00
|
|
|
var fixtures = process.path.join(dirname, 'fixtures');
|
|
|
|
var x = process.path.join(fixtures, 'x.txt');
|
2009-08-27 00:22:00 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
promise = process.cat(x, 'utf8');
|
2009-08-27 00:22:00 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
promise.addCallback(function(content) {
|
|
|
|
assert.equal('xyz', content.replace(/[\r\n]/, ''));
|
2009-08-27 00:22:00 +08:00
|
|
|
successes += 1;
|
|
|
|
});
|
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
promise.addErrback(function() {
|
2009-08-27 00:22:00 +08:00
|
|
|
errors += 1;
|
|
|
|
});
|
2009-06-29 01:05:58 +08:00
|
|
|
|
2011-10-15 07:08:36 +08:00
|
|
|
process.on('exit', function() {
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal(2, successes);
|
|
|
|
assert.equal(0, errors);
|
2009-08-27 00:51:04 +08:00
|
|
|
});
|