|
| 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('attributes option', () => { |
| 15 | + it(`should work without attributes 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 | + // console.log(dom.serialize()) |
| 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 with attributes option`, async () => { |
| 44 | + const compiler = getCompiler( |
| 45 | + 'attributes.js', |
| 46 | + {}, |
| 47 | + { |
| 48 | + output: { |
| 49 | + publicPath: '', |
| 50 | + path: path.resolve(__dirname, '../outputs'), |
| 51 | + filename: '[name].bundle.js', |
| 52 | + }, |
| 53 | + plugins: [ |
| 54 | + new MiniCssExtractPlugin({ |
| 55 | + attributes: { |
| 56 | + id: 'target', |
| 57 | + 'data-target': 'example', |
| 58 | + }, |
| 59 | + filename: '[name].css', |
| 60 | + }), |
| 61 | + ], |
| 62 | + } |
| 63 | + ); |
| 64 | + const stats = await compile(compiler); |
| 65 | + |
| 66 | + runInJsDom('main.bundle.js', compiler, stats, (dom) => { |
| 67 | + // console.log(dom.serialize()) |
| 68 | + expect(dom.serialize()).toMatchSnapshot('DOM'); |
| 69 | + }); |
| 70 | + |
| 71 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); |
| 72 | + expect(getErrors(stats)).toMatchSnapshot('errors'); |
| 73 | + }); |
| 74 | +}); |
0 commit comments