Skip to content

Commit

Permalink
chore(cli): "cdk context" is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
NetaNir committed Oct 7, 2020
1 parent c58127b commit 7722cca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 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 @@ -81,7 +81,7 @@ function listContext(context: any) {
function invalidateContext(context: Context, key: string) {
const i = parseInt(key, 10);
if (`${i}` === key) {
// Twas a number and we fully parsed it.
// was a number and we fully parsed it.
key = keyByNumber(context, i);
}

Expand All @@ -107,7 +107,7 @@ function keyByNumber(context: any, n: number) {
* Return enumerated keys in a definitive order
*/
function contextKeys(context: Context): [number, string][] {
const keys = context.keys;
const keys = Object.keys(context);
keys.sort();
return enumerate1(keys);
}
Expand Down
17 changes: 5 additions & 12 deletions packages/aws-cdk/test/commands/context-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import { realHandler } from '../../lib/commands/context';
import { Configuration } from '../../lib/settings';

test('context reset can remove a context key', async () => {
test('context list', 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: 'foo' },
args: {},
} as any);

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

test('context reset can remove a context key using number', async () => {
test('context reset can remove a context key', async () => {
// GIVEN
const configuration = new Configuration();
configuration.context.set('foo', 'bar');
Expand All @@ -38,11 +31,11 @@ test('context reset can remove a context key using number', async () => {
// WHEN
await realHandler({
configuration,
args: { reset: '1' },
args: { reset: 'foo' },
} as any);

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

0 comments on commit 7722cca

Please sign in to comment.