2013-01-31 01:49:25 +08:00
|
|
|
var should = require("should");
|
|
|
|
var path = require("path");
|
|
|
|
|
|
|
|
var webpack = require("../lib/webpack");
|
|
|
|
|
2013-02-01 16:08:06 +08:00
|
|
|
describe("Integration", function() {
|
2014-03-03 21:56:27 +08:00
|
|
|
this.timeout(5000);
|
2013-01-31 01:49:25 +08:00
|
|
|
it("should compile library1", function(done) {
|
|
|
|
webpack({
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}, function(err, stats) {
|
|
|
|
if(err) throw err;
|
2013-02-01 16:08:06 +08:00
|
|
|
stats.hasErrors().should.be.not.ok;
|
|
|
|
stats.hasWarnings().should.be.not.ok;
|
2013-01-31 01:49:25 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("should compile library2", function(done) {
|
|
|
|
webpack({
|
|
|
|
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: {
|
|
|
|
postLoaders: [
|
|
|
|
{
|
|
|
|
test: /extra2\.js/,
|
|
|
|
loader: "raw!extra!val?cacheable"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
amd: {
|
|
|
|
fromOptions: true
|
|
|
|
},
|
2013-10-16 05:59:02 +08:00
|
|
|
resolve: {
|
|
|
|
// cannot resolve should outside the outermost node_modules
|
|
|
|
// so it is injected here
|
|
|
|
alias: { should: require.resolve("should") }
|
|
|
|
},
|
2013-12-18 06:21:49 +08:00
|
|
|
plugins: [
|
2015-06-01 08:27:31 +08:00
|
|
|
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1}),
|
2013-12-18 06:21:49 +08:00
|
|
|
new webpack.DefinePlugin({
|
2014-05-27 18:42:41 +08:00
|
|
|
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
|
2013-12-18 06:21:49 +08:00
|
|
|
CONST_TRUE: true,
|
|
|
|
CONST_FALSE: false,
|
|
|
|
CONST_FUNCTION: function() { return "ok"; },
|
|
|
|
CONST_NUMBER: 123,
|
|
|
|
CONST_NUMBER_EXPR: "1*100+23",
|
|
|
|
CONST_OBJECT: {
|
|
|
|
A: 1,
|
|
|
|
B: JSON.stringify("B"),
|
|
|
|
C: function() { return "C"; }
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
function() {
|
2014-10-09 14:53:00 +08:00
|
|
|
this.plugin("normal-module-factory", function(nmf) {
|
|
|
|
nmf.plugin("after-resolve", function(data, callback) {
|
|
|
|
data.resource = data.resource.replace(/extra\.js/, "extra2.js");
|
2015-01-27 12:08:27 +08:00
|
|
|
setTimeout(function() {
|
|
|
|
callback(null, data);
|
|
|
|
}, 50);
|
2013-12-18 06:21:49 +08:00
|
|
|
});
|
2013-01-31 01:49:25 +08:00
|
|
|
});
|
|
|
|
}
|
2013-12-18 06:21:49 +08:00
|
|
|
]
|
2013-01-31 01:49:25 +08:00
|
|
|
}, function(err, stats) {
|
|
|
|
if(err) throw err;
|
2013-02-01 16:08:06 +08:00
|
|
|
stats.hasErrors().should.be.not.ok;
|
|
|
|
stats.hasWarnings().should.be.not.ok;
|
2013-01-31 01:49:25 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|