webpack/test/Integration.test.js

100 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-01-18 18:53:19 +08:00
"use strict";
2013-01-31 01:49:25 +08:00
2017-11-15 21:08:11 +08:00
require("should");
2017-01-18 18:53:19 +08:00
const path = require("path");
const webpack = require("../lib/webpack");
2013-01-31 01:49:25 +08:00
2013-02-01 16:08:06 +08:00
describe("Integration", function() {
2014-03-03 21:56:27 +08:00
this.timeout(5000);
2017-01-18 18:53:19 +08:00
it("should compile library1", (done) => {
2013-01-31 01:49:25 +08:00
webpack({
mode: "production",
2013-01-31 01:49:25 +08:00
entry: "library1",
2014-03-19 05:34:35 +08:00
bail: true,
2013-01-31 01:49:25 +08:00
context: path.join(__dirname, "browsertest"),
output: {
pathinfo: true,
path: path.join(__dirname, "browsertest", "js"),
filename: "library1.js",
library: "library1"
}
2017-01-18 18:53:19 +08:00
}, (err, stats) => {
2013-01-31 01:49:25 +08:00
if(err) throw err;
2017-01-02 08:44:24 +08:00
stats.hasErrors().should.be.not.ok();
stats.hasWarnings().should.be.not.ok();
2013-01-31 01:49:25 +08:00
done();
});
});
2017-01-18 18:53:19 +08:00
it("should compile library2", (done) => {
2013-01-31 01:49:25 +08:00
webpack({
mode: "production",
2013-01-31 01:49:25 +08:00
entry: "library2",
context: path.join(__dirname, "browsertest"),
output: {
pathinfo: true,
path: path.join(__dirname, "browsertest", "js"),
filename: "library2.js",
publicPath: "js/",
library: "library2"
},
2014-03-19 05:34:35 +08:00
bail: true,
2013-01-31 01:49:25 +08:00
module: {
2016-09-21 01:39:20 +08:00
rules: [{
2015-08-09 18:42:43 +08:00
test: /extra2\.js/,
2016-09-21 01:39:20 +08:00
loader: "raw!extra!val?cacheable",
enforce: "post"
2015-08-09 18:42:43 +08:00
}]
2013-01-31 01:49:25 +08:00
},
amd: {
fromOptions: true
},
2017-12-13 23:05:21 +08:00
optimization: {
minimize: false
},
2013-10-16 05:59:02 +08:00
resolve: {
// cannot resolve should outside the outermost node_modules
// so it is injected here
2015-08-09 18:42:43 +08:00
alias: {
should: require.resolve("should")
}
2013-10-16 05:59:02 +08:00
},
plugins: [
2015-08-09 18:42:43 +08:00
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
new webpack.DefinePlugin({
2014-05-27 18:42:41 +08:00
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
CONST_TRUE: true,
CONST_FALSE: false,
2015-08-09 18:42:43 +08:00
CONST_FUNCTION: function() {
return "ok";
},
CONST_NUMBER: 123,
CONST_NUMBER_EXPR: "1*100+23",
CONST_OBJECT: {
A: 1,
B: JSON.stringify("B"),
2015-08-09 18:42:43 +08:00
C: function() {
return "C";
}
}
}),
function() {
2017-12-20 23:51:24 +08:00
this.hooks.normalModuleFactory.tap("IntegrationTest", (nmf) => {
nmf.hooks.afterResolve.tapAsync("IntegrationTest", (data, callback) => {
2014-10-09 14:53:00 +08:00
data.resource = data.resource.replace(/extra\.js/, "extra2.js");
2017-01-18 18:53:19 +08:00
setTimeout(() => callback(null, data), 50);
});
2013-01-31 01:49:25 +08:00
});
}
]
2017-01-18 18:53:19 +08:00
}, (err, stats) => {
2013-01-31 01:49:25 +08:00
if(err) throw err;
2017-01-02 08:44:24 +08:00
stats.hasErrors().should.be.not.ok();
stats.hasWarnings().should.be.not.ok();
2013-01-31 01:49:25 +08:00
done();
});
});
2015-08-09 18:42:43 +08:00
});