-
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.
feat(server): add serveFile method for plugin use
- Loading branch information
1 parent
f77fd80
commit c500787
Showing
4 changed files
with
140 additions
and
22 deletions.
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
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,93 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../index"); | ||
|
||
var assert = require("chai").assert; | ||
var request = require("supertest"); | ||
|
||
describe("Plugins: Should be able to call `serveFile` on the instance when in server mode", function () { | ||
|
||
var PLUGIN_NAME = "KITTENZ"; | ||
var instance; | ||
|
||
before(function (done) { | ||
|
||
browserSync.reset(); | ||
|
||
var config = { | ||
logLevel: "silent", | ||
open: false, | ||
server: "test/fixtures" | ||
}; | ||
|
||
browserSync.use({ | ||
plugin: function (opts, bs) { | ||
bs.serveFile("/shane", { | ||
type: "text/css", | ||
content: "Hi there" | ||
}); | ||
done(); | ||
}, | ||
"plugin:name": PLUGIN_NAME | ||
}); | ||
|
||
instance = browserSync(config).instance; | ||
}); | ||
after(function () { | ||
instance.cleanup(); | ||
}); | ||
it("should serve the file", function (done) { | ||
request(instance.server) | ||
.get("/shane") | ||
.set("accept", "text/html") | ||
.expect(200) | ||
.end(function (err, res) { | ||
assert.include(res.text, "Hi there"); | ||
assert.equal(res.headers["content-type"], "text/css"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Plugins: Should be able to call `serveFile` on the instance when in snippet mode", function () { | ||
|
||
var PLUGIN_NAME = "KITTENZ"; | ||
var instance; | ||
|
||
before(function (done) { | ||
|
||
browserSync.reset(); | ||
|
||
var config = { | ||
logLevel: "silent", | ||
open: false | ||
}; | ||
|
||
browserSync.use({ | ||
plugin: function (opts, bs) { | ||
bs.serveFile("/shane", { | ||
type: "text/css", | ||
content: "Hi there" | ||
}); | ||
done(); | ||
}, | ||
"plugin:name": PLUGIN_NAME | ||
}); | ||
|
||
instance = browserSync(config).instance; | ||
}); | ||
after(function () { | ||
instance.cleanup(); | ||
}); | ||
it("should serve the file", function (done) { | ||
request(instance.server) | ||
.get("/shane") | ||
.set("accept", "text/html") | ||
.expect(200) | ||
.end(function (err, res) { | ||
assert.include(res.text, "Hi there"); | ||
assert.equal(res.headers["content-type"], "text/css"); | ||
done(); | ||
}); | ||
}); | ||
}); |