« index
Coverage for /Users/kris/q-io/spec/http-apps/directory-list-spec.js : 100%
84 lines |
84 run |
0 missing |
0 partial |
9 blocks |
9 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 | require("../lib/jasmine-promise"); var Http = require("../../http"); var Apps = require("../../http-apps"); var FS = require("../../fs"); describe("directory lists", function () { it("should be fine in plain text", function () { var fixture = FS.join(module.directory || __dirname, "fixtures"); var app = new Apps.Chain() .use(Apps.Cap) .use(Apps.ListDirectories) .use(function () { return Apps.FileTree(fixture); }) .end() return Http.Server(app) .listen(0) .then(function (server) { var port = server.address().port; return Http.read({ url: "http://127.0.0.1:" + port + "/", headers: { accept: "text/plain" }, charset: 'utf-8' }) .then(function (content) { expect(content).toEqual("1234.txt\n5678.txt\n9012/\n"); }) .finally(server.stop); }); }); it("should be fine in html", function () { var fixture = FS.join(module.directory || __dirname, "fixtures"); var app = new Apps.Chain() .use(Apps.Cap) .use(Apps.HandleHtmlFragmentResponses) .use(Apps.ListDirectories) .use(function () { return Apps.FileTree(fixture); }) .end() return Http.Server(app) .listen(0) .then(function (server) { var port = server.address().port; return Http.read({ url: "http://127.0.0.1:" + port + "/", headers: { accept: "text/html" }, charset: 'utf-8' }) .then(function (content) { expect(content).toEqual( "<!doctype html>\n" + "<html>\n" + " <head>\n" + " <title>Directory Index</title>\n" + " </head>\n" + " <body>\n" + " <ul class=\"directory-index\">\n" + " <li class=\"entry file\"><a href=\"1234.txt\">1234.txt</a></li>\n" + " <li class=\"entry file\"><a href=\"5678.txt\">5678.txt</a></li>\n" + " <li class=\"entry directory\"><a href=\"9012/\">9012/</a></li>\n" + " </ul>\n" + " </body>\n" + "</html>\n" ); }) .finally(server.stop); }); }); }); |