diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 85f7e096d..f6df349a2 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -147,11 +147,11 @@ Array [ .class { color: red; - background: url(/webpack/public/path/de52feff0a80fb98abe3.png); + background: url(/webpack/public/path/img.png); } .class-duplicate-url { - background: url(/webpack/public/path/de52feff0a80fb98abe3.png); + background: url(/webpack/public/path/img.png); } :root { diff --git a/test/fixtures/source-map/basic.scss b/test/fixtures/source-map/basic.scss index e646594f8..90fc3589b 100644 --- a/test/fixtures/source-map/basic.scss +++ b/test/fixtures/source-map/basic.scss @@ -1,4 +1,4 @@ -@import "./nested/nested"; +@import "./nested/nested.scss"; $font-stack: Helvetica, sans-serif; $primary-color: #333; diff --git a/test/loader.test.js b/test/loader.test.js index adc6772f9..4d487cca7 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -52,38 +52,43 @@ describe('loader', () => { it('should work with "asset" module type', async () => { const isWebpack5 = version[0] === '5'; + const config = { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: path.resolve(__dirname, '../src'), + }, + ], + }, + isWebpack5 + ? { + test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i, + type: 'asset', + } + : { + test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i, + loader: 'file-loader', + options: { name: '[name].[ext]' }, + }, + ], + }, + }; - const compiler = getCompiler( - './basic.js', - {}, - { - module: { - rules: [ - { - test: /\.css$/i, - use: [ - { - loader: path.resolve(__dirname, '../src'), - }, - ], - }, - isWebpack5 - ? { - test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i, - type: 'asset', - } - : { - test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i, - loader: 'file-loader', - options: { name: '[hash].[ext]' }, - }, - ], - }, - experiments: { - asset: true, - }, - } - ); + if (isWebpack5) { + config.experiments = { asset: true }; + config.output = { + path: path.resolve(__dirname, 'outputs'), + filename: '[name].bundle.js', + chunkFilename: '[name].chunk.js', + publicPath: '/webpack/public/path/', + assetModuleFilename: '[name][ext]', + }; + } + + const compiler = getCompiler('./basic.js', {}, config); const stats = await compile(compiler); expect(getModuleSource('./basic.css', stats)).toMatchSnapshot('module');