Skip to content

Commit 0a97681

Browse files
test: postcss emit error
1 parent e54e8aa commit 0a97681

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

test/CssMinimizerPlugin.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,38 @@ describe('CssMinimizerPlugin', () => {
256256
});
257257
});
258258

259+
it('should throw error from postcss', () => {
260+
const compiler = getCompiler({
261+
entry: {
262+
foo: `${__dirname}/fixtures/test/foo.css`,
263+
},
264+
});
265+
266+
new CssMinimizerPlugin({
267+
minify: (data) => {
268+
// eslint-disable-next-line global-require
269+
const postcss = require('postcss');
270+
271+
const plugin = postcss.plugin('error-plugin', () => (css) => {
272+
css.walkDecls((decl) => {
273+
throw decl.error('Postcss error');
274+
});
275+
});
276+
277+
return postcss([plugin])
278+
.process(data.input, data.postcssOptions)
279+
.then((result) => {
280+
return result;
281+
});
282+
},
283+
}).apply(compiler);
284+
285+
return compile(compiler).then((stats) => {
286+
expect(getErrors(stats)).toMatchSnapshot('error');
287+
expect(getWarnings(stats)).toMatchSnapshot('warning');
288+
});
289+
});
290+
259291
it('should build warning', () => {
260292
const compiler = getCompiler({
261293
entry: {

test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Ar
5959

6060
exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`;
6161

62+
exports[`CssMinimizerPlugin should throw error from postcss: error 1`] = `
63+
Array [
64+
"Error: foo.css from Css Minimizer
65+
error-plugin: /foo.css:2:3: Postcss error [foo.css:2,3]",
66+
]
67+
`;
68+
69+
exports[`CssMinimizerPlugin should throw error from postcss: warning 1`] = `Array []`;
70+
6271
exports[`CssMinimizerPlugin should work and show minimized assets in stats: assets 1`] = `
6372
Object {
6473
"foo.css": "body{color:red}a{color:#00f}",

test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Ar
5959

6060
exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`;
6161

62+
exports[`CssMinimizerPlugin should throw error from postcss: error 1`] = `
63+
Array [
64+
"Error: foo.css from Css Minimizer
65+
error-plugin: /foo.css:2:3: Postcss error [foo.css:2,3]",
66+
]
67+
`;
68+
69+
exports[`CssMinimizerPlugin should throw error from postcss: warning 1`] = `Array []`;
70+
6271
exports[`CssMinimizerPlugin should work and generate real content hash: assets 1`] = `
6372
Object {
6473
"entry.19e4764f9c1d9fe130e2.2d6ce991710d63180e35.87eaf84ce322e15b3c17.css": "body{color:red}a{color:#00f}",

0 commit comments

Comments
 (0)