GeezerVison is showing github.com — fix bug without async chunks, add more tests · webpack/webpack@d7a0fc3
File treeExpand file treeCollapse file tree Open diff view settings test/configCases/hash-length/output-filename
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/TemplatedPathPlugin.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -156,7 +156,9 @@ class TemplatedPathPlugin { | 156 | 156 | hash.update(JSON.stringify(chunk.getChunkMaps(true).hash)); | 157 | 157 | if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) { | 158 | 158 | hash.update( | 159 | | - JSON.stringify(chunk.getChunkMaps(true).contentHash.javascript) | | 159 | + JSON.stringify( | | 160 | + chunk.getChunkMaps(true).contentHash.javascript || {} | | 161 | + ) | 160 | 162 | ); | 161 | 163 | } | 162 | 164 | if (REGEXP_NAME_FOR_TEST.test(chunkFilename)) | |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +it("should compile and run the test " + NAME, function() {}); | | 2 | + | | 3 | +if (Math.random() < -1) { | | 4 | + require(["./chunk"], function() {}); | | 5 | +} |
Collapse file Copy file name to clipboardExpand all lines: test/configCases/hash-length/output-filename/test.config.js +20-13Lines changed: 20 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ require("should"); | 3 | 3 |
| 4 | 4 | var findFile = function(files, regex) { | 5 | 5 | return files.find(function(file) { | 6 | | - if(regex.test(file)) { | | 6 | + if (regex.test(file)) { | 7 | 7 | return true; | 8 | 8 | } | 9 | 9 | }); | @@ -17,23 +17,30 @@ module.exports = { | 17 | 17 | findBundle: function(i, options) { | 18 | 18 | var files = fs.readdirSync(options.output.path); | 19 | 19 |
| 20 | | - var bundleDetects = [{ | 21 | | - regex: new RegExp("^0.bundle" + i, "i"), | 22 | | - expectedNameLength: options.amd.expectedChunkFilenameLength | 23 | | - }, { | 24 | | - regex: new RegExp("^bundle" + i, "i"), | 25 | | - expectedNameLength: options.amd.expectedFilenameLength | 26 | | - }]; | | 20 | + var bundleDetects = [ | | 21 | + options.amd.expectedChunkFilenameLength && { | | 22 | + regex: new RegExp("^0.bundle" + i, "i"), | | 23 | + expectedNameLength: options.amd.expectedChunkFilenameLength | | 24 | + }, | | 25 | + { | | 26 | + regex: new RegExp("^bundle" + i, "i"), | | 27 | + expectedNameLength: options.amd.expectedFilenameLength | | 28 | + } | | 29 | + ].filter(Boolean); | 27 | 30 |
| 28 | 31 | var bundleDetect; | 29 | 32 | var filename; | 30 | 33 |
| 31 | | - for(bundleDetect of bundleDetects) { | | 34 | + for (bundleDetect of bundleDetects) { | 32 | 35 | filename = findFile(files, bundleDetect.regex); | 33 | | - verifyFilenameLength( | 34 | | - filename, | 35 | | - bundleDetect.expectedNameLength | 36 | | - ); | | 36 | + if (!filename) { | | 37 | + throw new Error( | | 38 | + `No file found with correct name (regex: ${ | | 39 | + bundleDetect.regex.source | | 40 | + }, files: ${files.join(", ")})` | | 41 | + ); | | 42 | + } | | 43 | + verifyFilenameLength(filename, bundleDetect.expectedNameLength); | 37 | 44 | } | 38 | 45 |
| 39 | 46 | return "./" + filename; | |
Collapse file Copy file name to clipboardExpand all lines: test/configCases/hash-length/output-filename/webpack.config.js +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -139,6 +139,58 @@ module.exports = [ | 139 | 139 | expectedFilenameLength: 9 + 7 + 3, | 140 | 140 | expectedChunkFilenameLength: 2 + 9 + 7 + 3 | 141 | 141 | } | | 142 | + }, | | 143 | + { | | 144 | + name: "contenthash in async-node", | | 145 | + output: { | | 146 | + filename: "bundle12.[contenthash].js", | | 147 | + chunkFilename: "[id].bundle12.[contenthash].js" | | 148 | + }, | | 149 | + target: "async-node", | | 150 | + amd: { | | 151 | + expectedFilenameLength: 32, | | 152 | + expectedChunkFilenameLength: 34 | | 153 | + } | | 154 | + }, | | 155 | + { | | 156 | + name: "contenthash in async-node with length", | | 157 | + output: { | | 158 | + filename: "bundle13.[contenthash:7].js", | | 159 | + chunkFilename: "[id].bundle13.[contenthash:7].js" | | 160 | + }, | | 161 | + target: "async-node", | | 162 | + amd: { | | 163 | + expectedFilenameLength: 9 + 7 + 3, | | 164 | + expectedChunkFilenameLength: 2 + 9 + 7 + 3 | | 165 | + } | | 166 | + }, | | 167 | + { | | 168 | + name: "contenthash in webpack", | | 169 | + entry: "./no-async", | | 170 | + output: { | | 171 | + filename: "bundle14.[contenthash].js", | | 172 | + chunkFilename: "[id].bundle14.[contenthash].js", | | 173 | + globalObject: "this" | | 174 | + }, | | 175 | + target: "web", | | 176 | + amd: { | | 177 | + expectedFilenameLength: 32, | | 178 | + expectedChunkFilenameLength: 34 | | 179 | + } | | 180 | + }, | | 181 | + { | | 182 | + name: "contenthash in async-node with length", | | 183 | + entry: "./no-async", | | 184 | + output: { | | 185 | + filename: "bundle15.[contenthash:7].js", | | 186 | + chunkFilename: "[id].bundle15.[contenthash:7].js", | | 187 | + globalObject: "this" | | 188 | + }, | | 189 | + target: "web", | | 190 | + amd: { | | 191 | + expectedFilenameLength: 9 + 7 + 3, | | 192 | + expectedChunkFilenameLength: 2 + 9 + 7 + 3 | | 193 | + } | 142 | 194 | } | 143 | 195 | ]; | 144 | 196 |
| |
|