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));
|
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
|
||||||
if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
|
if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
|
||||||
hash.update(
|
hash.update(
|
||||||
JSON.stringify(chunk.getChunkMaps(true).contentHash.javascript)
|
JSON.stringify(
|
||||||
|
chunk.getChunkMaps(true).contentHash.javascript || {}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (REGEXP_NAME_FOR_TEST.test(chunkFilename))
|
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) {
|
var findFile = function(files, regex) {
|
||||||
return files.find(function(file) {
|
return files.find(function(file) {
|
||||||
if(regex.test(file)) {
|
if (regex.test(file)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -17,23 +17,30 @@ module.exports = {
|
||||||
findBundle: function(i, options) {
|
findBundle: function(i, options) {
|
||||||
var files = fs.readdirSync(options.output.path);
|
var files = fs.readdirSync(options.output.path);
|
||||||
|
|
||||||
var bundleDetects = [{
|
var bundleDetects = [
|
||||||
regex: new RegExp("^0.bundle" + i, "i"),
|
options.amd.expectedChunkFilenameLength && {
|
||||||
expectedNameLength: options.amd.expectedChunkFilenameLength
|
regex: new RegExp("^0.bundle" + i, "i"),
|
||||||
}, {
|
expectedNameLength: options.amd.expectedChunkFilenameLength
|
||||||
regex: new RegExp("^bundle" + i, "i"),
|
},
|
||||||
expectedNameLength: options.amd.expectedFilenameLength
|
{
|
||||||
}];
|
regex: new RegExp("^bundle" + i, "i"),
|
||||||
|
expectedNameLength: options.amd.expectedFilenameLength
|
||||||
|
}
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
var bundleDetect;
|
var bundleDetect;
|
||||||
var filename;
|
var filename;
|
||||||
|
|
||||||
for(bundleDetect of bundleDetects) {
|
for (bundleDetect of bundleDetects) {
|
||||||
filename = findFile(files, bundleDetect.regex);
|
filename = findFile(files, bundleDetect.regex);
|
||||||
verifyFilenameLength(
|
if (!filename) {
|
||||||
filename,
|
throw new Error(
|
||||||
bundleDetect.expectedNameLength
|
`No file found with correct name (regex: ${
|
||||||
);
|
bundleDetect.regex.source
|
||||||
|
}, files: ${files.join(", ")})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
verifyFilenameLength(filename, bundleDetect.expectedNameLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "./" + filename;
|
return "./" + filename;
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,58 @@ module.exports = [
|
||||||
expectedFilenameLength: 9 + 7 + 3,
|
expectedFilenameLength: 9 + 7 + 3,
|
||||||
expectedChunkFilenameLength: 2 + 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