Skip to content

Commit

Permalink
fix(cli): cdk context --reset <number> does not work (aws#10619)
Browse files Browse the repository at this point in the history
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*

Fixes aws#3033
  • Loading branch information
diesal11 authored Oct 5, 2020
1 parent a72cfbd commit 3f62752
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/commands/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function keyByNumber(context: any, n: number) {
/**
* Return enumerated keys in a definitive order
*/
function contextKeys(context: any) {
const keys = Object.keys(context);
function contextKeys(context: Context): [number, string][] {
const keys = context.keys;
keys.sort();
return enumerate1(keys);
}
Expand Down
23 changes: 23 additions & 0 deletions packages/aws-cdk/test/commands/context-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,26 @@ test('context reset can remove a context key', async () => {
baz: 'quux',
});
});

test('context reset can remove a context key using number', async () => {
// GIVEN
const configuration = new Configuration();
configuration.context.set('foo', 'bar');
configuration.context.set('baz', 'quux');

expect(configuration.context.all).toEqual({
foo: 'bar',
baz: 'quux',
});

// WHEN
await realHandler({
configuration,
args: { reset: '1' },
} as any);

// THEN
expect(configuration.context.all).toEqual({
foo: 'bar',
});
});

0 comments on commit 3f62752

Please sign in to comment.