mirror of https://github.com/webpack/webpack.git
fix bug without async chunks, add more tests
This commit is contained in:
parent
c328c65371
commit
d7a0fc341b
|
|
@ -156,7 +156,9 @@ class TemplatedPathPlugin {
|
|||
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
|
||||
if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
|
||||
hash.update(
|
||||
JSON.stringify(chunk.getChunkMaps(true).contentHash.javascript)
|
||||
JSON.stringify(
|
||||
chunk.getChunkMaps(true).contentHash.javascript || {}
|
||||
)
|
||||
);
|
||||
}
|
||||
if (REGEXP_NAME_FOR_TEST.test(chunkFilename))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
it("should compile and run the test " + NAME, function() {});
|
||||
|
||||
if (Math.random() < -1) {
|
||||
require(["./chunk"], function() {});
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ require("should");
|
|||
|
||||
var findFile = function(files, regex) {
|
||||
return files.find(function(file) {
|
||||
if(regex.test(file)) {
|
||||
if (regex.test(file)) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
@ -17,23 +17,30 @@ module.exports = {
|
|||
findBundle: function(i, options) {
|
||||
var files = fs.readdirSync(options.output.path);
|
||||
|
||||
var bundleDetects = [{
|
||||
regex: new RegExp("^0.bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedChunkFilenameLength
|
||||
}, {
|
||||
regex: new RegExp("^bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedFilenameLength
|
||||
}];
|
||||
var bundleDetects = [
|
||||
options.amd.expectedChunkFilenameLength && {
|
||||
regex: new RegExp("^0.bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedChunkFilenameLength
|
||||
},
|
||||
{
|
||||
regex: new RegExp("^bundle" + i, "i"),
|
||||
expectedNameLength: options.amd.expectedFilenameLength
|
||||
}
|
||||
].filter(Boolean);
|
||||
|
||||
var bundleDetect;
|
||||
var filename;
|
||||
|
||||
for(bundleDetect of bundleDetects) {
|
||||
for (bundleDetect of bundleDetects) {
|
||||
filename = findFile(files, bundleDetect.regex);
|
||||
verifyFilenameLength(
|
||||
filename,
|
||||
bundleDetect.expectedNameLength
|
||||
);
|
||||
if (!filename) {
|
||||
throw new Error(
|
||||
`No file found with correct name (regex: ${
|
||||
bundleDetect.regex.source
|
||||
}, files: ${files.join(", ")})`
|
||||
);
|
||||
}
|
||||
verifyFilenameLength(filename, bundleDetect.expectedNameLength);
|
||||
}
|
||||
|
||||
return "./" + filename;
|
||||
|
|
|
|||
|
|
@ -139,6 +139,58 @@ module.exports = [
|
|||
expectedFilenameLength: 9 + 7 + 3,
|
||||
expectedChunkFilenameLength: 2 + 9 + 7 + 3
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "contenthash in async-node",
|
||||
output: {
|
||||
filename: "bundle12.[contenthash].js",
|
||||
chunkFilename: "[id].bundle12.[contenthash].js"
|
||||
},
|
||||
target: "async-node",
|
||||
amd: {
|
||||
expectedFilenameLength: 32,
|
||||
expectedChunkFilenameLength: 34
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "contenthash in async-node with length",
|
||||
output: {
|
||||
filename: "bundle13.[contenthash:7].js",
|
||||
chunkFilename: "[id].bundle13.[contenthash:7].js"
|
||||
},
|
||||
target: "async-node",
|
||||
amd: {
|
||||
expectedFilenameLength: 9 + 7 + 3,
|
||||
expectedChunkFilenameLength: 2 + 9 + 7 + 3
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "contenthash in webpack",
|
||||
entry: "./no-async",
|
||||
output: {
|
||||
filename: "bundle14.[contenthash].js",
|
||||
chunkFilename: "[id].bundle14.[contenthash].js",
|
||||
globalObject: "this"
|
||||
},
|
||||
target: "web",
|
||||
amd: {
|
||||
expectedFilenameLength: 32,
|
||||
expectedChunkFilenameLength: 34
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "contenthash in async-node with length",
|
||||
entry: "./no-async",
|
||||
output: {
|
||||
filename: "bundle15.[contenthash:7].js",
|
||||
chunkFilename: "[id].bundle15.[contenthash:7].js",
|
||||
globalObject: "this"
|
||||
},
|
||||
target: "web",
|
||||
amd: {
|
||||
expectedFilenameLength: 9 + 7 + 3,
|
||||
expectedChunkFilenameLength: 2 + 9 + 7 + 3
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue