2017-01-18 18:33:28 +08:00
|
|
|
"use strict";
|
|
|
|
|
2015-05-11 00:43:47 +08:00
|
|
|
/* globals describe it */
|
2017-01-18 18:33:28 +08:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
|
|
|
const webpack = require("../");
|
2013-12-03 20:01:03 +08:00
|
|
|
|
2017-01-18 18:33:28 +08:00
|
|
|
describe("Examples", () => {
|
2017-07-27 19:24:56 +08:00
|
|
|
const basePath = path.join(__dirname, "..", "examples");
|
|
|
|
const examples = require("../examples/examples.js");
|
2013-12-03 20:01:03 +08:00
|
|
|
|
2017-01-18 18:33:28 +08:00
|
|
|
examples.forEach((examplePath) => {
|
2017-12-21 15:51:07 +08:00
|
|
|
const filterPath = path.join(examplePath, "test.filter.js");
|
2018-02-25 08:20:45 +08:00
|
|
|
const relativePath = path.relative(basePath, examplePath);
|
2017-12-21 15:51:07 +08:00
|
|
|
if(fs.existsSync(filterPath) && !require(filterPath)()) {
|
2018-02-25 08:20:45 +08:00
|
|
|
describe.skip(relativePath, () => it("filtered"));
|
2017-12-21 15:51:07 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-02-25 08:20:45 +08:00
|
|
|
it("should compile " + relativePath, function(done) {
|
2017-01-18 18:33:28 +08:00
|
|
|
let options = {};
|
|
|
|
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
|
2014-06-03 03:26:57 +08:00
|
|
|
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;
|
2018-01-10 03:30:20 +08:00
|
|
|
options.output.path = path.join(examplePath, "dist");
|
|
|
|
options.output.publicPath = "dist/";
|
2014-06-12 05:01:05 +08:00
|
|
|
if(!options.entry)
|
|
|
|
options.entry = "./example.js";
|
2017-09-22 20:34:51 +08:00
|
|
|
if(!options.plugins)
|
|
|
|
options.plugins = [];
|
|
|
|
// To support deprecated loaders
|
|
|
|
// TODO remove in webpack 5
|
|
|
|
options.plugins.push(new webpack.LoaderOptionsPlugin({
|
|
|
|
options: {}
|
|
|
|
}));
|
2014-06-12 05:01:05 +08:00
|
|
|
}
|
2017-01-18 18:33:28 +08:00
|
|
|
webpack(options, (err, stats) => {
|
2013-12-03 20:01:03 +08:00
|
|
|
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();
|
|
|
|
});
|
2018-02-25 08:20:45 +08:00
|
|
|
}, 20000);
|
2013-12-03 20:01:03 +08:00
|
|
|
});
|
2015-08-09 18:42:43 +08:00
|
|
|
});
|