Skip to content

Commit 639ac56

Browse files
test: contenthash
1 parent b95a779 commit 639ac56

File tree

8 files changed

+193
-0
lines changed

8 files changed

+193
-0
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`loader should have same "contenthash" with "css-loader" and source maps: errors 1`] = `Array []`;
4+
5+
exports[`loader should have same "contenthash" with "css-loader" and source maps: module 1`] = `
6+
Array [
7+
"main.54b9712c1981e48c12c4.bundle.js",
8+
]
9+
`;
10+
11+
exports[`loader should have same "contenthash" with "css-loader" and source maps: warnings 1`] = `Array []`;
12+
13+
exports[`loader should have same "contenthash" with "postcss-loader" and source maps: errors 1`] = `Array []`;
14+
15+
exports[`loader should have same "contenthash" with "postcss-loader" and source maps: module 1`] = `
16+
Array [
17+
"main.d77dd6564bc6e6297cd4.bundle.js",
18+
]
19+
`;
20+
21+
exports[`loader should have same "contenthash" with "postcss-loader" and source maps: warnings 1`] = `Array []`;
22+
23+
exports[`loader should have same "contenthash" with "sass-loader" and source maps: errors 1`] = `Array []`;
24+
25+
exports[`loader should have same "contenthash" with "sass-loader" and source maps: module 1`] = `
26+
Array [
27+
"main.151589c7e12ebfd445e7.bundle.js",
28+
]
29+
`;
30+
31+
exports[`loader should have same "contenthash" with "sass-loader" and source maps: warnings 1`] = `Array []`;
32+
333
exports[`loader should reuse \`ast\` from "postcss-loader": errors 1`] = `Array []`;
434

535
exports[`loader should reuse \`ast\` from "postcss-loader": module 1`] = `
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './basic.css';
2+
3+
__export__ = css;
4+
5+
export default css;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import css from './basic.postcss.css';
2+
3+
__export__ = css;
4+
5+
export default css;
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;

test/fixtures/contenthash/basic.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a {
2+
color: red;
3+
}
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/fixtures/contenthash/basic.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$var: red;
2+
3+
a {
4+
color: $var;
5+
6+
&:hover {
7+
color: $var;
8+
}
9+
}

test/loader.test.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,133 @@ describe('loader', () => {
308308
expect(getWarnings(stats)).toMatchSnapshot('warnings');
309309
expect(getErrors(stats)).toMatchSnapshot('errors');
310310
});
311+
312+
it('should have same "contenthash" with "css-loader" and source maps', async () => {
313+
const compiler = getCompiler(
314+
'./contenthash/basic-css.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: /\.css$/i,
327+
rules: [
328+
{
329+
loader: path.resolve(__dirname, '../src'),
330+
options: { sourceMap: true },
331+
},
332+
],
333+
},
334+
],
335+
},
336+
}
337+
);
338+
const stats = await compile(compiler);
339+
340+
expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('module');
341+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
342+
expect(getErrors(stats)).toMatchSnapshot('errors');
343+
});
344+
345+
it('should have same "contenthash" with "postcss-loader" and source maps', async () => {
346+
const compiler = getCompiler(
347+
'./contenthash/basic-postcss.js',
348+
{},
349+
{
350+
output: {
351+
path: path.resolve(__dirname, '../outputs'),
352+
filename: '[name].[contenthash].bundle.js',
353+
chunkFilename: '[name].[contenthash].chunk.js',
354+
publicPath: '/webpack/public/path/',
355+
},
356+
module: {
357+
rules: [
358+
{
359+
test: /\.css$/i,
360+
rules: [
361+
{
362+
loader: path.resolve(__dirname, '../src'),
363+
options: {
364+
sourceMap: true,
365+
importLoaders: 1,
366+
},
367+
},
368+
{
369+
loader: 'postcss-loader',
370+
options: {
371+
plugins: () => [postcssPresetEnv({ stage: 0 })],
372+
sourceMap: true,
373+
},
374+
},
375+
],
376+
},
377+
],
378+
},
379+
}
380+
);
381+
const stats = await compile(compiler);
382+
383+
expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('module');
384+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
385+
expect(getErrors(stats)).toMatchSnapshot('errors');
386+
});
387+
388+
it('should have same "contenthash" with "sass-loader" and source maps', async () => {
389+
const compiler = getCompiler(
390+
'./contenthash/basic-sass.js',
391+
{},
392+
{
393+
output: {
394+
path: path.resolve(__dirname, '../outputs'),
395+
filename: '[name].[contenthash].bundle.js',
396+
chunkFilename: '[name].[contenthash].chunk.js',
397+
publicPath: '/webpack/public/path/',
398+
},
399+
module: {
400+
rules: [
401+
{
402+
test: /\.s[ca]ss$/i,
403+
rules: [
404+
{
405+
loader: path.resolve(__dirname, '../src'),
406+
options: {
407+
sourceMap: true,
408+
importLoaders: 1,
409+
},
410+
},
411+
{
412+
loader: 'postcss-loader',
413+
options: {
414+
plugins: () => [postcssPresetEnv({ stage: 0 })],
415+
sourceMap: true,
416+
},
417+
},
418+
{
419+
loader: 'sass-loader',
420+
options: {
421+
// eslint-disable-next-line global-require
422+
implementation: require('sass'),
423+
sourceMap: true,
424+
},
425+
},
426+
],
427+
},
428+
],
429+
},
430+
}
431+
);
432+
const stats = await compile(compiler);
433+
434+
console.log(stats.compilation.assets);
435+
436+
expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('module');
437+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
438+
expect(getErrors(stats)).toMatchSnapshot('errors');
439+
});
311440
});

0 commit comments

Comments
 (0)