« index
Coverage for /Users/kris/q-io/spec/http/basic-spec.js : 100%
94 lines |
94 run |
0 missing |
0 partial |
13 blocks |
13 blocks run |
0 blocks missing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | require("../lib/jasmine-promise"); var Q = require("q"); var HTTP = require("../../http"); describe("http server and client", function () { it("should work as both server and client", function () { var response = { "status": 200, "headers": { "content-type": "text/plain" }, "body": [ "Hello, World!" ] }; var server = HTTP.Server(function () { return response; }); return server.listen(0) .then(function (server) { var port = server.address().port; var request = { "host": "localhost", "port": port, "headers": { "host": "localhost" } }; return HTTP.request(request) .then(function (response) { expect(Q.isPromise(response.body)).toBe(false); var acc = []; return response.body.read() .then(function (body) { expect(body.toString("utf-8")).toBe("Hello, World!"); }); }) }) .finally(server.stop) }); it("should defer a response", function () { var response = { "status": 200, "headers": { "content-type": "text/plain; charset=utf-8" }, "body": { "forEach": function (write) { var deferred = Q.defer(); write("Hello, World!"); setTimeout(function () { deferred.resolve(); }, 100); return deferred.promise; } } }; var server = HTTP.Server(function () { return response; }); return server.listen(0).then(function (server) { var port = server.node.address().port; var request = { "host": "localhost", "port": port, "headers": { "host": "localhost" }, "charset": "utf-8" }; return HTTP.request(request) .then(function (response) { var acc = []; return response.body.read() .then(function (body) { expect(body).toBe("Hello, World!"); }); }) }) .finally(server.stop) }); }); |