Skip to content

Commit 7731565

Browse files
authored
fix(toolkit): correcty load cdk.json file without context (#1900)
1 parent f6adb7c commit 7731565

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/aws-cdk/lib/settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export class Context {
8686
}
8787

8888
public everything(): {[key: string]: any} {
89-
const b = this.bottom.get(this.bottomPrefixPath);
90-
const t = this.top.get([]);
89+
const b = this.bottom.get(this.bottomPrefixPath) || {};
90+
const t = this.top.get([]) || {};
9191
return Object.assign(b, t);
9292
}
9393

packages/aws-cdk/test/test.context.ts

+32
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,36 @@ export = {
110110

111111
test.done();
112112
},
113+
114+
async 'surive missing new file'(test: Test) {
115+
// GIVEN
116+
await fs.writeJSON('cdk.json', { context: { boo: 'far' } });
117+
const config = await new Configuration().load();
118+
119+
// WHEN
120+
test.deepEqual(config.context.everything(), { boo: 'far' });
121+
await config.saveContext();
122+
123+
// THEN
124+
test.deepEqual(await fs.readJSON('cdk.context.json'), {});
125+
test.deepEqual(await fs.readJSON('cdk.json'), { context: { boo: 'far' } });
126+
127+
test.done();
128+
},
129+
130+
async 'surive no context in old file'(test: Test) {
131+
// GIVEN
132+
await fs.writeJSON('cdk.json', { });
133+
await fs.writeJSON('cdk.context.json', { boo: 'far' });
134+
const config = await new Configuration().load();
135+
136+
// WHEN
137+
test.deepEqual(config.context.everything(), { boo: 'far' });
138+
await config.saveContext();
139+
140+
// THEN
141+
test.deepEqual(await fs.readJSON('cdk.context.json'), { boo: 'far' });
142+
143+
test.done();
144+
},
113145
};

0 commit comments

Comments
 (0)