Skip to content

Commit

Permalink
unit test overriding behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc authored and mrgrain committed Jan 24, 2025
1 parent 626eb68 commit c5d4908
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/aws-cdk/test/cli/cli-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ describe('yargs', () => {
assetMetadata: undefined,
build: undefined,
caBundlePath: undefined,
context: [],
context: undefined,
ignoreErrors: false,
noColor: false,
pathMetadata: undefined,
plugin: [],
plugin: undefined,
profile: undefined,
proxy: undefined,
roleArn: undefined,
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('yargs', () => {
progress: undefined,
requireApproval: undefined,
rollback: false,
tags: [],
tags: undefined,
toolkitStackName: undefined,
watch: undefined,
},
Expand Down
31 changes: 31 additions & 0 deletions packages/aws-cdk/test/cli/user-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as os from 'os';
import * as fs_path from 'path';
import * as fs from 'fs-extra';
import { Configuration, PROJECT_CONFIG, PROJECT_CONTEXT } from '../../lib/cli/user-configuration';
import { parseCommandLineArguments } from '../../lib/cli/parse-command-line-arguments';

// mock fs deeply
jest.mock('fs-extra');
Expand Down Expand Up @@ -112,3 +113,33 @@ test('Can specify the `quiet` key in the user config', async () => {

expect(config.settings.get(['quiet'])).toBe(true);
});

test('array settings are not overridden by yarg defaults', async () => {
// GIVEN
const GIVEN_CONFIG: Map<string, any> = new Map([
[PROJECT_CONFIG, {
plugin: ['dummy'],
}],
]);
const argsWithPlugin = await parseCommandLineArguments(['ls', '--plugin', '[]']);
const argsWithoutPlugin = await parseCommandLineArguments(['ls']);

// WHEN
mockedFs.pathExists.mockImplementation(path => {
return GIVEN_CONFIG.has(path);
});
mockedFs.readJSON.mockImplementation(path => {
return GIVEN_CONFIG.get(path);
});

const configWithPlugin = await new Configuration({
commandLineArguments: argsWithPlugin,
}).load();
const configWithoutPlugin = await new Configuration({
commandLineArguments: argsWithoutPlugin,
}).load();

// THEN
expect(configWithPlugin.settings.get(['plugin'])).toEqual(['[]']);
expect(configWithoutPlugin.settings.get(['plugin'])).toEqual(['dummy']);
});

0 comments on commit c5d4908

Please sign in to comment.