Skip to content

Commit

Permalink
test: add munual cases for crossOriginLoading option
Browse files Browse the repository at this point in the history
  • Loading branch information
chikara-chan committed Nov 25, 2018
1 parent 3df36ff commit 1e33e23
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/manual/index.html
Expand Up @@ -47,6 +47,10 @@
<p>Preloaded inlined CSS: Must be green.</p>
<p><button class="preloaded-button2">Pressing this button</button> displays an alert and should turn red.</p>
</div>
<div class="test crossorigin">
<p>CrossOriginLoading Option: Must be red.</p>
<p><button>Pressing this button</button> loads chunks with crossorigin attribute and should turn green.</p>
</div>
<div class="errors"></div>
<script async defer src="/dist/main.js"></script>
</body>
Expand Down
3 changes: 3 additions & 0 deletions test/manual/src/crossorigin.css
@@ -0,0 +1,3 @@
.crossorigin {
background: lightgreen;
}
1 change: 1 addition & 0 deletions test/manual/src/crossorigin.js
@@ -0,0 +1 @@
import './crossorigin.css';
14 changes: 14 additions & 0 deletions test/manual/src/index.js
Expand Up @@ -24,3 +24,17 @@ makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1"
makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2'));

makeButton(".lazy-failure-button", () => import('./lazy-failure.js'), false);

makeButton(".crossorigin", () => {
const originalPublicPath = __webpack_public_path__;
__webpack_public_path__ = "http://0.0.0.0:8080/dist/";
const promise = import("./crossorigin").then(() => {
const lastTwoElements = Array.from(document.head.children).slice(-2);
const hasCrossorigin = lastTwoElements.every(element => element.crossOrigin === "anonymous");
if (!hasCrossorigin) {
throw new Error('Chunks miss crossorigin="anonymous" attribute.')
}
});
__webpack_public_path__ = originalPublicPath;
return promise;
});
4 changes: 4 additions & 0 deletions test/manual/webpack.config.js
Expand Up @@ -5,6 +5,7 @@ module.exports = {
output: {
chunkFilename: "[contenthash].js",
publicPath: '/dist/',
crossOriginLoading: 'anonymous',
},
module: {
rules: [
Expand All @@ -25,5 +26,8 @@ module.exports = {
],
devServer: {
contentBase: __dirname,
headers: {
"Access-Control-Allow-Origin": "*",
}
},
};

0 comments on commit 1e33e23

Please sign in to comment.