Skip to content

Commit

Permalink
chore: clean up cdk.out after running integration tests (#2871)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller authored and rix0rrr committed Jun 17, 2019
1 parent b0730dd commit beaf03d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tools/cdk-integ-tools/lib/integ-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Helper functions for integration tests
import { DEFAULT_ACCOUNT_CONTEXT_KEY, DEFAULT_REGION_CONTEXT_KEY } from '@aws-cdk/cx-api';
import { spawnSync } from 'child_process';
import fs = require('fs');
import fs = require('fs-extra');
import path = require('path');
import util = require('util');

const stat = util.promisify(fs.stat);
const readdir = util.promisify(fs.readdir);
const CDK_INTEG_STACK_PRAGMA = '/// !cdk-integ';

export class IntegrationTests {
Expand Down Expand Up @@ -53,10 +50,10 @@ export class IntegrationTests {
const rootDir = this.directory;

async function recurse(dir: string) {
const files = await readdir(dir);
const files = await fs.readdir(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const statf = await stat(fullPath);
const statf = await fs.stat(fullPath);
if (statf.isFile()) { ret.push(fullPath.substr(rootDir.length + 1)); }
if (statf.isDirectory()) { await recurse(path.join(fullPath)); }
}
Expand Down Expand Up @@ -135,29 +132,32 @@ export class IntegrationTest {
}

public async readExpected(): Promise<any> {
return JSON.parse((await util.promisify(fs.readFile)(this.expectedFilePath, { encoding: 'utf-8' })));
return JSON.parse(await fs.readFile(this.expectedFilePath, { encoding: 'utf-8' }));
}

public async writeExpected(actual: any) {
await util.promisify(fs.writeFile)(this.expectedFilePath, JSON.stringify(actual, undefined, 2), { encoding: 'utf-8' });
await fs.writeFile(this.expectedFilePath, JSON.stringify(actual, 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' });
await fs.writeFile(this.cdkContextPath, JSON.stringify(config, undefined, 2), { encoding: 'utf-8' });
}

private deleteCdkContext() {
if (fs.existsSync(this.cdkContextPath)) {
fs.unlinkSync(this.cdkContextPath);
}
if (fs.existsSync('cdk.out')) {
fs.removeSync('cdk.out');
}
}

/**
* Reads the test source file and looks for the "!cdk-integ" pragma. If it exists, returns it's
* contents. This allows integ tests to supply custom command line arguments to "cdk deploy" and "cdk synth".
*/
private async readStackPragma(): Promise<string[]> {
const source = await util.promisify(fs.readFile)(this.sourceFilePath, 'utf-8');
const source = await fs.readFile(this.sourceFilePath, 'utf-8');
const pragmaLine = source.split('\n').find(x => x.startsWith(CDK_INTEG_STACK_PRAGMA + ' '));
if (!pragmaLine) {
return [];
Expand Down
43 changes: 43 additions & 0 deletions tools/cdk-integ-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tools/cdk-integ-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/fs-extra": "^7.0.0",
"@types/yargs": "^13.0.0",
"cdk-build-tools": "^0.34.0",
"pkglint": "^0.34.0"
Expand All @@ -37,6 +38,7 @@
"@aws-cdk/cloudformation-diff": "^0.34.0",
"@aws-cdk/cx-api": "^0.34.0",
"aws-cdk": "^0.34.0",
"fs-extra": "^8.0.1",
"yargs": "^13.2.4"
},
"keywords": [
Expand Down

0 comments on commit beaf03d

Please sign in to comment.