Skip to content

Commit

Permalink
tests: for exit-code in case of error in config (#1979)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Oct 24, 2020
1 parent 1e50e98 commit dd39959
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -4,3 +4,4 @@ test/**/dist/
test/**/bin/
test/**/binary/
test/**/index.js
test/config/error/syntax-error.js
20 changes: 20 additions & 0 deletions 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);
});
});
1 change: 1 addition & 0 deletions test/config/error/src/index.js
@@ -0,0 +1 @@
console.log('config error test');
5 changes: 5 additions & 0 deletions test/config/error/syntax-error.js
@@ -0,0 +1,5 @@
module.exports = {
name: 'config-error',
mode: 'development',
target: 'node'; //SyntaxError: Unexpected token ';'
};
5 changes: 5 additions & 0 deletions test/config/error/webpack.config.js
@@ -0,0 +1,5 @@
module.exports = {
name: 'config-error',
mode: 'unknown', //error
target: 'node',
};

0 comments on commit dd39959

Please sign in to comment.