Skip to content

Commit 74d0e3a

Browse files
authored
Merge pull request faceyspacey#2 from scottdj92/json-tests
JSON tests
2 parents cec5e8a + 57533f1 commit 74d0e3a

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var ExtractedModule = require("./ExtractedModule");
99
var Chunk = require("webpack/lib/Chunk");
1010
var OrderUndefinedError = require("./OrderUndefinedError");
1111
var loaderUtils = require("loader-utils");
12-
var schemaTester = require('./schema/valid');
12+
var schemaTester = require('./schema/validator');
1313

1414
var NS = fs.realpathSync(__dirname);
1515

@@ -105,7 +105,6 @@ function getOrder(a, b) {
105105
}
106106

107107
function ExtractTextPlugin(options) {
108-
schemaTester(options);
109108
if(arguments.length > 1) {
110109
throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
111110
"object *or* the name of the result file.\n" +
@@ -120,6 +119,8 @@ function ExtractTextPlugin(options) {
120119
}
121120
if(isString(options)) {
122121
options = { filename: options };
122+
} else {
123+
schemaTester(options);
123124
}
124125
this.filename = options.filename;
125126
this.id = options.id != null ? options.id : ++nextId;

schema/schema.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"type": "string"
1717
},
1818
"filename": {
19-
"description": "The filename and path that ExtractTextPlugin will extract to.",
19+
"description": "The filename and path that ExtractTextPlugin will extract to",
2020
"type": "string"
2121
},
2222
"loader": {
@@ -27,6 +27,5 @@
2727
"description": "",
2828
"type": "string"
2929
}
30-
},
31-
"required": ["loader"]
30+
}
3231
}
File renamed without changes.

test/extract.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ describe("ExtractTextPlugin.extract()", function() {
1010
});
1111
});
1212

13+
context("json schema validation", function() {
14+
it("does not throw if a filename is specified", function() {
15+
should.doesNotThrow(function() {
16+
ExtractTextPlugin.extract("file.css");
17+
});
18+
});
19+
20+
it("does not throw if a correct config object is passed in", function() {
21+
should.doesNotThrow(function() {
22+
ExtractTextPlugin.extract({loader: 'css-loader'});
23+
});
24+
});
25+
26+
it("throws if an incorrect config is passed in", function() {
27+
should.throws(function() {
28+
ExtractTextPlugin.extract({style: 'file.css'});
29+
});
30+
});
31+
});
32+
1333
context("specifying loader", function() {
1434
it("accepts a loader string", function() {
1535
ExtractTextPlugin.extract("css-loader").should.deepEqual([

0 commit comments

Comments
 (0)