Skip to content

Commit

Permalink
fix(toolkit): correcty load cdk.json file without context (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
rix0rrr authored Feb 27, 2019
1 parent f6adb7c commit 7731565
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export class Context {
}

public everything(): {[key: string]: any} {
const b = this.bottom.get(this.bottomPrefixPath);
const t = this.top.get([]);
const b = this.bottom.get(this.bottomPrefixPath) || {};
const t = this.top.get([]) || {};
return Object.assign(b, t);
}

Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk/test/test.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,36 @@ export = {

test.done();
},

async 'surive missing new file'(test: Test) {
// GIVEN
await fs.writeJSON('cdk.json', { context: { boo: 'far' } });
const config = await new Configuration().load();

// WHEN
test.deepEqual(config.context.everything(), { boo: 'far' });
await config.saveContext();

// THEN
test.deepEqual(await fs.readJSON('cdk.context.json'), {});
test.deepEqual(await fs.readJSON('cdk.json'), { context: { boo: 'far' } });

test.done();
},

async 'surive no context in old file'(test: Test) {
// GIVEN
await fs.writeJSON('cdk.json', { });
await fs.writeJSON('cdk.context.json', { boo: 'far' });
const config = await new Configuration().load();

// WHEN
test.deepEqual(config.context.everything(), { boo: 'far' });
await config.saveContext();

// THEN
test.deepEqual(await fs.readJSON('cdk.context.json'), { boo: 'far' });

test.done();
},
};

0 comments on commit 7731565

Please sign in to comment.