-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #623
- Loading branch information
Showing
16 changed files
with
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"mocha": true, | ||
"browser": true | ||
}, | ||
"rules": { | ||
|
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
/client/live.bundle.js | ||
/client/index.bundle.js | ||
/client/sockjs.bundle.js | ||
/coverage |
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,24 @@ | ||
var request = require("supertest"); | ||
var helper = require("./helper"); | ||
var config = require("./fixtures/simple-config/webpack.config"); | ||
|
||
describe("Compress", function() { | ||
var server; | ||
var req; | ||
|
||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
compress: true | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
after(helper.close); | ||
|
||
it("request to bundle file", function(done) { | ||
req.get("/bundle.js") | ||
.expect("Content-Encoding", "gzip") | ||
.expect(200, done); | ||
}); | ||
}); |
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 @@ | ||
var request = require("supertest"); | ||
var path = require("path"); | ||
var helper = require("./helper"); | ||
var config = require("./fixtures/contentbase-config/webpack.config"); | ||
|
||
var contentBasePublic = path.join(__dirname, "fixtures/contentbase-config/public"); | ||
var contentBaseOther = path.join(__dirname, "fixtures/contentbase-config/other"); | ||
|
||
describe("ContentBase", function() { | ||
var server; | ||
var req; | ||
afterEach(helper.close); | ||
|
||
describe("to directory", function() { | ||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
contentBase: contentBasePublic, | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
it("Request to index", function(done) { | ||
req.get("/") | ||
.expect(200, /Heyo/, done); | ||
}); | ||
|
||
it("Request to other file", function(done) { | ||
req.get("/other.html") | ||
.expect(200, /Other html/, done); | ||
}); | ||
}); | ||
|
||
describe("to directories", function() { | ||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
contentBase: [contentBasePublic, contentBaseOther], | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
it("Request to first directory", function(done) { | ||
req.get("/") | ||
.expect(200, /Heyo/, done); | ||
}); | ||
|
||
it("Request to second directory", function(done) { | ||
req.get("/foo.html") | ||
.expect(200, /Foo!/, done); | ||
}); | ||
}); | ||
|
||
describe("to port", function() { | ||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
contentBase: 9099999, | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
it("Request to page", function(done) { | ||
req.get("/other.html") | ||
.expect("Location", "//localhost:9099999/other.html") | ||
.expect(302, done); | ||
}); | ||
}); | ||
|
||
describe("to external url", function() { | ||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
contentBase: "http://example.com/", | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
it("Request to page", function(done) { | ||
req.get("/foo.html") | ||
// TODO: hmm, two slashes seems to be a bug? | ||
.expect("Location", "http://example.com//foo.html") | ||
.expect(302, done); | ||
}); | ||
|
||
it("Request to page with search params", function(done) { | ||
req.get("/foo.html?space=ship") | ||
// TODO: hmm, two slashes seems to be a bug? | ||
.expect("Location", "http://example.com//foo.html?space=ship") | ||
.expect(302, done); | ||
}); | ||
}); | ||
}); |
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,64 @@ | ||
var request = require("supertest"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var helper = require("./helper"); | ||
var config = require("./fixtures/simple-config/webpack.config"); | ||
|
||
var directoryIndex = fs.readFileSync(path.join(__dirname, "fixtures/directory-index.txt"), "utf-8"); | ||
var magicHtml = fs.readFileSync(path.join(__dirname, "fixtures/magic-html.txt"), "utf-8"); | ||
|
||
describe("Routes", function() { | ||
var server; | ||
var req; | ||
|
||
before(function(done) { | ||
server = helper.start(config, { | ||
quiet: true, | ||
headers: { "X-Foo": "1" } | ||
}, done); | ||
req = request(server.app); | ||
}); | ||
|
||
after(helper.close); | ||
|
||
it("GET request to inline bundle", function(done) { | ||
req.get("/webpack-dev-server.js") | ||
.expect("Content-Type", "application/javascript") | ||
.expect(200, done); | ||
}); | ||
|
||
it("GET request to live bundle", function(done) { | ||
req.get("/__webpack_dev_server__/live.bundle.js") | ||
.expect("Content-Type", "application/javascript") | ||
.expect(200, done); | ||
}); | ||
|
||
it("GET request to sockjs bundle", function(done) { | ||
req.get("/__webpack_dev_server__/sockjs.bundle.js") | ||
.expect("Content-Type", "application/javascript") | ||
.expect(200, done); | ||
}); | ||
|
||
it("GET request to live html", function(done) { | ||
req.get("/webpack-dev-server/") | ||
.expect("Content-Type", "text/html") | ||
.expect(200, /__webpack_dev_server__/, done); | ||
}); | ||
|
||
it("GET request to directory index", function(done) { | ||
req.get("/webpack-dev-server") | ||
.expect("Content-Type", "text/html") | ||
.expect(200, directoryIndex.trim(), done); | ||
}); | ||
|
||
it("GET request to magic html", function(done) { | ||
req.get("/bundle") | ||
.expect(200, magicHtml.trim(), done); | ||
}); | ||
|
||
it("GET request with headers", function(done) { | ||
req.get("/bundle") | ||
.expect("X-Foo", "1") | ||
.expect(200, done); | ||
}); | ||
}); |
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,3 @@ | ||
require("./index.html"); | ||
|
||
console.log("Hey."); |
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 @@ | ||
Foo! |
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 @@ | ||
Heyo. |
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 @@ | ||
Other html |
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,8 @@ | ||
module.exports = { | ||
context: __dirname, | ||
entry: "./foo.js", | ||
output: { | ||
filename: "bundle.js", | ||
publicPath: "/" | ||
} | ||
}; |
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 @@ | ||
<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><ul><li><a href="/bundle.js">bundle.js</a></li><li><a href="/bundle">bundle</a> (magic html for bundle.js) (<a href="/webpack-dev-server/bundle">webpack-dev-server</a>)</li></ul></body></html> |
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 @@ | ||
<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="/bundle.js"></script></body></html> |
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 @@ | ||
console.log("Hey."); |
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,8 @@ | ||
module.exports = { | ||
context: __dirname, | ||
entry: "./foo.js", | ||
output: { | ||
filename: "bundle.js", | ||
path: "/" | ||
} | ||
}; |
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,28 @@ | ||
var Server = require("../lib/Server"); | ||
var webpack = require("webpack"); | ||
|
||
var server; | ||
|
||
module.exports = { | ||
start: function(config, options, done) { | ||
var compiler = webpack(config); | ||
server = new Server(compiler, options); | ||
|
||
server.listen(8080, "localhost", function(err) { | ||
if(err) return done(err); | ||
done(); | ||
}); | ||
|
||
return server; | ||
}, | ||
close: function(done) { | ||
if(server) { | ||
server.close(function() { | ||
server = null; | ||
done(); | ||
}); | ||
} else { | ||
done(); | ||
} | ||
} | ||
}; |