From dd39959631aecbc3d7a594d8e5cdc6de4e5ae229 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 24 Oct 2020 21:25:48 +0530 Subject: [PATCH] tests: for exit-code in case of error in config (#1979) --- .eslintignore | 1 + .prettierignore | 1 + test/config/error/config-error.test.js | 20 ++++++++++++++++++++ test/config/error/src/index.js | 1 + test/config/error/syntax-error.js | 5 +++++ test/config/error/webpack.config.js | 5 +++++ 6 files changed, 33 insertions(+) create mode 100644 test/config/error/config-error.test.js create mode 100644 test/config/error/src/index.js create mode 100644 test/config/error/syntax-error.js create mode 100644 test/config/error/webpack.config.js diff --git a/.eslintignore b/.eslintignore index aafbffa5401..d1514bd87ba 100644 --- a/.eslintignore +++ b/.eslintignore @@ -15,6 +15,7 @@ test/**/bin/ test/**/binary/ test/**/index.js test/typescript/webpack.config.ts +test/config/error/syntax-error.js test/plugin/test-plugin/test/test-utils.js test/plugin/test-plugin/test/functional.test.js test/plugin/test-plugin/examples/simple/src/static-esm-module.js diff --git a/.prettierignore b/.prettierignore index a039fd52884..d037f141282 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ test/**/dist/ test/**/bin/ test/**/binary/ test/**/index.js +test/config/error/syntax-error.js diff --git a/test/config/error/config-error.test.js b/test/config/error/config-error.test.js new file mode 100644 index 00000000000..d11e29e29a7 --- /dev/null +++ b/test/config/error/config-error.test.js @@ -0,0 +1,20 @@ +'use strict'; +const { resolve } = require('path'); +const { run } = require('../../utils/test-utils'); + +describe('config error', () => { + it('should throw error with invalid configuration', () => { + const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')]); + + expect(stderr).toContain('Invalid configuration object'); + expect(stderr).toContain(`"development" | "production" | "none"`); + expect(exitCode).toBe(2); + }); + + it('should throw syntax error and exit with non-zero exit code', () => { + const { stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'syntax-error.js')]); + + expect(stderr).toContain('SyntaxError: Unexpected token'); + expect(exitCode).toBe(2); + }); +}); diff --git a/test/config/error/src/index.js b/test/config/error/src/index.js new file mode 100644 index 00000000000..97bfc742a9b --- /dev/null +++ b/test/config/error/src/index.js @@ -0,0 +1 @@ +console.log('config error test'); diff --git a/test/config/error/syntax-error.js b/test/config/error/syntax-error.js new file mode 100644 index 00000000000..96fc2e63b73 --- /dev/null +++ b/test/config/error/syntax-error.js @@ -0,0 +1,5 @@ +module.exports = { + name: 'config-error', + mode: 'development', + target: 'node'; //SyntaxError: Unexpected token ';' +}; diff --git a/test/config/error/webpack.config.js b/test/config/error/webpack.config.js new file mode 100644 index 00000000000..a967a05223c --- /dev/null +++ b/test/config/error/webpack.config.js @@ -0,0 +1,5 @@ +module.exports = { + name: 'config-error', + mode: 'unknown', //error + target: 'node', +};