Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42fd988

Browse files
committedNov 25, 2018
test: add munual cases for crossOriginLoading option
1 parent baefbb9 commit 42fd988

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed
 

Diff for: ‎test/manual/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<p>Preloaded inlined CSS: Must be green.</p>
4343
<p><button class="preloaded-button2">Pressing this button</button> displays an alert and should turn red.</p>
4444
</div>
45+
<div class="test crossorigin">
46+
<p>CrossOriginLoading Option: Must be red.</p>
47+
<p><button>Pressing this button</button> loads chunks with crossorigin attribute and should turn green.</p>
48+
</div>
4549
<div class="errors"></div>
4650
<script async defer src="/dist/main.js"></script>
4751
</body>

Diff for: ‎test/manual/src/crossorigin.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.crossorigin {
2+
background: lightgreen;
3+
}

Diff for: ‎test/manual/src/crossorigin.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './crossorigin.css';

Diff for: ‎test/manual/src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,17 @@ makeButton(".lazy-button2", () => import('./lazy2.css'));
2020

2121
makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1" */ './preloaded1'));
2222
makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2'));
23+
24+
makeButton(".crossorigin", () => {
25+
const originalPublicPath = __webpack_public_path__;
26+
__webpack_public_path__ = "http://0.0.0.0:8080/dist/";
27+
const promise = import("./crossorigin").then(() => {
28+
const lastTwoElements = Array.from(document.head.children).slice(-2);
29+
const hasCrossorigin = lastTwoElements.every(element => element.crossOrigin === "anonymous");
30+
if (!hasCrossorigin) {
31+
throw new Error('Chunks lost crossorigin="anonymous" attribute.')
32+
}
33+
});
34+
__webpack_public_path__ = originalPublicPath;
35+
return promise;
36+
});

Diff for: ‎test/manual/webpack.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
output: {
66
chunkFilename: "[contenthash].js",
77
publicPath: '/dist/',
8+
crossOriginLoading: 'anonymous',
89
},
910
module: {
1011
rules: [
@@ -25,5 +26,8 @@ module.exports = {
2526
],
2627
devServer: {
2728
contentBase: __dirname,
29+
headers: {
30+
"Access-Control-Allow-Origin": "*",
31+
}
2832
},
2933
};

0 commit comments

Comments
 (0)
Please sign in to comment.