|
| 1 | +/* eslint-env browser */ |
| 2 | +import path from "path"; |
| 3 | + |
| 4 | +import MiniCssExtractPlugin from "../src"; |
| 5 | + |
| 6 | +import { |
| 7 | + compile, |
| 8 | + getCompiler, |
| 9 | + getErrors, |
| 10 | + getWarnings, |
| 11 | + runInJsDom, |
| 12 | +} from "./helpers/index"; |
| 13 | + |
| 14 | +describe("nonce", () => { |
| 15 | + it(`should work when __webpack_nonce__ is not defined`, async () => { |
| 16 | + const compiler = getCompiler( |
| 17 | + "no-nonce.js", |
| 18 | + {}, |
| 19 | + { |
| 20 | + mode: "none", |
| 21 | + output: { |
| 22 | + publicPath: "", |
| 23 | + path: path.resolve(__dirname, "../outputs"), |
| 24 | + filename: "[name].bundle.js", |
| 25 | + }, |
| 26 | + plugins: [ |
| 27 | + new MiniCssExtractPlugin({ |
| 28 | + filename: "[name].css", |
| 29 | + }), |
| 30 | + ], |
| 31 | + } |
| 32 | + ); |
| 33 | + const stats = await compile(compiler); |
| 34 | + |
| 35 | + runInJsDom("main.bundle.js", compiler, stats, (dom) => { |
| 36 | + expect(dom.serialize()).toMatchSnapshot("DOM"); |
| 37 | + }); |
| 38 | + |
| 39 | + expect(getWarnings(stats)).toMatchSnapshot("warnings"); |
| 40 | + expect(getErrors(stats)).toMatchSnapshot("errors"); |
| 41 | + }); |
| 42 | + |
| 43 | + it(`should work when __webpack_nonce__ is defined`, async () => { |
| 44 | + const compiler = getCompiler( |
| 45 | + "nonce.js", |
| 46 | + {}, |
| 47 | + { |
| 48 | + mode: "none", |
| 49 | + output: { |
| 50 | + publicPath: "", |
| 51 | + path: path.resolve(__dirname, "../outputs"), |
| 52 | + filename: "[name].bundle.js", |
| 53 | + }, |
| 54 | + plugins: [ |
| 55 | + new MiniCssExtractPlugin({ |
| 56 | + filename: "[name].css", |
| 57 | + }), |
| 58 | + ], |
| 59 | + } |
| 60 | + ); |
| 61 | + const stats = await compile(compiler); |
| 62 | + |
| 63 | + runInJsDom("main.bundle.js", compiler, stats, (dom) => { |
| 64 | + expect(dom.serialize()).toMatchSnapshot("DOM"); |
| 65 | + }); |
| 66 | + |
| 67 | + expect(getWarnings(stats)).toMatchSnapshot("warnings"); |
| 68 | + expect(getErrors(stats)).toMatchSnapshot("errors"); |
| 69 | + }); |
| 70 | +}); |
0 commit comments