|
| 1 | +var request = require("supertest"); |
| 2 | +var path = require("path"); |
| 3 | +var helper = require("./helper"); |
| 4 | +var config = require("./fixtures/contentbase-config/webpack.config"); |
| 5 | + |
| 6 | +var contentBasePublic = path.join(__dirname, "fixtures/contentbase-config/public"); |
| 7 | +var contentBaseOther = path.join(__dirname, "fixtures/contentbase-config/other"); |
| 8 | + |
| 9 | +describe("ContentBase", function() { |
| 10 | + var server; |
| 11 | + var req; |
| 12 | + afterEach(helper.close); |
| 13 | + |
| 14 | + describe("to directory", function() { |
| 15 | + before(function(done) { |
| 16 | + server = helper.start(config, { |
| 17 | + quiet: true, |
| 18 | + contentBase: contentBasePublic, |
| 19 | + }, done); |
| 20 | + req = request(server.app); |
| 21 | + }); |
| 22 | + |
| 23 | + it("Request to index", function(done) { |
| 24 | + req.get("/") |
| 25 | + .expect(200, /Heyo/, done); |
| 26 | + }); |
| 27 | + |
| 28 | + it("Request to other file", function(done) { |
| 29 | + req.get("/other.html") |
| 30 | + .expect(200, /Other html/, done); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe("to directories", function() { |
| 35 | + before(function(done) { |
| 36 | + server = helper.start(config, { |
| 37 | + quiet: true, |
| 38 | + contentBase: [contentBasePublic, contentBaseOther], |
| 39 | + }, done); |
| 40 | + req = request(server.app); |
| 41 | + }); |
| 42 | + |
| 43 | + it("Request to first directory", function(done) { |
| 44 | + req.get("/") |
| 45 | + .expect(200, /Heyo/, done); |
| 46 | + }); |
| 47 | + |
| 48 | + it("Request to second directory", function(done) { |
| 49 | + req.get("/foo.html") |
| 50 | + .expect(200, /Foo!/, done); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe("to port", function() { |
| 55 | + before(function(done) { |
| 56 | + server = helper.start(config, { |
| 57 | + quiet: true, |
| 58 | + contentBase: 9099999, |
| 59 | + }, done); |
| 60 | + req = request(server.app); |
| 61 | + }); |
| 62 | + |
| 63 | + it("Request to page", function(done) { |
| 64 | + req.get("/other.html") |
| 65 | + .expect("Location", "//localhost:9099999/other.html") |
| 66 | + .expect(302, done); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe("to external url", function() { |
| 71 | + before(function(done) { |
| 72 | + server = helper.start(config, { |
| 73 | + quiet: true, |
| 74 | + contentBase: "http://example.com/", |
| 75 | + }, done); |
| 76 | + req = request(server.app); |
| 77 | + }); |
| 78 | + |
| 79 | + it("Request to page", function(done) { |
| 80 | + req.get("/foo.html") |
| 81 | + // TODO: hmm, two slashes seems to be a bug? |
| 82 | + .expect("Location", "http://example.com//foo.html") |
| 83 | + .expect(302, done); |
| 84 | + }); |
| 85 | + |
| 86 | + it("Request to page with search params", function(done) { |
| 87 | + req.get("/foo.html?space=ship") |
| 88 | + // TODO: hmm, two slashes seems to be a bug? |
| 89 | + .expect("Location", "http://example.com//foo.html?space=ship") |
| 90 | + .expect(302, done); |
| 91 | + }); |
| 92 | + }); |
| 93 | +}); |
0 commit comments