/
config-error.test.js
34 lines (26 loc) · 1.13 KB
/
config-error.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const { resolve } = require('path');
const { run } = require('../../utils/test-utils');
describe('config error', () => {
it('should throw error with invalid configuration', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.mjs')], {
env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true },
});
expect(exitCode).toBe(2);
if (!/Error: Not supported/.test(stderr)) {
expect(stderr).toContain('Invalid configuration object');
expect(stderr).toContain(`"development" | "production" | "none"`);
}
expect(stdout).toBeFalsy();
});
it('should throw syntax error and exit with non-zero exit code', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-c', resolve(__dirname, 'syntax-error.mjs')], {
env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true },
});
expect(exitCode).toBe(2);
if (!/Error: Not supported/.test(stderr)) {
expect(stderr).toContain('SyntaxError: Unexpected token');
}
expect(stdout).toBeFalsy();
});
});