From beaf03d6ae3457e5a82a44e59d7e12d52b9fe934 Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Mon, 17 Jun 2019 10:01:10 +0200 Subject: [PATCH] chore: clean up cdk.out after running integration tests (#2871) --- tools/cdk-integ-tools/lib/integ-helpers.ts | 20 +++++----- tools/cdk-integ-tools/package-lock.json | 43 ++++++++++++++++++++++ tools/cdk-integ-tools/package.json | 2 + 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/tools/cdk-integ-tools/lib/integ-helpers.ts b/tools/cdk-integ-tools/lib/integ-helpers.ts index 7eec3a9250519..0848b144c2fa7 100644 --- a/tools/cdk-integ-tools/lib/integ-helpers.ts +++ b/tools/cdk-integ-tools/lib/integ-helpers.ts @@ -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 { @@ -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)); } } @@ -135,21 +132,24 @@ export class IntegrationTest { } public async readExpected(): Promise { - 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'); + } } /** @@ -157,7 +157,7 @@ export class IntegrationTest { * contents. This allows integ tests to supply custom command line arguments to "cdk deploy" and "cdk synth". */ private async readStackPragma(): Promise { - 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 []; diff --git a/tools/cdk-integ-tools/package-lock.json b/tools/cdk-integ-tools/package-lock.json index 36904a2903b7e..c5686b72c6834 100644 --- a/tools/cdk-integ-tools/package-lock.json +++ b/tools/cdk-integ-tools/package-lock.json @@ -4,6 +4,21 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/fs-extra": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-7.0.0.tgz", + "integrity": "sha512-ndoMMbGyuToTy4qB6Lex/inR98nPiNHacsgMPvy+zqMLgSxbt8VtWpDArpGp69h1fEDQHn1KB+9DWD++wgbwYA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/node": { + "version": "12.0.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.8.tgz", + "integrity": "sha512-b8bbUOTwzIY3V5vDTY1fIJ+ePKDUBqt2hC2woVGotdQQhG/2Sh62HOKHrT7ab+VerXAcPyAiTEipPu/FsreUtg==", + "dev": true + }, "@types/yargs": { "version": "13.0.0", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.0.tgz", @@ -112,6 +127,16 @@ "locate-path": "^3.0.0" } }, + "fs-extra": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.0.1.tgz", + "integrity": "sha512-W+XLrggcDzlle47X/XnS7FXrXu9sDo+Ze9zpndeBxdgv88FHLm1HtmkhEwavruS6koanBjp098rUpHs65EmG7A==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -125,6 +150,11 @@ "pump": "^3.0.0" } }, + "graceful-fs": { + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" + }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", @@ -145,6 +175,14 @@ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, "lcid": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", @@ -332,6 +370,11 @@ "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/tools/cdk-integ-tools/package.json b/tools/cdk-integ-tools/package.json index 3a215ee26263d..9dba7fdbfc933 100644 --- a/tools/cdk-integ-tools/package.json +++ b/tools/cdk-integ-tools/package.json @@ -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" @@ -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": [