Skip to content

Commit d049da4

Browse files
authored
Lazy hashes follow-up
* Add end-to-end tests for lazy hashes * Validate hashLoading option values Ref #171
1 parent fc7cf19 commit d049da4

File tree

14 files changed

+179
-1
lines changed

14 files changed

+179
-1
lines changed

examples/lazy-e2e/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./nested1");

examples/lazy-e2e/nested1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./nested2");

examples/lazy-e2e/nested2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("ok");

examples/lazy-e2e/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "lazy-e2e",
3+
"description": "Basic end-to-end test with lazy-loaded hashes",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"private": true,
7+
"devDependencies": {
8+
"html-webpack-plugin": ">= 5.0.0-beta.1",
9+
"nyc": "*",
10+
"webpack": "^5.44.0",
11+
"webpack-cli": "4",
12+
"webpack-subresource-integrity": "*",
13+
"wsi-test-helper": "*"
14+
}
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity");
2+
const HtmlWebpackPlugin = require("html-webpack-plugin");
3+
const { RunInPuppeteerPlugin } = require("wsi-test-helper");
4+
5+
module.exports = {
6+
entry: {
7+
index: "./index.js",
8+
},
9+
output: {
10+
crossOriginLoading: "anonymous",
11+
},
12+
plugins: [
13+
new SubresourceIntegrityPlugin({
14+
hashFuncNames: ["sha256"],
15+
enabled: true,
16+
lazyHashes: true,
17+
}),
18+
new HtmlWebpackPlugin(),
19+
new RunInPuppeteerPlugin(),
20+
],
21+
};

examples/lazy-modified/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# With lazy hashes and a modified dynamically loaded chunk #hwp
2+
3+
Ensure that when a chunk is modified, it fails to load when hashes are
4+
lazy-loaded.

examples/lazy-modified/corrupt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("this should never load");

examples/lazy-modified/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./nested");

examples/lazy-modified/nested.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import(/* webpackChunkName: "corrupt" */ "./corrupt")
2+
.then(function error() {
3+
console.log("error");
4+
})
5+
.catch(function ok() {
6+
console.log("ok");
7+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "lazy-modified",
3+
"description": "Ensure that when a chunk is modified, it fails to load when hashes are lazy-loaded.",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"private": true,
7+
"devDependencies": {
8+
"html-webpack-plugin": ">= 5.0.0-beta.1",
9+
"nyc": "*",
10+
"webpack": "^5.44.0",
11+
"webpack-cli": "4",
12+
"webpack-subresource-integrity": "*",
13+
"wsi-test-helper": "*"
14+
}
15+
}

0 commit comments

Comments
 (0)