Skip to content

Commit 7be1ff0

Browse files
test: contenthash
1 parent b95a779 commit 7be1ff0

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ exports[`loader should work with "asset" module type: warnings 1`] = `Array []`;
290290
291291
exports[`loader should work with "sass-loader": errors 1`] = `Array []`;
292292
293+
exports[`loader should work with "sass-loader": errors 2`] = `Array []`;
294+
293295
exports[`loader should work with "sass-loader": module 1`] = `
294296
"// Imports
295297
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../src/runtime/api.js\\");
@@ -301,6 +303,12 @@ module.exports = exports;
301303
"
302304
`;
303305
306+
exports[`loader should work with "sass-loader": module 2`] = `
307+
Array [
308+
"main.747d79248a0219823c67.bundle.js",
309+
]
310+
`;
311+
304312
exports[`loader should work with "sass-loader": result 1`] = `
305313
Array [
306314
Array [
@@ -316,6 +324,8 @@ Array [
316324
317325
exports[`loader should work with "sass-loader": warnings 1`] = `Array []`;
318326
327+
exports[`loader should work with "sass-loader": warnings 2`] = `Array []`;
328+
319329
exports[`loader should work with ModuleConcatenationPlugin (file-loader): errors 1`] = `Array []`;
320330
321331
exports[`loader should work with ModuleConcatenationPlugin (file-loader): warnings 1`] = `Array []`;

test/fixtures/contenthash/basic.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './basic.scss';
2+
3+
__export__ = css;
4+
5+
export default css;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a {
2+
color: rgb(0 0 100% / 90%);
3+
4+
&:hover {
5+
color: rebeccapurple;
6+
}
7+
}

test/loader.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,55 @@ describe('loader', () => {
308308
expect(getWarnings(stats)).toMatchSnapshot('warnings');
309309
expect(getErrors(stats)).toMatchSnapshot('errors');
310310
});
311+
312+
it('should work with "sass-loader"', async () => {
313+
const compiler = getCompiler(
314+
'./contenthash/basic.js',
315+
{},
316+
{
317+
output: {
318+
path: path.resolve(__dirname, '../outputs'),
319+
filename: '[name].[contenthash].bundle.js',
320+
chunkFilename: '[name].[contenthash].chunk.js',
321+
publicPath: '/webpack/public/path/',
322+
},
323+
module: {
324+
rules: [
325+
{
326+
test: /\.s[ca]ss$/i,
327+
rules: [
328+
{
329+
loader: path.resolve(__dirname, '../src'),
330+
options: {
331+
sourceMap: true,
332+
importLoaders: 1,
333+
},
334+
},
335+
{
336+
loader: 'postcss-loader',
337+
options: {
338+
plugins: () => [postcssPresetEnv({ stage: 0 })],
339+
sourceMap: true,
340+
},
341+
},
342+
{
343+
loader: 'sass-loader',
344+
options: {
345+
// eslint-disable-next-line global-require
346+
implementation: require('sass'),
347+
sourceMap: true,
348+
},
349+
},
350+
],
351+
},
352+
],
353+
},
354+
}
355+
);
356+
const stats = await compile(compiler);
357+
358+
expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('module');
359+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
360+
expect(getErrors(stats)).toMatchSnapshot('errors');
361+
});
311362
});

0 commit comments

Comments
 (0)