Skip to content

Commit b284c6f

Browse files
committed
Add some simple tests for validation
1 parent 266bdf0 commit b284c6f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/Validation.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var config = require("./fixtures/simple-config/webpack.config");
2+
var OptionsValidationError = require("../lib/OptionsValidationError");
3+
var Server = require("../lib/Server");
4+
var webpack = require("webpack");
5+
6+
describe("Validation", function() {
7+
var compiler;
8+
before(function() {
9+
compiler = webpack(config);
10+
});
11+
var testCases = [{
12+
name: "invalid `hot` configuration",
13+
config: { hot: "asdf" },
14+
message: [
15+
" - configuration.hot should be a boolean."
16+
]
17+
}, {
18+
name: "invalid `public` configuration",
19+
config: { public: 1 },
20+
message: [
21+
" - configuration.public should be a string."
22+
]
23+
}, {
24+
name: "non-existing key configuration",
25+
config: { asdf: true },
26+
message: [
27+
" - configuration has an unknown property 'asdf'. These properties are valid:",
28+
" object { hot?, hotOnly?, lazy?, host?, filename?, publicPath?, port?, socket?, " +
29+
"watchOptions?, headers?, clientLogLevel?, key?, cert?, ca?, pfx?, pfxPassphrase?, " +
30+
"inline?, public?, https?, contentBase?, watchContentBase?, open?, features?, " +
31+
"compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " +
32+
"noInfo?, quiet?, serverSideRender?, index?, log?, warn? }"
33+
]
34+
}];
35+
testCases.forEach(function(testCase) {
36+
it("should fail validation for " + testCase.name, function() {
37+
try {
38+
new Server(compiler, testCase.config);
39+
} catch(e) {
40+
if(!(e instanceof OptionsValidationError))
41+
throw e;
42+
e.message.should.startWith("Invalid configuration object.");
43+
e.message.split("\n").slice(1).should.be.eql(testCase.message);
44+
return;
45+
}
46+
throw new Error("Validation didn't fail");
47+
})
48+
});
49+
});

0 commit comments

Comments
 (0)