diff --git a/packages/configtest/src/index.ts b/packages/configtest/src/index.ts index cd5a318327f..4fc6bc5f068 100644 --- a/packages/configtest/src/index.ts +++ b/packages/configtest/src/index.ts @@ -13,12 +13,7 @@ class ConfigTestCommand { pkg: '@webpack-cli/configtest', }, [], - async (configPath, program) => { - if (program.args.length > 1) { - logger.error('Only one configuration can be validated at a time.'); - process.exit(2); - } - + async (configPath: string) => { const { options } = await cli.resolveConfig({ config: [configPath] }); //eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -26,6 +21,7 @@ class ConfigTestCommand { if (validationErrors) { logger.error(validationErrors); + process.exit(2); } logger.success('There are no validation errors in the given webpack configuration.'); diff --git a/test/configtest/configtest.test.js b/test/configtest/configtest.test.js index 05b9fa4fc98..0831bc2a39a 100644 --- a/test/configtest/configtest.test.js +++ b/test/configtest/configtest.test.js @@ -29,11 +29,19 @@ describe('basic info usage', () => { expect(stdout).toBeFalsy(); }); - it('should throw error when multiple configurations are provided simultaneously', () => { - const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './error.config.js', './webpack.config.js'], false); + it('should throw error if configuration does not exist', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './a.js'], false); expect(exitCode).toBe(2); - expect(stderr).toContain('Only one configuration can be validated at a time'); + expect(stderr).toContain(`The specified config file doesn't exist`); + expect(stdout).toBeFalsy(); + }); + + it('should throw error if no configuration was provided', () => { + const { exitCode, stderr, stdout } = run(__dirname, ['configtest'], false); + + expect(exitCode).toBe(2); + expect(stderr).toContain(`error: missing required argument 'config-path'`); expect(stdout).toBeFalsy(); }); });