|
| 1 | +/* eslint-env browser */ |
| 2 | +import path from 'path'; |
| 3 | + |
| 4 | +import MiniCssExtractPlugin from '../src/cjs'; |
| 5 | + |
| 6 | +import { |
| 7 | + compile, |
| 8 | + getCompiler, |
| 9 | + getErrors, |
| 10 | + getWarnings, |
| 11 | + runInJsDom, |
| 12 | +} from './helpers/index'; |
| 13 | + |
| 14 | +describe('linkType option', () => { |
| 15 | + it(`should work without linkType option`, async () => { |
| 16 | + const compiler = getCompiler( |
| 17 | + 'attributes.js', |
| 18 | + {}, |
| 19 | + { |
| 20 | + output: { |
| 21 | + publicPath: '', |
| 22 | + path: path.resolve(__dirname, '../outputs'), |
| 23 | + filename: '[name].bundle.js', |
| 24 | + }, |
| 25 | + plugins: [ |
| 26 | + new MiniCssExtractPlugin({ |
| 27 | + filename: '[name].css', |
| 28 | + }), |
| 29 | + ], |
| 30 | + } |
| 31 | + ); |
| 32 | + const stats = await compile(compiler); |
| 33 | + |
| 34 | + runInJsDom('main.bundle.js', compiler, stats, (dom) => { |
| 35 | + expect(dom.serialize()).toMatchSnapshot('DOM'); |
| 36 | + }); |
| 37 | + |
| 38 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); |
| 39 | + expect(getErrors(stats)).toMatchSnapshot('errors'); |
| 40 | + }); |
| 41 | + |
| 42 | + it(`should work when linkType option is "false"`, async () => { |
| 43 | + const compiler = getCompiler( |
| 44 | + 'attributes.js', |
| 45 | + {}, |
| 46 | + { |
| 47 | + output: { |
| 48 | + publicPath: '', |
| 49 | + path: path.resolve(__dirname, '../outputs'), |
| 50 | + filename: '[name].bundle.js', |
| 51 | + }, |
| 52 | + plugins: [ |
| 53 | + new MiniCssExtractPlugin({ |
| 54 | + linkType: false, |
| 55 | + filename: '[name].css', |
| 56 | + }), |
| 57 | + ], |
| 58 | + } |
| 59 | + ); |
| 60 | + const stats = await compile(compiler); |
| 61 | + |
| 62 | + runInJsDom('main.bundle.js', compiler, stats, (dom) => { |
| 63 | + expect(dom.serialize()).toMatchSnapshot('DOM'); |
| 64 | + }); |
| 65 | + |
| 66 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); |
| 67 | + expect(getErrors(stats)).toMatchSnapshot('errors'); |
| 68 | + }); |
| 69 | + |
| 70 | + it(`should work when linkType option is "text/css"`, async () => { |
| 71 | + const compiler = getCompiler( |
| 72 | + 'attributes.js', |
| 73 | + {}, |
| 74 | + { |
| 75 | + output: { |
| 76 | + publicPath: '', |
| 77 | + path: path.resolve(__dirname, '../outputs'), |
| 78 | + filename: '[name].bundle.js', |
| 79 | + }, |
| 80 | + plugins: [ |
| 81 | + new MiniCssExtractPlugin({ |
| 82 | + linkType: 'text/css', |
| 83 | + filename: '[name].css', |
| 84 | + }), |
| 85 | + ], |
| 86 | + } |
| 87 | + ); |
| 88 | + const stats = await compile(compiler); |
| 89 | + |
| 90 | + runInJsDom('main.bundle.js', compiler, stats, (dom) => { |
| 91 | + expect(dom.serialize()).toMatchSnapshot('DOM'); |
| 92 | + }); |
| 93 | + |
| 94 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); |
| 95 | + expect(getErrors(stats)).toMatchSnapshot('errors'); |
| 96 | + }); |
| 97 | +}); |
0 commit comments