Skip to content

Commit

Permalink
feat: configtest
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jan 5, 2021
1 parent edd782d commit 417075b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 2 additions & 6 deletions packages/configtest/src/index.ts
Expand Up @@ -13,19 +13,15 @@ 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
const validationErrors: any = validate(options);

if (validationErrors) {
logger.error(validationErrors);
process.exit(2);
}

logger.success('There are no validation errors in the given webpack configuration.');
Expand Down
14 changes: 11 additions & 3 deletions test/configtest/configtest.test.js
Expand Up @@ -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();
});
});

0 comments on commit 417075b

Please sign in to comment.