Skip to content

Commit

Permalink
Add failing test for BrowserSync/browser-sync#381
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 3, 2015
1 parent 3542cc0 commit e39d8de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion test/specs/rewrite/rewrite.redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var connect = require("connect");
var http = require("http");
var foxy = require("../../../");
var getUrl = require("./helpers").getUrl;
describe("rewrite paths", (function() {
describe("Rewrite redirect headers", (function() {
var app,
server,
serverUrl,
Expand All @@ -20,6 +20,11 @@ describe("rewrite paths", (function() {
res.end();
next();
}));
app.use("/redirect-google", (function(req, res, next) {
res.writeHead(302, {"Location": "http://www.google.co.uk"});
res.end();
next();
}));
proxy = foxy("http://127.0.0.1:" + port).listen();
done();
}));
Expand All @@ -35,4 +40,12 @@ describe("rewrite paths", (function() {
done();
}));
}));
it("Should NOT re-write redirect location if external", (function(done) {
var proxyPort = proxy.address().port;
http.get(("http://localhost:" + proxyPort + "/redirect-google"), (function(res) {
assert.equal(res.statusCode, 302);
assert.equal(res.headers["location"], "http://www.google.co.uk");
done();
}));
}));
}));
15 changes: 14 additions & 1 deletion test/src/rewrite/rewrite.redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var http = require("http");
var foxy = require("../../../");
var getUrl = require("./helpers").getUrl;

describe("rewrite paths", () => {
describe("Rewrite redirect headers", () => {

var app, server, serverUrl, port, proxy;

Expand All @@ -18,6 +18,11 @@ describe("rewrite paths", () => {
res.end();
next();
});
app.use("/redirect-google", (req, res, next) => {
res.writeHead(302, {"Location": "http://www.google.co.uk"});
res.end();
next();
});
proxy = foxy("http://127.0.0.1:" + port).listen();
done();
});
Expand All @@ -35,4 +40,12 @@ describe("rewrite paths", () => {
done();
});
});
it("Should NOT re-write redirect location if external", done => {
var proxyPort = proxy.address().port;
http.get(`http://localhost:${proxyPort}/redirect-google`, res => {
assert.equal(res.statusCode, 302);
assert.equal(res.headers["location"], `http://www.google.co.uk`);
done();
});
});
});

0 comments on commit e39d8de

Please sign in to comment.