forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples.test.js
62 lines (58 loc) · 1.75 KB
/
Examples.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict";
/* describe it */
const path = require("path");
const fs = require("graceful-fs");
const webpack = require("..");
describe("Examples", () => {
const basePath = path.join(__dirname, "..", "examples");
const examples = require("../examples/examples.js");
examples.forEach(examplePath => {
const filterPath = path.join(examplePath, "test.filter.js");
const relativePath = path.relative(basePath, examplePath);
if (fs.existsSync(filterPath) && !require(filterPath)()) {
describe.skip(relativePath, () => it("filtered"));
return;
}
it(
"should compile " + relativePath,
function (done) {
let options = {};
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
webpackConfigPath =
webpackConfigPath.substr(0, 1).toUpperCase() +
webpackConfigPath.substr(1);
if (fs.existsSync(webpackConfigPath))
options = require(webpackConfigPath);
if (typeof options === "function") options = options();
if (Array.isArray(options)) options.forEach(processOptions);
else processOptions(options);
function processOptions(options) {
options.context = examplePath;
options.output = options.output || {};
options.output.pathinfo = true;
options.output.path = path.join(examplePath, "dist");
options.output.publicPath = "dist/";
if (!options.entry) options.entry = "./example.js";
if (!options.plugins) options.plugins = [];
}
webpack(options, (err, stats) => {
if (err) return done(err);
if (stats.hasErrors()) {
return done(
new Error(
stats.toString({
all: false,
errors: true,
errorDetails: true,
errorStacks: true
})
)
);
}
done();
});
},
45000
);
});
});