-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add end-to-end tests for lazy hashes * Validate hashLoading option values Ref #171
- Loading branch information
Showing
14 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import("./nested1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import("./nested2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("ok"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "lazy-e2e", | ||
"description": "Basic end-to-end test with lazy-loaded hashes", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"private": true, | ||
"devDependencies": { | ||
"html-webpack-plugin": ">= 5.0.0-beta.1", | ||
"nyc": "*", | ||
"webpack": "^5.44.0", | ||
"webpack-cli": "4", | ||
"webpack-subresource-integrity": "*", | ||
"wsi-test-helper": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
const { RunInPuppeteerPlugin } = require("wsi-test-helper"); | ||
|
||
module.exports = { | ||
entry: { | ||
index: "./index.js", | ||
}, | ||
output: { | ||
crossOriginLoading: "anonymous", | ||
}, | ||
plugins: [ | ||
new SubresourceIntegrityPlugin({ | ||
hashFuncNames: ["sha256"], | ||
enabled: true, | ||
lazyHashes: true, | ||
}), | ||
new HtmlWebpackPlugin(), | ||
new RunInPuppeteerPlugin(), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# With lazy hashes and a modified dynamically loaded chunk #hwp | ||
|
||
Ensure that when a chunk is modified, it fails to load when hashes are | ||
lazy-loaded. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("this should never load"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import("./nested"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import(/* webpackChunkName: "corrupt" */ "./corrupt") | ||
.then(function error() { | ||
console.log("error"); | ||
}) | ||
.catch(function ok() { | ||
console.log("ok"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "lazy-modified", | ||
"description": "Ensure that when a chunk is modified, it fails to load when hashes are lazy-loaded.", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"private": true, | ||
"devDependencies": { | ||
"html-webpack-plugin": ">= 5.0.0-beta.1", | ||
"nyc": "*", | ||
"webpack": "^5.44.0", | ||
"webpack-cli": "4", | ||
"webpack-subresource-integrity": "*", | ||
"wsi-test-helper": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
const { RunInPuppeteerPlugin } = require("wsi-test-helper"); | ||
const { writeFileSync } = require("fs"); | ||
|
||
let gotError = false; | ||
|
||
module.exports = { | ||
entry: { | ||
index: "./index.js", | ||
}, | ||
output: { | ||
crossOriginLoading: "anonymous", | ||
}, | ||
plugins: [ | ||
new SubresourceIntegrityPlugin({ | ||
hashFuncNames: ["sha256", "sha384"], | ||
lazyHashes: true, | ||
}), | ||
new HtmlWebpackPlugin(), | ||
new RunInPuppeteerPlugin({ | ||
onStart: (stats) => { | ||
console.log(stats.compilation.assets); | ||
writeFileSync("dist/corrupt.js", 'console.log("corrupted");'); | ||
}, | ||
onConsoleError: (msg) => { | ||
console.log(msg); | ||
if ( | ||
msg.match( | ||
/Failed to find a valid digest in the 'integrity' attribute for resource/ | ||
) | ||
) { | ||
gotError = true; | ||
} | ||
}, | ||
onDone: () => { | ||
if (!gotError) { | ||
throw new Error("No error was raised"); | ||
} | ||
}, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters