2015-05-11 00:43:47 +08:00
|
|
|
/* globals describe it */
|
|
|
|
require("should");
|
2013-12-03 20:01:03 +08:00
|
|
|
var path = require("path");
|
|
|
|
var fs = require("fs");
|
|
|
|
var webpack = require("../");
|
|
|
|
|
|
|
|
describe("Examples", function() {
|
|
|
|
var examples = fs.readdirSync(path.join(__dirname, "..", "examples")).map(function(name) {
|
|
|
|
return path.join(__dirname, "..", "examples", name);
|
|
|
|
}).filter(function(p) {
|
2015-10-13 23:53:54 +08:00
|
|
|
return fs.statSync(p).isDirectory() && fs.existsSync(path.join(p, "build.js"));
|
2013-12-03 20:01:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
examples.forEach(function(examplePath) {
|
|
|
|
it("should compile " + path.basename(examplePath), function(done) {
|
2016-07-13 18:45:56 +08:00
|
|
|
this.timeout(20000);
|
2013-12-03 20:01:03 +08:00
|
|
|
var options = {};
|
2014-06-03 03:26:57 +08:00
|
|
|
var webpackConfigPath = path.join(examplePath, "webpack.config.js");
|
|
|
|
webpackConfigPath = webpackConfigPath.substr(0, 1).toUpperCase() + webpackConfigPath.substr(1);
|
|
|
|
if(fs.existsSync(webpackConfigPath))
|
|
|
|
options = require(webpackConfigPath);
|
2014-06-12 05:01:05 +08:00
|
|
|
if(Array.isArray(options))
|
|
|
|
options.forEach(processOptions);
|
|
|
|
else
|
|
|
|
processOptions(options);
|
2015-08-09 18:42:43 +08:00
|
|
|
|
2014-06-12 05:01:05 +08:00
|
|
|
function processOptions(options) {
|
|
|
|
options.context = examplePath;
|
|
|
|
options.output = options.output || {};
|
2016-09-19 06:54:35 +08:00
|
|
|
options.output.pathinfo = true;
|
2014-06-12 05:01:05 +08:00
|
|
|
options.output.path = path.join(examplePath, "js");
|
|
|
|
options.output.publicPath = "js/";
|
|
|
|
if(!options.output.filename)
|
|
|
|
options.output.filename = "output.js";
|
|
|
|
if(!options.entry)
|
|
|
|
options.entry = "./example.js";
|
|
|
|
}
|
2013-12-03 20:01:03 +08:00
|
|
|
webpack(options, function(err, stats) {
|
|
|
|
if(err) return done(err);
|
2015-08-09 19:32:19 +08:00
|
|
|
stats = stats.toJson({
|
|
|
|
errorDetails: true
|
|
|
|
});
|
2015-01-13 00:45:30 +08:00
|
|
|
if(stats.errors.length > 0) {
|
|
|
|
return done(new Error(stats.errors[0]));
|
|
|
|
}
|
2013-12-03 20:01:03 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-08-09 18:42:43 +08:00
|
|
|
});
|