-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugins): Allow plugins to register middleware via server:middlew…
…are hook when in proxy mode - fixes #663
- Loading branch information
1 parent
864bdf0
commit 104dbb4
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../"); | ||
var testUtils = require("../../protractor/utils"); | ||
var Immutable = require("immutable"); | ||
var sinon = require("sinon"); | ||
var request = require("supertest"); | ||
|
||
describe("Plugins: Should be able to register middleware when in proxy mode", function () { | ||
|
||
var bs; | ||
var app; | ||
var spy; | ||
|
||
before(function (done) { | ||
|
||
browserSync.reset(); | ||
|
||
app = testUtils.getApp(Immutable.Map({scheme: "http"})); | ||
app.server.listen(); | ||
|
||
spy = sinon.spy(); | ||
|
||
var config = { | ||
proxy: "http://localhost:" + app.server.address().port, | ||
open: false, | ||
logLevel: "silent" | ||
}; | ||
|
||
browserSync.use({ | ||
"plugin": function () { | ||
/* noop */ | ||
}, | ||
"hooks": { | ||
"server:middleware": function () { | ||
return function (req, res, next) { | ||
spy(); | ||
next(); | ||
}; | ||
} | ||
}, | ||
"plugin:name": "KITTENZ" | ||
}); | ||
|
||
bs = browserSync(config, done).instance; | ||
}); | ||
|
||
after(function () { | ||
bs.cleanup(); | ||
}); | ||
it("should serve the file", function (done) { | ||
request(bs.server) | ||
.get("/") | ||
.set("accept", "text/html") | ||
.end(function () { | ||
sinon.assert.calledOnce(spy); | ||
done(); | ||
}); | ||
}); | ||
}); |