Skip to content

Commit 52d5609

Browse files
committed
Many more tests.
Ref #121
1 parent cedc09f commit 52d5609

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

test/Advanced.test.js renamed to test/API.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ describe("Advanced API", function() {
6767
instance.waitUntilValid(done);
6868
});
6969
});
70+
71+
it("should work without callback", function() {
72+
var instance = middleware(compiler, options);
73+
plugins.done(doneStats);
74+
setTimeout(function() {
75+
instance.waitUntilValid();
76+
});
77+
});
7078
});
7179

7280
describe("invalidate", function() {
@@ -91,6 +99,15 @@ describe("Advanced API", function() {
9199
doneCalled = true;
92100
});
93101
});
102+
103+
it("should work without callback", function(done) {
104+
var instance = middleware(compiler, options);
105+
instance.invalidate();
106+
setTimeout(function() {
107+
should.strictEqual(invalidationCount, 1);
108+
done();
109+
});
110+
});
94111
});
95112

96113
describe("close", function() {
@@ -106,6 +123,12 @@ describe("Advanced API", function() {
106123
done();
107124
});
108125
});
126+
127+
it("should call close on watcher without callback", function() {
128+
var instance = middleware(compiler, options);
129+
instance.close();
130+
should.strictEqual(closeCount, 1);
131+
});
109132
});
110133

111134
describe("getFilenameFromUrl", function() {

test/Reporter.test.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ describe("Reporter", function() {
1919
var plugins = {};
2020
var compiler = {
2121
watch: function() {
22-
return {};
22+
return {
23+
invalidate: function() {}
24+
};
2325
},
2426
plugin: function(name, callback) {
2527
plugins[name] = callback;
@@ -152,6 +154,42 @@ describe("Reporter", function() {
152154
});
153155
});
154156

157+
describe("wait until bundle valid", function() {
158+
it("should print message", function(done) {
159+
var instance = middleware(compiler);
160+
161+
plugins.invalid();
162+
instance.invalidate(function myInvalidateFunction() {});
163+
setTimeout(function() {
164+
should.strictEqual(console.log.callCount, 1);
165+
should.strictEqual(console.log.calledWith("webpack: wait until bundle finished: myInvalidateFunction"), true);
166+
done();
167+
});
168+
});
169+
170+
it("should not print if options.quiet is true", function(done) {
171+
var instance = middleware(compiler, { quiet: true });
172+
173+
plugins.invalid();
174+
instance.invalidate();
175+
setTimeout(function() {
176+
should.strictEqual(console.log.callCount, 0);
177+
done();
178+
});
179+
});
180+
181+
it("should not print if options.noInfo is true", function(done) {
182+
var instance = middleware(compiler, { noInfo: true });
183+
184+
plugins.invalid();
185+
instance.invalidate();
186+
setTimeout(function() {
187+
should.strictEqual(console.log.callCount, 0);
188+
done();
189+
});
190+
});
191+
});
192+
155193
describe("custom reporter", function() {
156194
it("should allow a custom reporter", function(done) {
157195
middleware(compiler, {

test/Server.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("Server", function() {
4141
it("GET request to bundle file", function(done) {
4242
request(app).get("/bundle.js")
4343
.expect("Content-Type", "application/javascript")
44-
// .expect("Content-Length", "2657")
44+
.expect("Content-Length", "2780")
4545
.expect("Access-Control-Allow-Origin", "*")
4646
.expect(200, /console\.log\("Hey\."\)/, done);
4747
});
@@ -64,6 +64,28 @@ describe("Server", function() {
6464
.expect("Content-Type", "text/html; charset=utf-8")
6565
.expect(404, done);
6666
});
67+
68+
it("request to directory", function(done) {
69+
request(app).get("/")
70+
.expect("Content-Type", "text/html")
71+
.expect("Content-Length", "10")
72+
.expect("Access-Control-Allow-Origin", "*")
73+
.expect(200, /My\ Index\./, done);
74+
});
75+
76+
it("invalid range header", function(done) {
77+
request(app).get("/svg.svg")
78+
.set("Range", "bytes=6000-")
79+
.expect(416, done);
80+
});
81+
82+
it("valid range header", function(done) {
83+
request(app).get("/svg.svg")
84+
.set("Range", "bytes=3000-3500")
85+
.expect("Content-Length", "501")
86+
.expect("Content-Range", "bytes 3000-3500/4778")
87+
.expect(206, done);
88+
});
6789
});
6890

6991
describe("custom headers", function() {

test/fixtures/server-test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My Index.

test/fixtures/server-test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require("./svg.svg");
2+
require("./index.html");
23

34
console.log("Hey.");

test/fixtures/server-test/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
module: {
99
loaders: [
1010
{
11-
test: /\.svg$/,
11+
test: /\.(svg|html)$/,
1212
loader: "file",
1313
query: { name: "[name].[ext]" }
1414
}

0 commit comments

Comments
 (0)