Skip to content

Commit

Permalink
tests: more e2e tests for live updating rewrite rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed May 22, 2015
1 parent bf0c4f7 commit d3fff5c
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/server/proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ module.exports = function createProxyServer (bs, scripts) {

var opts = getOptions(bs, scripts);

var foxy = require("foxy").create(options.getIn(["proxy", "target"]), opts);
bs.proxy = require("foxy").create(options.getIn(["proxy", "target"]), opts);

bs.proxy = foxy;

var proxy = utils.getServer(foxy.app, bs.options);
var proxy = utils.getServer(bs.proxy.app, bs.options);

/**
* How best to handle websockets going forward?
Expand Down
49 changes: 49 additions & 0 deletions test/specs/e2e/server/e2e.server.rewrite.rules.add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";

var browserSync = require("../../../../index");

var request = require("supertest");
var assert = require("chai").assert;

describe("E2E server test with rewrite rules added on the fly", function () {

var bs;

before(function (done) {

browserSync.reset();

var config = {
server: {
baseDir: "test/fixtures"
},
logLevel: "silent",
open: false
};

bs = browserSync.init(config, done).instance;
});

after(function () {
bs.cleanup();
});

it("serves files with HTML rewritten", function (done) {

bs.addRewriteRule({
match: /Forms/g,
fn: function () {
return "Shane's forms";
}
});

request(bs.server)
.get("/index.html")
.set("accept", "text/html")
.expect(200)
.end(function (err, res) {
assert.include(res.text, "Shane's forms");
done();
});
});
});
61 changes: 61 additions & 0 deletions test/specs/e2e/server/e2e.server.rewrite.rules.remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"use strict";

var browserSync = require("../../../../index");

var request = require("supertest");
var assert = require("chai").assert;

describe("E2E server test with rewrite rules removed on the fly", function () {

var bs;

before(function (done) {

browserSync.reset();

var config = {
server: {
baseDir: "test/fixtures"
},
logLevel: "silent",
open: false
};

bs = browserSync.init(config, done).instance;
});

after(function () {
bs.cleanup();
});

it("serves files with HTML rewritten", function (done) {

bs.addRewriteRule({
id: "myrule",
match: /Forms/g,
fn: function () {
return "Shane's forms";
}
});

request(bs.server)
.get("/index.html")
.set("accept", "text/html")
.expect(200)
.end(function (err, res) {
assert.include(res.text, "Shane's forms");

bs.removeRewriteRule("myrule");

request(bs.server)
.get("/index.html")
.set("accept", "text/html")
.expect(200)
.end(function (err, res) {
assert.notInclude(res.text, "Shane's forms");
done();
});

});
});
});

0 comments on commit d3fff5c

Please sign in to comment.