Skip to content

Commit 5b6509c

Browse files
committed
test compiling of examples
1 parent f27995c commit 5b6509c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎test/Examples.test.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var should = require("should");
2+
var path = require("path");
3+
var fs = require("fs");
4+
var webpack = require("../");
5+
6+
describe("Examples", function() {
7+
var examples = fs.readdirSync(path.join(__dirname, "..", "examples")).map(function(name) {
8+
return path.join(__dirname, "..", "examples", name);
9+
}).filter(function(p) {
10+
return fs.statSync(p).isDirectory();
11+
});
12+
13+
examples.forEach(function(examplePath) {
14+
it("should compile " + path.basename(examplePath), function(done) {
15+
var options = {};
16+
if(fs.existsSync(path.join(examplePath, "webpack.config.js")))
17+
options = require(path.join(examplePath, "webpack.config.js"));
18+
options.context = examplePath;
19+
options.optimize = options.optimize || {};
20+
options.output = options.output || {};
21+
options.optimize.occurenceOrder = true;
22+
options.output.pathInfo = true;
23+
options.output.path = path.join(examplePath, "js")
24+
if(!options.output.filename)
25+
options.output.filename = "output.js";
26+
if(!options.entry)
27+
options.entry = "./example.js";
28+
webpack(options, function(err, stats) {
29+
if(err) return done(err);
30+
stats = stats.toJson();
31+
if(stats.errors.length > 0)
32+
return done(stats.errors[0]);
33+
done();
34+
});
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)