Skip to content

Commit

Permalink
tests: add tests in case of warnings from loader
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 18, 2020
1 parent 8611c6a commit 33097e1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Compiler {
logger.error(err.stack || err);
process.exit(1); // eslint-disable-line
}
if (!outputOptions.watch && stats.hasErrors()) {
if (!outputOptions.watch && (stats.hasErrors() || stats.hasWarnings())) {
process.exitCode = 1;
}
if (outputOptions.json) {
Expand Down
17 changes: 17 additions & 0 deletions test/loader/warning-test/dist/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is not neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/*!*********************!*\
!*** ./src/main.js ***!
\*********************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: */
eval("console.log('loader warning test');\n\n\n//# sourceURL=webpack:///./src/main.js?");
/******/ })()
;
12 changes: 12 additions & 0 deletions test/loader/warning-test/loader-warning.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const { run } = require('../../utils/test-utils');

describe('loader warning test', () => {
it(`should not ignore loader's warning and exit with a non zero exit code`, () => {
const { stdout, exitCode } = run(__dirname, [], false);

expect(stdout).toContain('This is a warning');
expect(exitCode).not.toEqual(0);
});
});
5 changes: 5 additions & 0 deletions test/loader/warning-test/my-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function loader(source) {
const { emitWarning } = this;
emitWarning('This is a warning');
return source;
};
1 change: 1 addition & 0 deletions test/loader/warning-test/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('loader warning test');
30 changes: 30 additions & 0 deletions test/loader/warning-test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path');

module.exports = {
mode: 'development',

entry: {
bundle: './src/main.js',
},

output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},

module: {
rules: [
{
test: /.(js|jsx)?$/,
loader: 'my-loader',
include: [path.resolve(__dirname, 'src')],
exclude: [/node_modules/],
},
],
},
resolveLoader: {
alias: {
'my-loader': require.resolve('./my-loader'),
},
},
};

0 comments on commit 33097e1

Please sign in to comment.