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