From b389b4f366e0c7421f2c15474f49619f9577b35d Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Sat, 22 Aug 2020 17:19:04 +0300 Subject: [PATCH] test: persistent cache (#25) --- test/CssMinimizerPlugin.test.js | 68 ++++++++++++++++++- .../CssMinimizerPlugin.test.js.snap.webpack4 | 22 ++++++ .../CssMinimizerPlugin.test.js.snap.webpack5 | 24 ++++++- .../sourceMap-option.test.js.snap.webpack4 | 14 ++-- .../sourceMap-option.test.js.snap.webpack5 | 14 ++-- test/fixtures/simple-async.js | 1 + test/fixtures/simple-emit-2.js | 1 + test/fixtures/simple-emit.js | 1 + test/fixtures/simple.js | 10 +++ ...s => emitAssetInChildCompilationLoader.js} | 0 test/helpers/emitAssetLoader.js | 7 ++ test/helpers/emitAssetLoader2.js | 7 ++ test/helpers/getCompiler.js | 23 ++++--- 13 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 test/fixtures/simple-async.js create mode 100644 test/fixtures/simple-emit-2.js create mode 100644 test/fixtures/simple-emit.js create mode 100644 test/fixtures/simple.js rename test/helpers/{preLoader.js => emitAssetInChildCompilationLoader.js} (100%) create mode 100644 test/helpers/emitAssetLoader.js create mode 100644 test/helpers/emitAssetLoader2.js diff --git a/test/CssMinimizerPlugin.test.js b/test/CssMinimizerPlugin.test.js index c0a18d5..e435d15 100644 --- a/test/CssMinimizerPlugin.test.js +++ b/test/CssMinimizerPlugin.test.js @@ -353,7 +353,10 @@ describe('CssMinimizerPlugin', () => { test: /entry.js$/i, use: [ { - loader: path.resolve(__dirname, './helpers/preLoader'), + loader: path.resolve( + __dirname, + './helpers/emitAssetInChildCompilationLoader' + ), }, ], }, @@ -445,4 +448,67 @@ describe('CssMinimizerPlugin', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); } }); + + it('should work in watch mode', async () => { + const compiler = getCompiler({ + entry: { + foo: `${__dirname}/fixtures/simple.js`, + }, + plugins: [], + module: { + rules: [ + { + test: /.s?css$/i, + use: ['css-loader'], + }, + { + test: /simple-emit.js$/i, + loader: require.resolve('./helpers/emitAssetLoader.js'), + }, + { + test: /simple-emit-2.js$/i, + loader: require.resolve('./helpers/emitAssetLoader2.js'), + }, + ], + }, + }); + + new CssMinimizerPlugin().apply(compiler); + + const stats = await compile(compiler); + + if (getCompiler.isWebpack4()) { + expect( + Object.keys(stats.compilation.assets).filter( + (assetName) => stats.compilation.assets[assetName].emitted + ).length + ).toBe(4); + } else { + expect(stats.compilation.emittedAssets.size).toBe(4); + } + + expect(readAssets(compiler, stats, '.css')).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('errors'); + expect(getErrors(stats)).toMatchSnapshot('warnings'); + + await new Promise(async (resolve) => { + const newStats = await compile(compiler); + + if (getCompiler.isWebpack4()) { + expect( + Object.keys(newStats.compilation.assets).filter( + (assetName) => newStats.compilation.assets[assetName].emitted + ).length + ).toBe(0); + } else { + expect(newStats.compilation.emittedAssets.size).toBe(0); + } + + expect(readAssets(compiler, newStats, '.css')).toMatchSnapshot('assets'); + expect(getWarnings(newStats)).toMatchSnapshot('errors'); + expect(getErrors(newStats)).toMatchSnapshot('warnings'); + + resolve(); + }); + }); }); diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 index b782d2c..5e736bd 100644 --- a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4 @@ -69,6 +69,28 @@ exports[`CssMinimizerPlugin should work and show minimized assets in stats: erro exports[`CssMinimizerPlugin should work and show minimized assets in stats: warnings 1`] = `Array []`; +exports[`CssMinimizerPlugin should work in watch mode: assets 1`] = ` +Object { + "style-2.css": "a{color:coral}", + "style.css": "a{color:red}", +} +`; + +exports[`CssMinimizerPlugin should work in watch mode: assets 2`] = ` +Object { + "style-2.css": "a{color:coral}", + "style.css": "a{color:red}", +} +`; + +exports[`CssMinimizerPlugin should work in watch mode: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: errors 2`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: warnings 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: warnings 2`] = `Array []`; + exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` diff --git a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 index 22af5d0..3a66ae0 100644 --- a/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 +++ b/test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5 @@ -61,7 +61,7 @@ exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = ` exports[`CssMinimizerPlugin should work and generate real content hash: assets 1`] = ` Object { - "entry.19e4764f9c1d9fe130e2.655a1d8e7614dda9272e.1afdccbeaec4b0402d74.css": "body{color:red}a{color:#00f}", + "entry.19e4764f9c1d9fe130e2.2d6ce991710d63180e35.87eaf84ce322e15b3c17.css": "body{color:red}a{color:#00f}", } `; @@ -79,6 +79,28 @@ exports[`CssMinimizerPlugin should work and show minimized assets in stats: erro exports[`CssMinimizerPlugin should work and show minimized assets in stats: warnings 1`] = `Array []`; +exports[`CssMinimizerPlugin should work in watch mode: assets 1`] = ` +Object { + "style-2.css": "a{color:coral}", + "style.css": "a{color:red}", +} +`; + +exports[`CssMinimizerPlugin should work in watch mode: assets 2`] = ` +Object { + "style-2.css": "a{color:coral}", + "style.css": "a{color:red}", +} +`; + +exports[`CssMinimizerPlugin should work in watch mode: errors 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: errors 2`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: warnings 1`] = `Array []`; + +exports[`CssMinimizerPlugin should work in watch mode: warnings 2`] = `Array []`; + exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`CssMinimizerPlugin should work with assets using querystring: entry.css?v=test 1`] = ` diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 index 197ec7f..7a59b64 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack4 @@ -31,9 +31,9 @@ Object { } `; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: errors 1`] = `Array []`; @@ -48,9 +48,9 @@ Object { } `; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: errors 1`] = `Array []`; @@ -67,9 +67,9 @@ Object { exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): errors 1`] = `Array []`; -exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): warnings 1`] = `Array []`; @@ -77,7 +77,7 @@ exports[`when applied with "sourceMap" option should emit warning when broken so Array [ "Error: broken-source-map.css from Css Minimizer Error: \\"version\\" is a required argument.", - "ModuleBuildError: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): + "ModuleBuildError: Module build failed (from /node_modules/mini-css-extract-plugin/dist/loader.js): Error: broken-source-map.css from Css Minimizer", ] `; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 index 197ec7f..7f419dd 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 +++ b/test/__snapshots__/sourceMap-option.test.js.snap.webpack5 @@ -31,9 +31,9 @@ Object { } `; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: errors 1`] = `Array []`; @@ -48,9 +48,9 @@ Object { } `; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: errors 1`] = `Array []`; @@ -67,9 +67,9 @@ Object { exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): errors 1`] = `Array []`; -exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; -exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; +exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`; exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): warnings 1`] = `Array []`; @@ -77,7 +77,7 @@ exports[`when applied with "sourceMap" option should emit warning when broken so Array [ "Error: broken-source-map.css from Css Minimizer Error: \\"version\\" is a required argument.", - "ModuleBuildError: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): + "ModuleBuildError: Module build failed (from ../../node_modules/mini-css-extract-plugin/dist/loader.js): Error: broken-source-map.css from Css Minimizer", ] `; diff --git a/test/fixtures/simple-async.js b/test/fixtures/simple-async.js new file mode 100644 index 0000000..d9a5cff --- /dev/null +++ b/test/fixtures/simple-async.js @@ -0,0 +1 @@ +export default 'bar'; diff --git a/test/fixtures/simple-emit-2.js b/test/fixtures/simple-emit-2.js new file mode 100644 index 0000000..d9a5cff --- /dev/null +++ b/test/fixtures/simple-emit-2.js @@ -0,0 +1 @@ +export default 'bar'; diff --git a/test/fixtures/simple-emit.js b/test/fixtures/simple-emit.js new file mode 100644 index 0000000..d02ba54 --- /dev/null +++ b/test/fixtures/simple-emit.js @@ -0,0 +1 @@ +export default 'foo'; diff --git a/test/fixtures/simple.js b/test/fixtures/simple.js new file mode 100644 index 0000000..5b298a6 --- /dev/null +++ b/test/fixtures/simple.js @@ -0,0 +1,10 @@ +import foo from './simple-emit'; +import bar from './simple-emit-2'; + +async function load() { + return import('./simple-async'); +} + +load(); + +export default [foo, bar, css, otherCss]; diff --git a/test/helpers/preLoader.js b/test/helpers/emitAssetInChildCompilationLoader.js similarity index 100% rename from test/helpers/preLoader.js rename to test/helpers/emitAssetInChildCompilationLoader.js diff --git a/test/helpers/emitAssetLoader.js b/test/helpers/emitAssetLoader.js new file mode 100644 index 0000000..4ba8281 --- /dev/null +++ b/test/helpers/emitAssetLoader.js @@ -0,0 +1,7 @@ +export default function loader(content) { + this.emitFile('style.css', 'a { color: red; }'); + + const callback = this.async(); + + return callback(null, content); +} diff --git a/test/helpers/emitAssetLoader2.js b/test/helpers/emitAssetLoader2.js new file mode 100644 index 0000000..a99bb4b --- /dev/null +++ b/test/helpers/emitAssetLoader2.js @@ -0,0 +1,7 @@ +export default function loader(content) { + this.emitFile('style-2.css', 'a { color: coral; }'); + + const callback = this.async(); + + return callback(null, content); +} diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 3b439dd..681a7b9 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -4,17 +4,16 @@ import webpack from 'webpack'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import { createFsFromVolume, Volume } from 'memfs'; -export default function getCompiler(options) { +export default function getCompiler(config) { const compiler = webpack({ - mode: 'production', - bail: true, - cache: getCompiler.isWebpack4() ? false : { type: 'memory' }, + mode: 'development', + devtool: config.devtool || false, + context: path.resolve(__dirname, '../fixtures'), optimization: { minimize: false, }, output: { - pathinfo: false, - path: path.resolve(__dirname, 'dist'), + path: path.resolve(__dirname, '../outputs'), filename: '[name].js', chunkFilename: '[id].[name].js', }, @@ -32,14 +31,16 @@ export default function getCompiler(options) { }, ], }, - ...options, + ...config, }); - const outputFileSystem = createFsFromVolume(new Volume()); - // Todo remove when we drop webpack@4 support - outputFileSystem.join = path.join.bind(path); + if (!config.outputFileSystem) { + const outputFileSystem = createFsFromVolume(new Volume()); + // Todo remove when we drop webpack@4 support + outputFileSystem.join = path.join.bind(path); - compiler.outputFileSystem = outputFileSystem; + compiler.outputFileSystem = outputFileSystem; + } return compiler; }