node/test/disabled/test-cat.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

var common = require('../common.js');
var assert = require('assert');
var http = require('http');
2009-06-21 22:40:08 +08:00
console.log('hello world');
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'
});
2009-06-21 22:40:08 +08:00
res.sendBody(body);
res.finish();
});
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;
var promise = process.cat('http://localhost:' + common.PORT, 'utf8');
2009-06-29 01:05:58 +08:00
promise.addCallback(function(content) {
assert.equal(body, content);
2009-08-27 00:22:00 +08:00
server.close();
successes += 1;
});
2009-06-29 01:05:58 +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);
var fixtures = process.path.join(dirname, 'fixtures');
var x = process.path.join(fixtures, 'x.txt');
2009-08-27 00:22:00 +08:00
promise = process.cat(x, 'utf8');
2009-08-27 00:22:00 +08:00
promise.addCallback(function(content) {
assert.equal('xyz', content.replace(/[\r\n]/, ''));
2009-08-27 00:22:00 +08:00
successes += 1;
});
promise.addErrback(function() {
2009-08-27 00:22:00 +08:00
errors += 1;
});
2009-06-29 01:05:58 +08:00
process.on('exit', function() {
assert.equal(2, successes);
assert.equal(0, errors);
});