Skip to content

Commit

Permalink
fix(cdk-integ): Update cdk-integ to use new context file (#1962)
Browse files Browse the repository at this point in the history
Running integ tests is currently broken, since the integ tests will
write context to `cdk.json`, which then gets moved to
`cdk.context.json`. `cdk.json` gets cleaned up afterwards but
`cdk.context.json` does not, so it gets left there and messes up the
next integ run.

Just write all fake context to `cdk.context.json` right now as intended.
  • Loading branch information
rix0rrr authored and RomainMuller committed Mar 6, 2019
1 parent 1767b61 commit dbd2401
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tools/cdk-integ-tools/lib/integ-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,33 @@ export class IntegrationTests {
export class IntegrationTest {
public readonly expectedFileName: string;
private readonly expectedFilePath: string;
private readonly cdkConfigPath: string;
private readonly cdkContextPath: string;

constructor(private readonly directory: string, public readonly name: string) {
const baseName = this.name.endsWith('.js') ? this.name.substr(0, this.name.length - 3) : this.name;
this.expectedFileName = baseName + '.expected.json';
this.expectedFilePath = path.join(this.directory, this.expectedFileName);
this.cdkConfigPath = path.join(this.directory, 'cdk.json');
this.cdkContextPath = path.join(this.directory, 'cdk.context.json');
}

public async invoke(args: string[], options: { json?: boolean, context?: any, verbose?: boolean } = { }): Promise<any> {
// Write context to cdk.json, afterwards delete. We need to do this because there is no way
// to pass structured context data from the command-line, currently.
if (options.context) {
await this.writeCdkConfig({ context: options.context, versionReporting: false });
await this.writeCdkContext(options.context);
} else {
this.deleteCdkConfig();
this.deleteCdkContext();
}

try {
const cdk = require.resolve('aws-cdk/bin/cdk');
return exec([cdk, '-a', `node ${this.name}`].concat(args), {
return exec([cdk, '-a', `node ${this.name}`, '--no-version-reporting'].concat(args), {
cwd: this.directory,
json: options.json,
verbose: options.verbose,
});
} finally {
this.deleteCdkConfig();
this.deleteCdkContext();
}
}

Expand All @@ -103,13 +103,13 @@ export class IntegrationTest {
await util.promisify(fs.writeFile)(this.expectedFilePath, JSON.stringify(actual, undefined, 2), { encoding: 'utf-8' });
}

private async writeCdkConfig(config: any) {
await util.promisify(fs.writeFile)(this.cdkConfigPath, JSON.stringify(config, undefined, 2), { encoding: 'utf-8' });
private async writeCdkContext(config: any) {
await util.promisify(fs.writeFile)(this.cdkContextPath, JSON.stringify(config, undefined, 2), { encoding: 'utf-8' });
}

private deleteCdkConfig() {
if (fs.existsSync(this.cdkConfigPath)) {
fs.unlinkSync(this.cdkConfigPath);
private deleteCdkContext() {
if (fs.existsSync(this.cdkContextPath)) {
fs.unlinkSync(this.cdkContextPath);
}
}
}
Expand Down

0 comments on commit dbd2401

Please sign in to comment.