-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
nonce
if __webpack_nonce__
has been defined
- Loading branch information
1 parent
878822b
commit c7f0aee
Showing
5 changed files
with
118 additions
and
0 deletions.
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
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,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`nonce should work when __webpack_nonce__ is defined: DOM 1`] = ` | ||
"<!DOCTYPE html><html><head> | ||
<title>style-loader test</title> | ||
<style id=\\"existing-style\\">.existing { color: yellow }</style> | ||
<link rel=\\"stylesheet\\" type=\\"text/css\\" nonce=\\"THE_NONCE\\" href=\\"simple.css\\"><script charset=\\"utf-8\\" nonce=\\"THE_NONCE\\" src=\\"simple.bundle.js\\"></script></head> | ||
<body> | ||
<h1>Body</h1> | ||
<div class=\\"target\\"></div> | ||
<iframe class=\\"iframeTarget\\"></iframe> | ||
</body></html>" | ||
`; | ||
exports[`nonce should work when __webpack_nonce__ is defined: errors 1`] = `Array []`; | ||
exports[`nonce should work when __webpack_nonce__ is defined: warnings 1`] = `Array []`; | ||
exports[`nonce should work when __webpack_nonce__ is not defined: DOM 1`] = ` | ||
"<!DOCTYPE html><html><head> | ||
<title>style-loader test</title> | ||
<style id=\\"existing-style\\">.existing { color: yellow }</style> | ||
<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"simple.css\\"><script charset=\\"utf-8\\" src=\\"simple.bundle.js\\"></script></head> | ||
<body> | ||
<h1>Body</h1> | ||
<div class=\\"target\\"></div> | ||
<iframe class=\\"iframeTarget\\"></iframe> | ||
</body></html>" | ||
`; | ||
exports[`nonce should work when __webpack_nonce__ is not defined: errors 1`] = `Array []`; | ||
exports[`nonce should work when __webpack_nonce__ is not defined: warnings 1`] = `Array []`; |
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,2 @@ | ||
/* eslint-disable-next-line no-unused-expressions */ | ||
import(/* webpackChunkName: "simple" */ './simple.css'); |
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 @@ | ||
__webpack_nonce__ = 'THE_NONCE'; | ||
|
||
/* eslint-disable-next-line no-unused-expressions */ | ||
import(/* webpackChunkName: "simple" */ './simple.css'); |
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,70 @@ | ||
/* eslint-env browser */ | ||
import path from "path"; | ||
|
||
import MiniCssExtractPlugin from "../src"; | ||
|
||
import { | ||
compile, | ||
getCompiler, | ||
getErrors, | ||
getWarnings, | ||
runInJsDom, | ||
} from "./helpers/index"; | ||
|
||
describe("nonce", () => { | ||
it(`should work when __webpack_nonce__ is not defined`, async () => { | ||
const compiler = getCompiler( | ||
"no-nonce.js", | ||
{}, | ||
{ | ||
mode: "none", | ||
output: { | ||
publicPath: "", | ||
path: path.resolve(__dirname, "../outputs"), | ||
filename: "[name].bundle.js", | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it(`should work when __webpack_nonce__ is defined`, async () => { | ||
const compiler = getCompiler( | ||
"nonce.js", | ||
{}, | ||
{ | ||
mode: "none", | ||
output: { | ||
publicPath: "", | ||
path: path.resolve(__dirname, "../outputs"), | ||
filename: "[name].bundle.js", | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
}); |