diff --git a/.projenrc.ts b/.projenrc.ts index b154d9750..14733a6d4 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -691,6 +691,7 @@ const tmpToolkitHelpers = configureProject( 'wrap-ansi@^7', // Last non-ESM version 'yaml@^1', ], + tsconfig: { compilerOptions: { ...defaultTsOptions, @@ -699,6 +700,24 @@ const tmpToolkitHelpers = configureProject( module: 'NodeNext', }, }, + + jestOptions: jestOptionsForProject({ + jestConfig: { + coverageThreshold: { + // We want to improve our test coverage + // DO NOT LOWER THESE VALUES! + // If you need to break glass, open an issue to re-up the values with additional test coverage + statements: 80, + branches: 80, + functions: 80, + lines: 80, + }, + // We have many tests here that commonly time out + testTimeout: 30_000, + testEnvironment: './test/_helpers/jest-bufferedconsole.ts', + setupFilesAfterEnv: ['/test/_helpers/jest-setup-after-env.ts'], + }, + }), }), ); @@ -713,6 +732,12 @@ tmpToolkitHelpers.package.addField('exports', { tmpToolkitHelpers.eslint?.addRules({ '@cdklabs/no-throw-default-error': 'error', }); +tmpToolkitHelpers.eslint?.addOverride({ + files: ['./test/**'], + rules: { + '@cdklabs/no-throw-default-error': 'off', + }, +}); tmpToolkitHelpers.gitignore.addPatterns('test/**/*.map'); @@ -849,9 +874,9 @@ const cli = configureProject( '/lib/api/aws-auth/sdk.ts', // Files generated by cli-args-gen - '/lib/parse-command-line-arguments.ts', - '/lib/user-input.ts', - '/lib/convert-to-user-input.ts', + '/lib/cli/parse-command-line-arguments.ts', + '/lib/cli/user-input.ts', + '/lib/cli/convert-to-user-input.ts', ], testEnvironment: './test/_helpers/jest-bufferedconsole.ts', setupFilesAfterEnv: ['/test/_helpers/jest-setup-after-env.ts'], @@ -867,7 +892,7 @@ const cli = configureProject( // Eslint rules cli.eslint?.addRules({ - '@cdklabs/no-throw-default-error': ['error'], + '@cdklabs/no-throw-default-error': 'error', }); cli.eslint?.addOverride({ files: ['./test/**'], @@ -1177,7 +1202,6 @@ const toolkitLib = configureProject( }, jestOptions: jestOptionsForProject({ jestConfig: { - testEnvironment: './test/_helpers/jest-bufferedconsole.ts', coverageThreshold: { // this is very sad but we will get better statements: 85, @@ -1185,6 +1209,8 @@ const toolkitLib = configureProject( functions: 77, lines: 85, }, + testEnvironment: './test/_helpers/jest-bufferedconsole.ts', + setupFilesAfterEnv: ['/test/_helpers/jest-setup-after-env.ts'], }, }), tsconfig: { diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/.eslintrc.json b/packages/@aws-cdk/tmp-toolkit-helpers/.eslintrc.json index 37f148684..9a8a259e9 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/.eslintrc.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/.eslintrc.json @@ -317,5 +317,14 @@ ], "@cdklabs/no-throw-default-error": "error" }, - "overrides": [] + "overrides": [ + { + "files": [ + "./test/**" + ], + "rules": { + "@cdklabs/no-throw-default-error": "off" + } + } + ] } diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/jest.config.json b/packages/@aws-cdk/tmp-toolkit-helpers/jest.config.json index c0e3067d0..99a63cac6 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/jest.config.json +++ b/packages/@aws-cdk/tmp-toolkit-helpers/jest.config.json @@ -5,7 +5,7 @@ "js" ], "maxWorkers": "80%", - "testEnvironment": "node", + "testEnvironment": "./test/_helpers/jest-bufferedconsole.ts", "coverageThreshold": { "global": { "statements": 80, @@ -47,6 +47,10 @@ ] ], "randomize": true, + "testTimeout": 30000, + "setupFilesAfterEnv": [ + "/test/_helpers/jest-setup-after-env.ts" + ], "clearMocks": true, "coverageDirectory": "coverage", "testPathIgnorePatterns": [ diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/index.ts b/packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/index.ts index e4ab7fedf..86597e245 100644 --- a/packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/index.ts +++ b/packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/index.ts @@ -5,4 +5,3 @@ export * from './message-maker'; export * from './messages'; export * from './types'; export * from './io-default-messages'; -export * from './testing'; diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-bufferedconsole.ts b/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-bufferedconsole.ts new file mode 100644 index 000000000..043b819ec --- /dev/null +++ b/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-bufferedconsole.ts @@ -0,0 +1,111 @@ +/* eslint-disable import/no-extraneous-dependencies,@typescript-eslint/unbound-method */ +/** + * A Jest environment that buffers outputs to `console.log()` and only shows it for failing tests. + */ +import type { EnvironmentContext, JestEnvironment, JestEnvironmentConfig } from '@jest/environment'; +import type { Circus } from '@jest/types'; +import { TestEnvironment as NodeEnvironment } from 'jest-environment-node'; + +interface ConsoleMessage { + type: 'log' | 'error' | 'warn' | 'info' | 'debug'; + args: any[]; +} + +export default class TestEnvironment extends NodeEnvironment implements JestEnvironment { + private log = new Array(); + + private originalConsole!: typeof console; + private originalStdoutWrite!: typeof process.stdout.write; + private originalStderrWrite!: typeof process.stderr.write; + + constructor(config: JestEnvironmentConfig, context: EnvironmentContext) { + super(config, context); + + // We need to set the event handler by assignment in the constructor, + // because if we declare it as an async member TypeScript's type derivation + // doesn't work properly. + (this as JestEnvironment).handleTestEvent = (async (event, _state) => { + if (event.name === 'test_done' && event.test.errors.length > 0 && this.log.length > 0) { + this.stopCapture(); + + this.originalConsole.log(`[Console output] ${fullTestName(event.test)}\n`); + for (const item of this.log) { + this.originalConsole[item.type].apply(this.originalConsole, [' ', ...item.args]); + } + this.originalConsole.log('\n'); + + this.startCapture(); + } + + if (event.name === 'test_done') { + this.log = []; + } + }) satisfies Circus.EventHandler; + } + + async setup() { + await super.setup(); + + this.log = []; + this.startCapture(); + } + + async teardown() { + this.stopCapture(); + await super.teardown(); + } + + private startCapture() { + this.originalConsole = console; + this.originalStdoutWrite = process.stdout.write; + this.originalStderrWrite = process.stderr.write; + + this.global.console = { + ...console, + log: (...args) => this.log.push({ type: 'log', args }), + error: (...args) => this.log.push({ type: 'error', args }), + warn: (...args) => this.log.push({ type: 'warn', args }), + info: (...args) => this.log.push({ type: 'info', args }), + debug: (...args) => this.log.push({ type: 'debug', args }), + }; + + const self = this; + process.stdout.write = function (chunk: Buffer | string, enccb?: BufferEncoding | ((error?: Error | null) => void)): void { + const encoding = typeof enccb === 'string' ? enccb : 'utf-8'; + const message = Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk; + self.log.push({ type: 'log', args: [message.replace(/\n$/, '')] }); + if (typeof enccb === 'function') { + enccb(); + } + } as any; + process.stderr.write = function (chunk: Buffer | string, enccb?: BufferEncoding | ((error?: Error | null) => void)): void { + const encoding = typeof enccb === 'string' ? enccb : 'utf-8'; + const message = Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk; + self.log.push({ type: 'error', args: [message.replace(/\n$/, '')] }); + if (typeof enccb === 'function') { + enccb(); + } + } as any; + } + + private stopCapture() { + this.global.console = this.originalConsole; + process.stdout.write = this.originalStdoutWrite; + process.stderr.write = this.originalStderrWrite; + } +} + +// DescribeBlock is not exported from `@jest/types`, so we need to build the parts we are interested in +type TestDescription = PartialBy, 'parent'>; + +// Utility type to make specific fields optional +type PartialBy = Omit & Partial> + +function fullTestName(test: TestDescription) { + let ret = test.name; + while (test.parent != null && test.parent.name !== 'ROOT_DESCRIBE_BLOCK') { + ret = test.parent.name + ' › ' + ret; + test = test.parent; + } + return ret; +} diff --git a/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-setup-after-env.ts b/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-setup-after-env.ts new file mode 100644 index 000000000..e063a80c1 --- /dev/null +++ b/packages/@aws-cdk/tmp-toolkit-helpers/test/_helpers/jest-setup-after-env.ts @@ -0,0 +1,83 @@ +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; +import { isPromise } from 'util/types'; + +/** + * Global test setup for Jest tests + * + * It's easy to accidentally write tests that interfere with each other by + * writing files to disk in the "current directory". To prevent this, the global + * test setup creates a directory in the temporary directory and chmods it to + * being non-writable. That way, whenever a test tries to write to the current + * directory, it will produce an error and we'll be able to find and fix the + * test. + * + * If you see `EACCES: permission denied`, you have a test that creates files + * in the current directory, and you should be sure to do it in a temporary + * directory that you clean up afterwards. + * + * ## Alternate approach + * + * I tried an approach where I would automatically try to create and clean up + * temp directories for every test, but it was introducing too many conflicts + * with existing test behavior (around specific ordering of temp directory + * creation and cleanup tasks that are already present) in many places that I + * didn't want to go and chase down. + * + */ + +let tmpDir: string; +let oldDir: string; + +beforeAll(() => { + tmpDir = path.join(os.tmpdir(), 'cdk-nonwritable-on-purpose'); + fs.mkdirSync(tmpDir, { recursive: true }); + fs.chmodSync(tmpDir, 0o500); + oldDir = process.cwd(); + process.chdir(tmpDir); + tmpDir = process.cwd(); // This will have resolved symlinks +}); + +const reverseAfterAll: Array = []; + +/** + * We need a cleanup here + * + * 99% of the time, Jest runs the tests in a subprocess and this isn't + * necessary because we would have `chdir`ed in the subprocess. + * + * But sometimes we ask Jest with `-i` to run the tests in the main process, + * or if you only ask for a single test suite Jest runs the tests in the main + * process, and then we `chdir`ed the main process away. + * + * Jest will then try to write the `coverage` directory to the readonly directory, + * and fail. Chdir back to the original dir. + * + * If the test file has an `afterAll()` hook it installed as well, we need to run + * it before our cleanup, otherwise the wrong thing will happen (by default, + * all `afterAll()`s run in call order, but they should be run in reverse). + */ +afterAll(async () => { + for (const aft of reverseAfterAll.reverse()) { + await new Promise((resolve, reject) => { + const response = aft(resolve as any); + if (isPromise(response)) { + response.then(() => { + return resolve(); + }, reject); + } else { + resolve(); + } + }); + } + + if (process.cwd() === tmpDir) { + process.chdir(oldDir); + } +}); + +// Patch afterAll to make later-provided afterAll's run before us (in reverse order even). +afterAll = (after: jest.ProvidesHookCallback) => { + reverseAfterAll.push(after); +}; diff --git a/packages/@aws-cdk/toolkit-lib/jest.config.json b/packages/@aws-cdk/toolkit-lib/jest.config.json index e92181da8..5d78bd12e 100644 --- a/packages/@aws-cdk/toolkit-lib/jest.config.json +++ b/packages/@aws-cdk/toolkit-lib/jest.config.json @@ -47,6 +47,9 @@ ] ], "randomize": true, + "setupFilesAfterEnv": [ + "/test/_helpers/jest-setup-after-env.ts" + ], "clearMocks": true, "coverageDirectory": "coverage", "testPathIgnorePatterns": [ diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/index.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/index.ts index d8817ad78..276aae5bb 100644 --- a/packages/@aws-cdk/toolkit-lib/test/_helpers/index.ts +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/index.ts @@ -4,8 +4,8 @@ import * as path from 'node:path'; import type { AssemblyDirectoryProps, Toolkit } from '../../lib'; import { ToolkitError } from '../../lib'; -export * from '../../lib/api/shared-private'; export * from './test-cloud-assembly-source'; +export * from './test-io-host'; function fixturePath(...parts: string[]): string { return path.normalize(path.join(__dirname, '..', '_fixtures', ...parts)); @@ -18,6 +18,7 @@ export async function appFixture(toolkit: Toolkit, name: string, context?: { [ke } const app = `cat ${appPath} | node --input-type=module`; return toolkit.fromCdkApp(app, { + workingDirectory: path.join(__dirname, '..', '..'), outdir: tmpOutdir(), context, }); diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/jest-setup-after-env.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/jest-setup-after-env.ts new file mode 100644 index 000000000..e063a80c1 --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/jest-setup-after-env.ts @@ -0,0 +1,83 @@ +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; +import { isPromise } from 'util/types'; + +/** + * Global test setup for Jest tests + * + * It's easy to accidentally write tests that interfere with each other by + * writing files to disk in the "current directory". To prevent this, the global + * test setup creates a directory in the temporary directory and chmods it to + * being non-writable. That way, whenever a test tries to write to the current + * directory, it will produce an error and we'll be able to find and fix the + * test. + * + * If you see `EACCES: permission denied`, you have a test that creates files + * in the current directory, and you should be sure to do it in a temporary + * directory that you clean up afterwards. + * + * ## Alternate approach + * + * I tried an approach where I would automatically try to create and clean up + * temp directories for every test, but it was introducing too many conflicts + * with existing test behavior (around specific ordering of temp directory + * creation and cleanup tasks that are already present) in many places that I + * didn't want to go and chase down. + * + */ + +let tmpDir: string; +let oldDir: string; + +beforeAll(() => { + tmpDir = path.join(os.tmpdir(), 'cdk-nonwritable-on-purpose'); + fs.mkdirSync(tmpDir, { recursive: true }); + fs.chmodSync(tmpDir, 0o500); + oldDir = process.cwd(); + process.chdir(tmpDir); + tmpDir = process.cwd(); // This will have resolved symlinks +}); + +const reverseAfterAll: Array = []; + +/** + * We need a cleanup here + * + * 99% of the time, Jest runs the tests in a subprocess and this isn't + * necessary because we would have `chdir`ed in the subprocess. + * + * But sometimes we ask Jest with `-i` to run the tests in the main process, + * or if you only ask for a single test suite Jest runs the tests in the main + * process, and then we `chdir`ed the main process away. + * + * Jest will then try to write the `coverage` directory to the readonly directory, + * and fail. Chdir back to the original dir. + * + * If the test file has an `afterAll()` hook it installed as well, we need to run + * it before our cleanup, otherwise the wrong thing will happen (by default, + * all `afterAll()`s run in call order, but they should be run in reverse). + */ +afterAll(async () => { + for (const aft of reverseAfterAll.reverse()) { + await new Promise((resolve, reject) => { + const response = aft(resolve as any); + if (isPromise(response)) { + response.then(() => { + return resolve(); + }, reject); + } else { + resolve(); + } + }); + } + + if (process.cwd() === tmpDir) { + process.chdir(oldDir); + } +}); + +// Patch afterAll to make later-provided afterAll's run before us (in reverse order even). +afterAll = (after: jest.ProvidesHookCallback) => { + reverseAfterAll.push(after); +}; diff --git a/packages/@aws-cdk/toolkit-lib/test/_helpers/test-io-host.ts b/packages/@aws-cdk/toolkit-lib/test/_helpers/test-io-host.ts new file mode 100644 index 000000000..c0b1df0ad --- /dev/null +++ b/packages/@aws-cdk/toolkit-lib/test/_helpers/test-io-host.ts @@ -0,0 +1,62 @@ +import type { IIoHost, IoMessage, IoMessageLevel, IoRequest } from '../../lib/api/io'; +import { asIoHelper, isMessageRelevantForLevel, type IoHelper } from '../../lib/api/shared-private'; +import { RequireApproval } from '../../lib/toolkit'; + +/** + * A test implementation of IIoHost that does nothing but can be spied on. + * + * Includes a level to filter out irrelevant messages, defaults to `info`. + * + * Optionally set an approval level for code `CDK_TOOLKIT_I5060`. + * + * # How to use + * + * Configure and reset the `notifySpy` and `requestSpy` members as you would any + * mock function. + */ +export class TestIoHost implements IIoHost { + public readonly notifySpy: jest.Mock; + public readonly requestSpy: jest.Mock; + + public requireDeployApproval = RequireApproval.NEVER; + + constructor(public level: IoMessageLevel = 'info') { + this.notifySpy = jest.fn(); + this.requestSpy = jest.fn(); + } + + public asHelper(action = 'synth'): IoHelper { + return asIoHelper(this, action as any); + } + + public async notify(msg: IoMessage): Promise { + if (isMessageRelevantForLevel(msg, this.level)) { + this.notifySpy(msg); + } + } + + public async requestResponse(msg: IoRequest): Promise { + if (isMessageRelevantForLevel(msg, this.level) && this.needsApproval(msg)) { + this.requestSpy(msg); + } + return msg.defaultResponse; + } + + private needsApproval(msg: IoRequest): boolean { + // Return true if the code is unrelated to approval + if (!['CDK_TOOLKIT_I5060'].includes(msg.code)) { + return true; + } + + switch (this.requireDeployApproval) { + case RequireApproval.NEVER: + return false; + case RequireApproval.ANY_CHANGE: + return true; + case RequireApproval.BROADENING: + return msg.data?.permissionChangeType === 'broadening'; + default: + return true; + } + } +} diff --git a/packages/@aws-cdk/toolkit-lib/test/actions/bootstrap.test.ts b/packages/@aws-cdk/toolkit-lib/test/actions/bootstrap.test.ts index f89a477b9..a3aa70253 100644 --- a/packages/@aws-cdk/toolkit-lib/test/actions/bootstrap.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/actions/bootstrap.test.ts @@ -34,10 +34,14 @@ beforeEach(() => { restoreSdkMocksToDefault(); setDefaultSTSMocks(); ioHost.notifySpy.mockClear(); + + mockSdkProvider.forEnvironment = jest.fn().mockImplementation(() => { + return { sdk: new MockSdk() }; + }); }); afterEach(() => { - jest.resetAllMocks(); + jest.clearAllMocks(); }); function setupMockCloudFormationClient(mockStack: Stack) { @@ -111,20 +115,8 @@ function expectSuccessfulBootstrap() { describe('bootstrap', () => { describe('with user-specified environments', () => { - const originalSdk = mockSdkProvider.forEnvironment.bind(mockSdkProvider); - beforeEach(() => { - const mockForEnvironment = jest.fn().mockImplementation(() => { - return { sdk: new MockSdk() }; - }); - mockSdkProvider.forEnvironment = mockForEnvironment; - }); - - afterAll(() => { - mockSdkProvider.forEnvironment = originalSdk; - }); - test('bootstraps specified environments', async () => { - // GIVEN + // GIVEN const mockStack1 = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'BUCKET_NAME_1' }, { OutputKey: 'BucketDomainName', OutputValue: 'BUCKET_ENDPOINT_1' }, @@ -177,7 +169,7 @@ describe('bootstrap', () => { }); test('handles errors in user-specified environments', async () => { - // GIVEN + // GIVEN const error = new Error('Access Denied'); error.name = 'AccessDeniedException'; mockCloudFormationClient @@ -198,7 +190,7 @@ describe('bootstrap', () => { }); test('throws error for invalid environment format', async () => { - // WHEN/THEN + // WHEN/THEN await expect(runBootstrap({ environments: ['invalid-format'] })) .rejects.toThrow('Expected environment name in format \'aws:///\', got: invalid-format'); }); @@ -206,7 +198,7 @@ describe('bootstrap', () => { describe('bootstrap parameters', () => { test('bootstrap with default parameters', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'BUCKET_NAME' }, { OutputKey: 'BucketDomainName', OutputValue: 'BUCKET_ENDPOINT' }, @@ -248,7 +240,7 @@ describe('bootstrap', () => { }); test('bootstrap with exact parameters', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'CUSTOM_BUCKET' }, { OutputKey: 'BucketDomainName', OutputValue: 'CUSTOM_ENDPOINT' }, @@ -288,7 +280,7 @@ describe('bootstrap', () => { }); test('bootstrap with additional parameters', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'EXISTING_BUCKET' }, { OutputKey: 'BucketDomainName', OutputValue: 'EXISTING_ENDPOINT' }, @@ -328,7 +320,7 @@ describe('bootstrap', () => { }); test('bootstrap with only existing parameters', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'EXISTING_BUCKET' }, { OutputKey: 'BucketDomainName', OutputValue: 'EXISTING_ENDPOINT' }, @@ -374,7 +366,7 @@ describe('bootstrap', () => { describe('template sources', () => { test('uses default template when no source is specified', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'BUCKET_NAME' }, { OutputKey: 'BucketDomainName', OutputValue: 'BUCKET_ENDPOINT' }, @@ -390,7 +382,7 @@ describe('bootstrap', () => { }); test('uses custom template when specified', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'BUCKET_NAME' }, { OutputKey: 'BucketDomainName', OutputValue: 'BUCKET_ENDPOINT' }, @@ -410,7 +402,7 @@ describe('bootstrap', () => { }); test('handles errors with custom template', async () => { - // GIVEN + // GIVEN const templateError = new Error('Invalid template file'); mockCloudFormationClient .on(DescribeStacksCommand) @@ -430,7 +422,7 @@ describe('bootstrap', () => { }); test('bootstrap handles no-op scenarios', async () => { - // GIVEN + // GIVEN const mockExistingStack = { StackId: 'mock-stack-id', StackName: 'CDKToolkit', @@ -488,7 +480,7 @@ describe('bootstrap', () => { describe('error handling', () => { test('returns correct BootstrapResult for successful bootstraps', async () => { - // GIVEN + // GIVEN const mockStack = createMockStack([ { OutputKey: 'BucketName', OutputValue: 'BUCKET_NAME' }, { OutputKey: 'BucketDomainName', OutputValue: 'BUCKET_ENDPOINT' }, @@ -508,7 +500,7 @@ describe('bootstrap', () => { }); test('returns correct BootstrapResult for no-op scenarios', async () => { - // GIVEN + // GIVEN const mockExistingStack = { StackId: 'mock-stack-id', StackName: 'CDKToolkit', @@ -546,7 +538,7 @@ describe('bootstrap', () => { }); test('returns correct BootstrapResult for failure', async () => { - // GIVEN + // GIVEN const error = new Error('Access Denied'); error.name = 'AccessDeniedException'; mockCloudFormationClient @@ -563,7 +555,7 @@ describe('bootstrap', () => { }); test('handles generic bootstrap errors', async () => { - // GIVEN + // GIVEN const error = new Error('Bootstrap failed'); mockCloudFormationClient .on(DescribeStacksCommand) @@ -579,7 +571,7 @@ describe('bootstrap', () => { }); test('handles permission errors', async () => { - // GIVEN + // GIVEN const error = new Error('Access Denied'); error.name = 'AccessDeniedException'; mockCloudFormationClient diff --git a/packages/@aws-cdk/toolkit-lib/test/util/aws-cdk.ts b/packages/@aws-cdk/toolkit-lib/test/util/aws-cdk.ts index d7020bad6..7500157ca 100644 --- a/packages/@aws-cdk/toolkit-lib/test/util/aws-cdk.ts +++ b/packages/@aws-cdk/toolkit-lib/test/util/aws-cdk.ts @@ -9,4 +9,4 @@ export { mockSTSClient, setDefaultSTSMocks, restoreSdkMocksToDefault, -} from '../../../../aws-cdk/test/util/mock-sdk'; +} from '../../../../aws-cdk/test/_helpers/mock-sdk'; diff --git a/packages/aws-cdk/.eslintrc.json b/packages/aws-cdk/.eslintrc.json index 3b7564c00..06b0316ff 100644 --- a/packages/aws-cdk/.eslintrc.json +++ b/packages/aws-cdk/.eslintrc.json @@ -313,9 +313,7 @@ "prettier/prettier": [ "off" ], - "@cdklabs/no-throw-default-error": [ - "error" - ] + "@cdklabs/no-throw-default-error": "error" }, "overrides": [ { diff --git a/packages/aws-cdk/jest.config.json b/packages/aws-cdk/jest.config.json index be8b208ed..eb826d6b6 100644 --- a/packages/aws-cdk/jest.config.json +++ b/packages/aws-cdk/jest.config.json @@ -36,9 +36,9 @@ ".warnings.jsii.js$", "/node_modules/", "/lib/api/aws-auth/sdk.ts", - "/lib/parse-command-line-arguments.ts", - "/lib/user-input.ts", - "/lib/convert-to-user-input.ts" + "/lib/cli/parse-command-line-arguments.ts", + "/lib/cli/user-input.ts", + "/lib/cli/convert-to-user-input.ts" ], "reporters": [ "default", diff --git a/packages/aws-cdk/test/cloud-assembly-trees/built-with-1_144_0/tree.json b/packages/aws-cdk/test/_fixtures/cloud-assembly-trees/built-with-1_144_0/tree.json similarity index 100% rename from packages/aws-cdk/test/cloud-assembly-trees/built-with-1_144_0/tree.json rename to packages/aws-cdk/test/_fixtures/cloud-assembly-trees/built-with-1_144_0/tree.json diff --git a/packages/aws-cdk/test/cloud-assembly-trees/built-with-2_12_0/tree.json b/packages/aws-cdk/test/_fixtures/cloud-assembly-trees/built-with-2_12_0/tree.json similarity index 100% rename from packages/aws-cdk/test/cloud-assembly-trees/built-with-2_12_0/tree.json rename to packages/aws-cdk/test/_fixtures/cloud-assembly-trees/built-with-2_12_0/tree.json diff --git a/packages/aws-cdk/test/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json b/packages/aws-cdk/test/_fixtures/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json similarity index 100% rename from packages/aws-cdk/test/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json rename to packages/aws-cdk/test/_fixtures/cloud-assembly-trees/experimental-module-pre-release-semver/tree.json diff --git a/packages/aws-cdk/test/cloud-assembly-trees/experimental-module/tree.json b/packages/aws-cdk/test/_fixtures/cloud-assembly-trees/experimental-module/tree.json similarity index 100% rename from packages/aws-cdk/test/cloud-assembly-trees/experimental-module/tree.json rename to packages/aws-cdk/test/_fixtures/cloud-assembly-trees/experimental-module/tree.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack-with-asset-parameters.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-one-stack-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack-with-asset-parameters.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack-with-dependency-on-sibling-stack-output.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-lambda-version-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-version-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-lambda-version-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-lambda-version-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-output-one-param-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-output-one-param-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-output-one-param-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-output-one-param-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-output-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-output-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-output-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-output-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-resource-one-stack-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-one-stack-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-resource-one-stack-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-one-stack-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-resource-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-resource-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-resource-two-stacks-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-stack-with-two-nested-stacks-stack.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-unnamed-lambda-stack.nested.template.json diff --git a/packages/aws-cdk/test/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json b/packages/aws-cdk/test/_fixtures/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json similarity index 100% rename from packages/aws-cdk/test/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json rename to packages/aws-cdk/test/_fixtures/nested-stack-templates/one-unnamed-lambda-two-stacks-stack.nested.template.json diff --git a/packages/aws-cdk/test/_helpers/assembly.ts b/packages/aws-cdk/test/_helpers/assembly.ts index a4b5fc55f..4d9f93a9c 100644 --- a/packages/aws-cdk/test/_helpers/assembly.ts +++ b/packages/aws-cdk/test/_helpers/assembly.ts @@ -3,11 +3,12 @@ import * as path from 'path'; import { ArtifactMetadataEntryType, ArtifactType, type AssetManifest, type AssetMetadataEntry, type AwsCloudFormationStackProperties, type MetadataEntry, type MissingContext } from '@aws-cdk/cloud-assembly-schema'; import { type CloudAssembly, CloudAssemblyBuilder, type CloudFormationStackArtifact, type StackMetadata } from '@aws-cdk/cx-api'; import { cxapiAssemblyWithForcedVersion } from '../api/cxapp/assembly-versions'; -import { MockSdkProvider } from '../util/mock-sdk'; +import { MockSdkProvider } from '../_helpers/mock-sdk'; import { CloudExecutable } from '../../lib/api/cxapp/cloud-executable'; import { Configuration } from '../../lib/cli/user-configuration'; -import { asIoHelper, TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from './io-host'; import { IIoHost } from '../../lib/cli/io-host'; +import { asIoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; export const DEFAULT_FAKE_TEMPLATE = { No: 'Resources' }; @@ -118,7 +119,7 @@ function addNestedStacks(templatePath: string, outdir: string, rootStackTemplate if (!template) { const templatePathWithDir = path.join('nested-stack-templates', templatePath); - template = JSON.parse(fs.readFileSync(path.join(__dirname, '..', templatePathWithDir)).toString()); + template = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '_fixtures', templatePathWithDir)).toString()); fs.writeFileSync(path.join(outdir, templatePath), JSON.stringify(template, undefined, 2)); } diff --git a/packages/aws-cdk/test/_helpers/fake-io-host.ts b/packages/aws-cdk/test/_helpers/fake-io-host.ts new file mode 100644 index 000000000..27eaeebfd --- /dev/null +++ b/packages/aws-cdk/test/_helpers/fake-io-host.ts @@ -0,0 +1,42 @@ +import { IIoHost, IoMessage, IoMessageLevel, IoRequest } from "../../../@aws-cdk/tmp-toolkit-helpers/src/api/io"; + +/** + * An implementation of `IIoHost` that records messages and lets you assert on what was logged + * + * It's like `TestIoHost`, but comes with a predefined implementation for `notify` + * that appends all messages to an in-memory array, and comes with a helper function + * `expectMessage()` to test for the existence of a function in that array. + * + * Has a public mock for `requestResponse` that you configure like any + * other mock function. + * + * # How to use + * + * Either create a new instance of this class for every test, or call `clear()` + * on it between runs. + */ +export class FakeIoHost implements IIoHost { + public messages: Array> = []; + public requestResponse!: (msg: IoRequest) => Promise; + + constructor() { + this.clear(); + } + + public clear() { + this.messages.splice(0, this.messages.length); + this.requestResponse = jest.fn().mockRejectedValue(new Error('requestResponse not mocked')); + } + + public async notify(msg: IoMessage): Promise { + this.messages.push(msg); + } + + public expectMessage(m: { containing: string; level?: IoMessageLevel }) { + expect(this.messages).toContainEqual(expect.objectContaining({ + ...m.level ? { level: m.level } : undefined, + // Can be a partial string as well + message: expect.stringContaining(m.containing), + })); + } +} diff --git a/packages/aws-cdk/test/_helpers/io-host.ts b/packages/aws-cdk/test/_helpers/io-host.ts new file mode 100644 index 000000000..079d0b98f --- /dev/null +++ b/packages/aws-cdk/test/_helpers/io-host.ts @@ -0,0 +1,41 @@ +import { type IIoHost, type IoMessage, type IoMessageLevel, type IoRequest } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io'; +import { asIoHelper, isMessageRelevantForLevel, type IoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; + +/** + * A test implementation of IIoHost that does nothing but can be spied on. + * + * Includes a level to filter out irrelevant messages, defaults to `info`. + * + * Optionally set an approval level for code `CDK_TOOLKIT_I5060`. + * + * # How to use + * + * Configure and reset the `notifySpy` and `requestSpy` members as you would any + * mock function. + */ +export class TestIoHost implements IIoHost { + public readonly notifySpy: jest.Mock; + public readonly requestSpy: jest.Mock; + + constructor(public level: IoMessageLevel = 'info') { + this.notifySpy = jest.fn(); + this.requestSpy = jest.fn(); + } + + public asHelper(action = 'synth'): IoHelper { + return asIoHelper(this, action as any); + } + + public async notify(msg: IoMessage): Promise { + if (isMessageRelevantForLevel(msg, this.level)) { + this.notifySpy(msg); + } + } + + public async requestResponse(msg: IoRequest): Promise { + if (isMessageRelevantForLevel(msg, this.level)) { + this.requestSpy(msg); + } + return msg.defaultResponse; + } +} diff --git a/packages/aws-cdk/test/util/mock-sdk.ts b/packages/aws-cdk/test/_helpers/mock-sdk.ts similarity index 98% rename from packages/aws-cdk/test/util/mock-sdk.ts rename to packages/aws-cdk/test/_helpers/mock-sdk.ts index 904d56ace..1d5bb569d 100644 --- a/packages/aws-cdk/test/util/mock-sdk.ts +++ b/packages/aws-cdk/test/_helpers/mock-sdk.ts @@ -24,7 +24,7 @@ import { mockClient } from 'aws-sdk-client-mock'; import { type Account } from 'cdk-assets'; import { SDK, SdkProvider } from '../../lib/api/aws-auth'; import { CloudFormationStack } from '../../lib/api/cloudformation'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from './io-host'; export const FAKE_CREDENTIALS: AwsCredentialIdentity = { accessKeyId: 'ACCESS', diff --git a/packages/aws-cdk/test/util/mock-toolkitinfo.ts b/packages/aws-cdk/test/_helpers/mock-toolkitinfo.ts similarity index 96% rename from packages/aws-cdk/test/util/mock-toolkitinfo.ts rename to packages/aws-cdk/test/_helpers/mock-toolkitinfo.ts index dd0561fe5..40650059f 100644 --- a/packages/aws-cdk/test/util/mock-toolkitinfo.ts +++ b/packages/aws-cdk/test/_helpers/mock-toolkitinfo.ts @@ -1,6 +1,6 @@ /* eslint-disable import/order */ import { ToolkitInfo, DEFAULT_BOOTSTRAP_VARIANT } from '../../lib/api'; -import { CloudFormationStack } from '../../lib/api/deployments'; +import { CloudFormationStack } from '../../lib/api/cloudformation'; export interface MockToolkitInfoProps { readonly bucketName?: string; diff --git a/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts b/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts index 9c542d023..7a5d91c44 100644 --- a/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts +++ b/packages/aws-cdk/test/api/_helpers/fake-cloudformation-stack.ts @@ -1,7 +1,7 @@ import { ICloudFormationClient } from '../../../lib/api'; import { CloudFormationStack, Template } from '../../../lib/api/cloudformation'; import { StackStatus } from '../../../lib/api/stack-events'; -import { MockSdk } from '../../util/mock-sdk'; +import { MockSdk } from '../../_helpers/mock-sdk'; export interface FakeCloudFormationStackProps { readonly stackName: string; diff --git a/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts b/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts index 4f8e9b107..a3397213a 100644 --- a/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts +++ b/packages/aws-cdk/test/api/_helpers/hotswap-test-setup.ts @@ -11,10 +11,10 @@ import { MockSdkProvider, restoreSdkMocksToDefault, setDefaultSTSMocks, -} from '../../util/mock-sdk'; +} from '../../_helpers/mock-sdk'; import { FakeCloudformationStack } from './fake-cloudformation-stack'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; import { CloudFormationStack, Template } from '../../../lib/api/cloudformation'; +import { TestIoHost } from '../../_helpers/io-host'; const STACK_NAME = 'withouterrors'; export const STACK_ID = 'stackId'; @@ -145,6 +145,6 @@ export class HotswapMockSdkProvider extends MockSdkProvider { hotswapPropertyOverrides?: HotswapPropertyOverrides, ): Promise { let hotswapProps = hotswapPropertyOverrides || new HotswapPropertyOverrides(); - return deployments.tryHotswapDeployment(this, asIoHelper(ioHost, 'deploy'), assetParams, currentCfnStack, stackArtifact, hotswapMode as any, hotswapProps); + return deployments.tryHotswapDeployment(this, ioHost.asHelper('deploy'), assetParams, currentCfnStack, stackArtifact, hotswapMode as any, hotswapProps); } } diff --git a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts b/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts index a1846cd1f..7a3b69911 100644 --- a/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/account-cache.test.ts @@ -4,7 +4,8 @@ import * as fs from 'fs-extra'; import { AccountAccessKeyCache } from '../../../lib/api/aws-auth/account-cache'; import { withMocked } from '../../_helpers/as-mock'; -const noOp = async () => {}; +const noOp = async () => { +}; async function makeCache() { const dir = await fs.mkdtemp('/tmp/account-cache-test'); @@ -86,7 +87,6 @@ test('fetch(k, resolver) can be used to "atomically" get + resolve + put', async }); test(`cache is nuked if it exceeds ${AccountAccessKeyCache.MAX_ENTRIES} entries`, async () => { - const { cacheDir, cacheFile, cache } = await makeCache(); try { @@ -127,7 +127,6 @@ test('cache pretends to be empty if cache file does not contain JSON', async() = }); describe('using cache file', () => { - afterAll(() => { bockfs.restore(); }); @@ -163,5 +162,4 @@ describe('using cache file', () => { expect(result).toEqual(account); }); - }); diff --git a/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts b/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts index 588a2fa14..9168f3226 100644 --- a/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/awscli-compatible.test.ts @@ -2,15 +2,13 @@ import * as os from 'os'; import * as path from 'path'; import * as fs from 'fs-extra'; import { AwsCliCompatible } from '../../../lib/api/aws-auth/awscli-compatible'; -import { TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; const ioHost = new TestIoHost(); const ioHelper = ioHost.asHelper('sdk'); describe('AwsCliCompatible.region', () => { - beforeEach(() => { - // make sure we don't mistakenly point to an unrelated file process.env.AWS_CONFIG_FILE = '/dev/null'; process.env.AWS_SHARED_CREDENTIALS_FILE = '/dev/null'; @@ -21,11 +19,9 @@ describe('AwsCliCompatible.region', () => { delete process.env.AMAZON_REGION; delete process.env.AWS_DEFAULT_REGION; delete process.env.AMAZON_DEFAULT_REGION; - }); test('default region can be specified in config', async () => { - const config = ` [default] region=region-in-config @@ -35,40 +31,33 @@ describe('AwsCliCompatible.region', () => { }); test('default region can be specified in credentials', async () => { - const creds = ` [default] region=region-in-credentials `; await expect(region({ credentialsFile: creds })).resolves.toBe('region-in-credentials'); - }); test('profile region can be specified in config', async () => { - const config = ` [profile user1] region=region-in-config `; await expect(region({ configFile: config, profile: 'user1' })).resolves.toBe('region-in-config'); - }); test('profile region can be specified in credentials', async () => { - const creds = ` [user1] region=region-in-credentials `; await expect(region({ credentialsFile: creds, profile: 'user1' })).resolves.toBe('region-in-credentials'); - }); test('with profile | profile-region-in-credentials is priority 1', async () => { - const config = ` [default] region=default-region-in-config @@ -86,11 +75,12 @@ describe('AwsCliCompatible.region', () => { region=profile-region-in-credentials `; - await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe('profile-region-in-credentials'); + await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe( + 'profile-region-in-credentials', + ); }); test('with profile | profile-region-in-config is priority 2', async () => { - const config = ` [default] region=default-region-in-config @@ -107,11 +97,12 @@ describe('AwsCliCompatible.region', () => { [user] `; - await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe('profile-region-in-config'); + await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe( + 'profile-region-in-config', + ); }); test('with profile | default-region-in-credentials is priority 3', async () => { - const config = ` [default] region=default-region-in-config @@ -127,11 +118,12 @@ describe('AwsCliCompatible.region', () => { [user] `; - await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe('default-region-in-credentials'); + await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe( + 'default-region-in-credentials', + ); }); test('with profile | default-region-in-config is priority 4', async () => { - const config = ` [default] region=default-region-in-config @@ -146,11 +138,12 @@ describe('AwsCliCompatible.region', () => { [user] `; - await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe('default-region-in-config'); + await expect(region({ credentialsFile: creds, configFile: config, profile: 'user' })).resolves.toBe( + 'default-region-in-config', + ); }); test('with profile | us-east-1 is priority 5', async () => { - const config = ` [default] @@ -168,7 +161,6 @@ describe('AwsCliCompatible.region', () => { }); test('without profile | default-region-in-credentials is priority 1', async () => { - const config = ` [default] region=default-region-in-config @@ -185,7 +177,6 @@ describe('AwsCliCompatible.region', () => { }); test('without profile | default-region-in-config is priority 2', async () => { - const config = ` [default] region=default-region-in-config @@ -201,7 +192,6 @@ describe('AwsCliCompatible.region', () => { }); test('without profile | us-east-1 is priority 3', async () => { - const config = ` [default] @@ -214,7 +204,6 @@ describe('AwsCliCompatible.region', () => { await expect(region({ credentialsFile: creds, configFile: config })).resolves.toBe('us-east-1'); }); - }); async function region(opts: { @@ -222,11 +211,9 @@ async function region(opts: { readonly credentialsFile?: string; readonly profile?: string; }) { - const workdir = fs.mkdtempSync(path.join(os.tmpdir(), 'awscli-compatible.test')); try { - if (opts.configFile) { const configPath = path.join(workdir, 'config'); fs.writeFileSync(configPath, opts.configFile); @@ -240,7 +227,6 @@ async function region(opts: { } return await new AwsCliCompatible(ioHelper).region(opts.profile); - } finally { fs.removeSync(workdir); } diff --git a/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts b/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts index a30329435..124272f95 100644 --- a/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/credential-plugins.test.ts @@ -2,7 +2,7 @@ import type { PluginProviderResult, SDKv2CompatibleCredentials } from '@aws-cdk/ import { CredentialPlugins } from '../../../lib/api/aws-auth/credential-plugins'; import { PluginHost } from '../../../lib/api/plugin'; import { Mode } from '../../../lib/api/plugin/mode'; -import { TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; const ioHost = new TestIoHost(); const ioHelper = ioHost.asHelper('deploy'); diff --git a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts b/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts index e2ad6da56..dbaad36c4 100644 --- a/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts +++ b/packages/aws-cdk/test/api/aws-auth/sdk-provider.test.ts @@ -25,8 +25,8 @@ import { defaultCliUserAgent } from '../../../lib/api/aws-auth/user-agent'; import { PluginHost } from '../../../lib/api/plugin'; import { Mode } from '../../../lib/api/plugin/mode'; import { instanceMockFrom, withMocked } from '../../_helpers/as-mock'; -import { undoAllSdkMocks } from '../../util/mock-sdk'; -import { TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { undoAllSdkMocks } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; // As part of the imports above we import `mock-sdk.ts` which automatically mocks // all SDK clients. We don't want that for this test suite, so undo it. diff --git a/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts b/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts index 48e54c7d2..3d2895c48 100644 --- a/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts +++ b/packages/aws-cdk/test/api/bootstrap/bootstrap.test.ts @@ -13,8 +13,8 @@ import { parse } from 'yaml'; import { Bootstrapper } from '../../../lib/api/bootstrap'; import { legacyBootstrapTemplate } from '../../../lib/api/bootstrap/legacy-template'; import { deserializeStructure, serializeStructure, toYAML } from '../../../lib/util'; -import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../util/mock-sdk'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; const env = { account: '123456789012', @@ -32,7 +32,7 @@ let sdk: MockSdkProvider; let changeSetTemplate: any | undefined; let bootstrapper: Bootstrapper; let ioHost = new TestIoHost(); -let ioHelper = asIoHelper(ioHost, 'bootstrap'); +let ioHelper = ioHost.asHelper('bootstrap'); beforeEach(() => { sdk = new MockSdkProvider(); diff --git a/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts b/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts index 088fea5ea..12fee5662 100644 --- a/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts +++ b/packages/aws-cdk/test/api/bootstrap/bootstrap2.test.ts @@ -9,7 +9,7 @@ import { mockIAMClient, MockSdkProvider, restoreSdkMocksToDefault, setDefaultSTSMocks, -} from '../../util/mock-sdk'; +} from '../../_helpers/mock-sdk'; import { IIoHost } from '../../../lib/cli/io-host'; import { asIoHelper } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; @@ -23,7 +23,7 @@ let ioHost: IIoHost = { }), requestResponse: jest.fn().mockImplementation((msg) => { process.stderr.write(msg.message + '\n'); - return msg.defaultResponses + return msg.defaultResponses; }), }; let ioHelper = asIoHelper(ioHost, 'bootstrap'); diff --git a/packages/aws-cdk/test/api/cxapp/exec.test.ts b/packages/aws-cdk/test/api/cxapp/exec.test.ts index e943dfad0..d06c0df43 100644 --- a/packages/aws-cdk/test/api/cxapp/exec.test.ts +++ b/packages/aws-cdk/test/api/cxapp/exec.test.ts @@ -9,16 +9,16 @@ import { execProgram } from '../../../lib/api/cxapp/exec'; import { Configuration } from '../../../lib/cli/user-configuration'; import { testAssembly } from '../../_helpers/assembly'; import { mockSpawn } from '../../util/mock-child_process'; -import { MockSdkProvider } from '../../util/mock-sdk'; +import { MockSdkProvider } from '../../_helpers/mock-sdk'; import { RWLock } from '../../../lib/api/util/rwlock'; import { rewriteManifestMinimumCliVersion, rewriteManifestVersion } from './assembly-versions'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; import { ToolkitError } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api'; let sdkProvider: MockSdkProvider; let config: Configuration; const ioHost = new TestIoHost(); -const ioHelper = asIoHelper(ioHost, 'synth'); +const ioHelper = ioHost.asHelper('synth'); beforeEach(() => { ioHost.notifySpy.mockClear(); diff --git a/packages/aws-cdk/test/api/deployments/assets.test.ts b/packages/aws-cdk/test/api/deployments/assets.test.ts index 203574e11..61e5b3d62 100644 --- a/packages/aws-cdk/test/api/deployments/assets.test.ts +++ b/packages/aws-cdk/test/api/deployments/assets.test.ts @@ -4,16 +4,16 @@ import { testStack, withMocked } from '../../_helpers'; import { addMetadataAssetsToManifest } from '../../../lib/api/deployments/assets'; import { AssetManifestBuilder } from '../../../lib/api/deployments'; import { EnvironmentResources, EnvironmentResourcesRegistry } from '../../../lib/api/environment'; -import { MockSdk } from '../../util/mock-sdk'; -import { MockToolkitInfo } from '../../util/mock-toolkitinfo'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { MockSdk } from '../../_helpers/mock-sdk'; +import { MockToolkitInfo } from '../../_helpers/mock-toolkitinfo'; +import { TestIoHost } from '../../_helpers/io-host'; let assets: AssetManifestBuilder; let envRegistry: EnvironmentResourcesRegistry; let envResources: EnvironmentResources; let toolkitMock: ReturnType; let ioHost = new TestIoHost(); -let ioHelper = asIoHelper(ioHost, 'deploy'); +let ioHelper = ioHost.asHelper('deploy'); beforeEach(() => { ioHost.notifySpy.mockClear(); diff --git a/packages/aws-cdk/test/api/deployments/checks.test.ts b/packages/aws-cdk/test/api/deployments/checks.test.ts index cf9390484..da1c28d38 100644 --- a/packages/aws-cdk/test/api/deployments/checks.test.ts +++ b/packages/aws-cdk/test/api/deployments/checks.test.ts @@ -1,9 +1,9 @@ import { DescribeStacksCommand, StackStatus } from '@aws-sdk/client-cloudformation'; import { determineAllowCrossAccountAssetPublishing, getBootstrapStackInfo } from '../../../lib/api/deployments/checks'; -import { mockCloudFormationClient, MockSdk } from '../../util/mock-sdk'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { mockCloudFormationClient, MockSdk } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; -let ioHelper = asIoHelper(new TestIoHost(), 'deploy'); +let ioHelper = new TestIoHost().asHelper('deploy'); describe('determineAllowCrossAccountAssetPublishing', () => { it('should return true when hasStagingBucket is false', async () => { diff --git a/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts b/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts index 232a31481..90e903c59 100644 --- a/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts +++ b/packages/aws-cdk/test/api/deployments/cloudformation-deployments.test.ts @@ -24,9 +24,9 @@ import { mockSSMClient, restoreSdkMocksToDefault, setDefaultSTSMocks, -} from '../../util/mock-sdk'; +} from '../../_helpers/mock-sdk'; import { FakeCloudformationStack } from '../_helpers/fake-cloudformation-stack'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; import { Deployments } from '../../../lib/api/deployments'; import { CloudFormationStack } from '../../../lib/api/cloudformation'; import { createChangeSet } from '../../../lib/api/deployments/cfn-api'; @@ -40,7 +40,7 @@ let deployments: Deployments; let mockToolkitInfoLookup: jest.Mock; let currentCfnStackResources: { [key: string]: StackResourceSummary[] }; let ioHost = new TestIoHost(); -let ioHelper = asIoHelper(ioHost, 'deploy'); +let ioHelper = ioHost.asHelper('deploy'); beforeEach(() => { jest.resetAllMocks(); @@ -1120,7 +1120,9 @@ describe('stackExists', () => { [false, 'deploy:here:123456789012'], [true, 'lookup:here:123456789012'], ])('uses lookup role if requested: %p', async (tryLookupRole, expectedRoleArn) => { - const mockForEnvironment = jest.fn().mockImplementation(() => { return { sdk: new MockSdk() }; }); + const mockForEnvironment = jest.fn().mockImplementation(() => { + return { sdk: new MockSdk() }; + }); sdkProvider.forEnvironment = mockForEnvironment; givenStacks({ '*': { template: {} }, diff --git a/packages/aws-cdk/test/api/deployments/cloudformation.test.ts b/packages/aws-cdk/test/api/deployments/cloudformation.test.ts index 0630fd5b7..ba0ce836f 100644 --- a/packages/aws-cdk/test/api/deployments/cloudformation.test.ts +++ b/packages/aws-cdk/test/api/deployments/cloudformation.test.ts @@ -1,6 +1,6 @@ import { SSMPARAM_NO_INVALIDATE } from '@aws-cdk/cx-api'; import { DescribeStacksCommand, GetTemplateCommand, StackStatus } from '@aws-sdk/client-cloudformation'; -import { MockSdk, mockCloudFormationClient } from '../../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient } from '../../_helpers/mock-sdk'; import type { ICloudFormationClient } from '../../../lib/api/aws-auth'; import { CloudFormationStack } from '../../../lib/api/cloudformation'; import { TemplateParameters } from '../../../lib/api/deployments/cfn-api'; diff --git a/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts b/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts index e217d6787..d771a02ec 100644 --- a/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts +++ b/packages/aws-cdk/test/api/deployments/deploy-stack.test.ts @@ -28,11 +28,11 @@ import { MockSdk, MockSdkProvider, restoreSdkMocksToDefault, -} from '../../util/mock-sdk'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +} from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; let ioHost = new TestIoHost(); -let ioHelper = asIoHelper(ioHost, 'deploy'); +let ioHelper = ioHost.asHelper('deploy'); function testDeployStack(options: DeployStackOptions) { return deployStack(options, ioHelper); @@ -902,7 +902,7 @@ test('empty change set is deleted if --execute is given', async () => { expect(mockCloudFormationClient).toHaveReceivedCommand(CreateChangeSetCommand); expect(mockCloudFormationClient).not.toHaveReceivedCommand(ExecuteChangeSetCommand); - //the first deletion is for any existing cdk change sets, the second is for the deleting the new empty change set + // the first deletion is for any existing cdk change sets, the second is for the deleting the new empty change set expect(mockCloudFormationClient).toHaveReceivedCommandTimes(DeleteChangeSetCommand, 2); }); @@ -927,7 +927,7 @@ test('empty change set is not deleted if --no-execute is given', async () => { expect(mockCloudFormationClient).toHaveReceivedCommand(CreateChangeSetCommand); expect(mockCloudFormationClient).not.toHaveReceivedCommand(ExecuteChangeSetCommand); - //the first deletion is for any existing cdk change sets + // the first deletion is for any existing cdk change sets expect(mockCloudFormationClient).toHaveReceivedCommandTimes(DeleteChangeSetCommand, 1); }); diff --git a/packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts b/packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts index 2842e7aa5..3078eb734 100644 --- a/packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/deployments/hotswap-deployments.test.ts @@ -3,8 +3,8 @@ import { UpdateFunctionCodeCommand } from '@aws-sdk/client-lambda'; import { UpdateStateMachineCommand } from '@aws-sdk/client-sfn'; import { CfnEvaluationException } from '../../../lib/api/cloudformation'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { MockSdk, mockCloudFormationClient, mockLambdaClient, mockStepFunctionsClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { MockSdk, mockCloudFormationClient, mockLambdaClient, mockStepFunctionsClient } from '../../_helpers/mock-sdk'; + import * as setup from '../_helpers/hotswap-test-setup'; jest.mock('@aws-sdk/client-lambda', () => { @@ -27,7 +27,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('returns a deployStackResult with noOp=true when it receives an empty set of changes', async () => { + test('returns a deployStackResult with noOp=true when it receives an empty set of changes', async () => { // WHEN const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment( hotswapMode, @@ -40,7 +40,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot expect(deployStackResult?.stackArn).toEqual(setup.STACK_ID); }); - silentTest( + test( 'A change to only a non-hotswappable resource results in a full deployment for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { // GIVEN @@ -88,7 +88,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'A change to both a hotswappable resource and a non-hotswappable resource results in a full deployment for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { // GIVEN @@ -165,7 +165,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('changes only to CDK::Metadata result in a noOp', async () => { + test('changes only to CDK::Metadata result in a noOp', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -200,7 +200,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot expect(mockLambdaClient).not.toHaveReceivedCommand(UpdateFunctionCodeCommand); }); - silentTest('resource deletions require full deployments for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { + test('resource deletions require full deployments for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -231,7 +231,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot } }); - silentTest('can correctly reference AWS::Partition in hotswappable changes', async () => { + test('can correctly reference AWS::Partition in hotswappable changes', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -286,7 +286,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('can correctly reference AWS::URLSuffix in hotswappable changes', async () => { + test('can correctly reference AWS::URLSuffix in hotswappable changes', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -341,7 +341,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'changing the type of a deployed resource always results in a full deployment for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { // GIVEN @@ -394,7 +394,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'A change to both a hotswappable resource and a stack output results in a full deployment for HOTSWAP and a hotswap deployment for HOTSWAP_ONLY', async () => { // GIVEN @@ -469,7 +469,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('Multiple CfnEvaluationException will not cause unhandled rejections', async () => { + test('Multiple CfnEvaluationException will not cause unhandled rejections', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -555,7 +555,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot expect(mockLambdaClient).not.toHaveReceivedCommand(UpdateFunctionCodeCommand); }); - silentTest( + test( 'deleting a resource and making a hotswappable change results in full deployments for HOTSWAP and a hotswap deployment for HOTSWAP_ONLY', async () => { // GIVEN @@ -623,7 +623,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('can correctly reference Fn::ImportValue in hotswappable changes', async () => { + test('can correctly reference Fn::ImportValue in hotswappable changes', async () => { // GIVEN mockCloudFormationClient.on(ListExportsCommand).resolves({ Exports: [ diff --git a/packages/aws-cdk/test/api/environment/environment-resources.test.ts b/packages/aws-cdk/test/api/environment/environment-resources.test.ts index 855fca32c..7508934aa 100644 --- a/packages/aws-cdk/test/api/environment/environment-resources.test.ts +++ b/packages/aws-cdk/test/api/environment/environment-resources.test.ts @@ -4,9 +4,9 @@ import { Context } from '../../../lib/api/context'; import { EnvironmentResourcesRegistry } from '../../../lib/api/environment'; import * as version from '../../../lib/cli/version'; import { CachedDataSource, Notices, NoticesFilter } from '../../../lib/notices'; -import { MockSdk, mockBootstrapStack, mockSSMClient } from '../../util/mock-sdk'; -import { MockToolkitInfo } from '../../util/mock-toolkitinfo'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { MockSdk, mockBootstrapStack, mockSSMClient } from '../../_helpers/mock-sdk'; +import { MockToolkitInfo } from '../../_helpers/mock-toolkitinfo'; +import { TestIoHost } from '../../_helpers/io-host'; import { FakeIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private/testing/fake-io-host'; let mockSdk: MockSdk; @@ -14,7 +14,7 @@ let envRegistry: EnvironmentResourcesRegistry; let toolkitMock: ReturnType; let ioHost = new TestIoHost(); -let ioHelper = asIoHelper(ioHost, 'deploy'); +let ioHelper = ioHost.asHelper('deploy'); beforeEach(() => { mockSdk = new MockSdk(); diff --git a/packages/aws-cdk/test/api/evaluate-cloudformation-template.test.ts b/packages/aws-cdk/test/api/evaluate-cloudformation-template.test.ts index 3c881f4e4..a422e11f2 100644 --- a/packages/aws-cdk/test/api/evaluate-cloudformation-template.test.ts +++ b/packages/aws-cdk/test/api/evaluate-cloudformation-template.test.ts @@ -4,7 +4,7 @@ import { EvaluateCloudFormationTemplate, Template, } from '../../lib/api/cloudformation'; -import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; const sdk = new MockSdk(); diff --git a/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts b/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts index b2920431b..6a9491f8b 100644 --- a/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts +++ b/packages/aws-cdk/test/api/garbage-collection/garbage-collection.test.ts @@ -7,7 +7,7 @@ import { Stack, } from '@aws-sdk/client-cloudformation'; import { ECR_ISOLATED_TAG, GarbageCollector, S3_ISOLATED_TAG, ToolkitInfo } from '../../../lib/api'; -import { mockBootstrapStack, mockCloudFormationClient, mockECRClient, mockS3Client, MockSdk, MockSdkProvider } from '../../util/mock-sdk'; +import { mockBootstrapStack, mockCloudFormationClient, mockECRClient, mockS3Client, MockSdk, MockSdkProvider } from '../../_helpers/mock-sdk'; import { DeleteObjectsCommand, DeleteObjectTaggingCommand, @@ -28,7 +28,7 @@ import { ListImagesCommand, PutImageCommand, } from '@aws-sdk/client-ecr'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; let garbageCollector: GarbageCollector; @@ -73,7 +73,7 @@ function gc(props: { }): GarbageCollector { return new GarbageCollector({ sdkProvider: new MockSdkProvider(), - ioHelper: asIoHelper(ioHost, 'gc'), + ioHelper: ioHost.asHelper('gc'), action: props.action, resolvedEnvironment: { account: '123456789012', @@ -935,7 +935,7 @@ describe('BackgroundStackRefresh', () => { refreshProps = { cfn: foo.cloudFormation(), - ioHelper: asIoHelper(ioHost, 'gc'), + ioHelper: ioHost.asHelper('gc'), activeAssets: new ActiveAssetCache(), }; @@ -1020,7 +1020,7 @@ describe('ProgressPrinter', () => { setInterval = jest.spyOn(global, 'setInterval'); clearInterval = jest.spyOn(global, 'clearInterval'); - progressPrinter = new ProgressPrinter(asIoHelper(ioHost, 'gc'), 0, 1000); + progressPrinter = new ProgressPrinter(ioHost.asHelper('gc'), 0, 1000); }); afterEach(() => { diff --git a/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts index ddae8d7fd..f61696727 100644 --- a/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/appsync-mapping-templates-hotswap-deployments.test.ts @@ -11,8 +11,8 @@ import { GetObjectCommand } from '@aws-sdk/client-s3'; import { sdkStreamMixin } from '@smithy/util-stream'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockAppSyncClient, mockS3Client } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockAppSyncClient, mockS3Client } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -29,7 +29,7 @@ const getBodyStream = (input: string) => { }; describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest( + test( `A new Resolver being added to the Stack returns undefined in CLASSIC mode and returns a noOp in HOTSWAP_ONLY mode`, async () => { @@ -60,7 +60,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateResolver() API when it receives only a mapping template difference in a Unit Resolver', async () => { // GIVEN @@ -129,7 +129,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateResolver() API when it receives only a mapping template difference s3 location in a Unit Resolver', async () => { // GIVEN @@ -206,7 +206,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateResolver() API when it receives only a code s3 location in a Pipeline Resolver', async () => { // GIVEN @@ -280,7 +280,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateResolver() API when it receives only a code difference in a Pipeline Resolver', async () => { // GIVEN @@ -346,7 +346,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateResolver() API when it receives only a mapping template difference in a Pipeline Resolver', async () => { // GIVEN @@ -417,7 +417,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `when it receives a change that is not a mapping template difference in a Resolver, it does not call the updateResolver() API in CLASSIC mode but does call the updateResolver() API in HOTSWAP_ONLY mode`, async () => { @@ -485,7 +485,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateResolver() API when a resource with type that is not AWS::AppSync::Resolver but has the same properties is changed', async () => { // GIVEN @@ -533,7 +533,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateFunction() API when it receives only a mapping template difference in a Function', async () => { // GIVEN @@ -597,7 +597,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateFunction() API with function version when it receives both function version and runtime with a mapping template in a Function', async () => { // GIVEN @@ -663,7 +663,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateFunction() API with runtime when it receives both function version and runtime with code in a Function', async () => { // GIVEN @@ -726,7 +726,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateFunction() API when it receives only a mapping template s3 location difference in a Function', async () => { // GIVEN @@ -797,7 +797,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `when it receives a change that is not a mapping template difference in a Function, it does not call the updateFunction() API in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { @@ -861,7 +861,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateFunction() API when a resource with type that is not AWS::AppSync::FunctionConfiguration but has the same properties is changed', async () => { // GIVEN @@ -911,7 +911,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the startSchemaCreation() API when it receives only a definition difference in a graphql schema', async () => { // GIVEN @@ -969,7 +969,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'updateFunction() API recovers from failed update attempt through retry logic', async () => { @@ -1044,7 +1044,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'updateFunction() API fails if it recieves 7 failed attempts in a row', async () => { // Ignore the wait times that the SDK tries to impose and always set timers for 1 ms @@ -1134,7 +1134,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot 320000, ); - silentTest('calls the updateFunction() API with functionId when function is listed on second page', async () => { + test('calls the updateFunction() API with functionId when function is listed on second page', async () => { // GIVEN mockAppSyncClient .on(ListFunctionsCommand) @@ -1209,7 +1209,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'calls the startSchemaCreation() API when it receives only a definition difference in a graphql schema', async () => { // GIVEN @@ -1264,7 +1264,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }, ); - silentTest( + test( 'calls the startSchemaCreation() API when it receives only a definition s3 location difference in a graphql schema', async () => { // GIVEN @@ -1326,7 +1326,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call startSchemaCreation() API when a resource with type that is not AWS::AppSync::GraphQLSchema but has the same properties is change', async () => { // GIVEN @@ -1383,7 +1383,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the startSchemaCreation() and waits for schema creation to stabilize before finishing', async () => { // GIVEN @@ -1442,7 +1442,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('calls the startSchemaCreation() and throws if schema creation fails', async () => { + test('calls the startSchemaCreation() and throws if schema creation fails', async () => { // GIVEN mockAppSyncClient.on(StartSchemaCreationCommand).resolvesOnce({ status: 'PROCESSING' }); mockAppSyncClient.on(GetSchemaCreationStatusCommand).resolvesOnce({ status: 'FAILED', details: 'invalid schema' }); @@ -1499,7 +1499,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'calls the updateApiKey() API when it receives only a expires property difference in an AppSync ApiKey', async () => { // GIVEN @@ -1556,7 +1556,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateApiKey() API when it receives only a expires property difference and no api-key-id in an AppSync ApiKey', async () => { // GIVEN diff --git a/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts index 371d1b76f..706b9aede 100644 --- a/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/code-build-projects-hotswap-deployments.test.ts @@ -1,8 +1,8 @@ import { UpdateProjectCommand } from '@aws-sdk/client-codebuild'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockCodeBuildClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockCodeBuildClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -11,7 +11,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('returns undefined when a new CodeBuild Project is added to the Stack', async () => { + test('returns undefined when a new CodeBuild Project is added to the Stack', async () => { // GIVEN const cdkStackArtifact = setup.cdkStackArtifactOf({ template: { @@ -41,7 +41,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot } }); - silentTest( + test( 'calls the updateProject() API when it receives only a source difference in a CodeBuild project', async () => { // GIVEN @@ -97,7 +97,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateProject() API when it receives only a source version difference in a CodeBuild project', async () => { // GIVEN @@ -152,7 +152,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateProject() API when it receives only an environment difference in a CodeBuild project', async () => { // GIVEN @@ -261,7 +261,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "correctly evaluates the project's name when it references a different resource from the template", async () => { // GIVEN @@ -328,7 +328,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "correctly falls back to taking the project's name from the current stack if it can't evaluate it in the template", async () => { // GIVEN @@ -397,7 +397,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it cannot find a Ref target (outside the project's name)", async () => { // GIVEN @@ -452,7 +452,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it doesn't know how to handle a specific attribute (outside the project's name)", async () => { // GIVEN @@ -508,7 +508,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateProject() API when it receives a difference in a CodeBuild project with no name', async () => { // GIVEN @@ -565,7 +565,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateProject() API when it receives a change that is not Source, SourceVersion, or Environment difference in a CodeBuild project', async () => { // GIVEN @@ -619,7 +619,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `when it receives a change that is not Source, SourceVersion, or Environment difference in a CodeBuild project alongside a hotswappable change, it does not call the updateProject() API in CLASSIC mode, but it does in HOTSWAP_ONLY mode`, async () => { @@ -681,7 +681,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot } }, ); - silentTest( + test( 'does not call the updateProject() API when a resource with type that is not AWS::CodeBuild::Project but has the same properties is changed', async () => { // GIVEN diff --git a/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts index 8ee2a4aac..12a6984dc 100644 --- a/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/ecs-services-hotswap-deployments.test.ts @@ -2,8 +2,8 @@ import { DescribeServicesCommand, RegisterTaskDefinitionCommand, UpdateServiceCo import * as setup from '../_helpers/hotswap-test-setup'; import { EcsHotswapProperties, HotswapMode, HotswapPropertyOverrides } from '../../../lib/api/hotswap/common'; import { Configuration } from '../../../lib/cli/user-configuration'; -import { mockECSClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockECSClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -33,7 +33,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest( + test( 'should call registerTaskDefinition and updateService for a difference only in the TaskDefinition with a Family property', async () => { // GIVEN @@ -108,7 +108,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'any other TaskDefinition property change besides ContainerDefinition cannot be hotswapped in CLASSIC mode but does not block HOTSWAP_ONLY mode deployments', async () => { // GIVEN @@ -195,7 +195,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'deleting any other TaskDefinition property besides ContainerDefinition results in a full deployment in CLASSIC mode and a hotswap deployment in HOTSWAP_ONLY mode', async () => { // GIVEN @@ -281,7 +281,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'should call registerTaskDefinition and updateService for a difference only in the TaskDefinition without a Family property', async () => { // GIVEN @@ -358,7 +358,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'a difference just in a TaskDefinition, without any services using it, is not hotswappable in FALL_BACK mode', async () => { // GIVEN @@ -421,7 +421,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'if anything besides an ECS Service references the changed TaskDefinition, hotswapping is not possible in CLASSIC mode but is possible in HOTSWAP_ONLY', async () => { // GIVEN @@ -525,7 +525,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('should call registerTaskDefinition with certain properties not lowercased', async () => { + test('should call registerTaskDefinition with certain properties not lowercased', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { diff --git a/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts b/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts index 4371c4ad0..27853dc9c 100644 --- a/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts +++ b/packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts @@ -1,7 +1,7 @@ import { StackStatus } from '@aws-sdk/client-cloudformation'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { silentTest } from '../../util/silent'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -10,7 +10,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest( + test( 'A change to an IAM Policy results in a full deployment for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { // GIVEN diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts index df4e5c23f..62fba5510 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts @@ -11,8 +11,8 @@ jest.mock('@aws-sdk/client-lambda', () => { import { UpdateFunctionCodeCommand, waitUntilFunctionUpdatedV2 } from '@aws-sdk/client-lambda'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -25,7 +25,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest( + test( 'calls the updateLambdaCode() API when it receives only a code difference in a Lambda function', async () => { // GIVEN @@ -76,7 +76,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('calls the waiter with a delay of 5', async () => { + test('calls the waiter with a delay of 5', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -127,7 +127,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot ); }); - silentTest( + test( 'throws error in case of timeout', async () => { // GIVEN diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts index 74906bf9c..8ffce7637 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/lambda-functions-hotswap-deployments.test.ts @@ -5,8 +5,8 @@ import { } from '@aws-sdk/client-lambda'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); @@ -23,7 +23,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('returns undefined when a new Lambda function is added to the Stack', async () => { + test('returns undefined when a new Lambda function is added to the Stack', async () => { // GIVEN const cdkStackArtifact = setup.cdkStackArtifactOf({ template: { @@ -52,7 +52,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot } }); - silentTest( + test( 'calls the updateLambdaCode() API when it receives only a code difference in a Lambda function', async () => { // GIVEN @@ -106,7 +106,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "correctly evaluates the function's name when it references a different resource from the template", async () => { // GIVEN @@ -171,7 +171,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "correctly falls back to taking the function's name from the current stack if it can't evaluate it in the template", async () => { // GIVEN @@ -236,7 +236,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it cannot find a Ref target (outside the function's name)", async () => { // GIVEN @@ -289,7 +289,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it doesn't know how to handle a specific attribute (outside the function's name)", async () => { // GIVEN @@ -345,7 +345,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateLambdaCode() API when it receives a code difference in a Lambda function with no name', async () => { // GIVEN @@ -400,7 +400,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateLambdaCode() API when it receives a change that is not a code difference in a Lambda function', async () => { // GIVEN @@ -454,7 +454,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `when it receives a non-hotswappable change that includes a code difference in a Lambda function, it does not call the updateLambdaCode() API in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { @@ -514,7 +514,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateLambdaCode() API when a resource with type that is not AWS::Lambda::Function but has the same properties is changed', async () => { // GIVEN @@ -572,7 +572,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('calls waiter after function code is updated with delay 1', async () => { + test('calls waiter after function code is updated with delay 1', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -626,7 +626,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot ); }); - silentTest('calls waiter after function code is updated and VpcId is empty string with delay 1', async () => { + test('calls waiter after function code is updated and VpcId is empty string with delay 1', async () => { // GIVEN mockLambdaClient.on(UpdateFunctionCodeCommand).resolves({ VpcConfig: { @@ -684,7 +684,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot ); }); - silentTest('calls getFunction() after function code is updated on a VPC function with delay 5', async () => { + test('calls getFunction() after function code is updated on a VPC function with delay 5', async () => { // GIVEN mockLambdaClient.on(UpdateFunctionCodeCommand).resolves({ VpcConfig: { @@ -742,7 +742,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot ); }); - silentTest( + test( 'calls the updateLambdaConfiguration() API when it receives difference in Description field of a Lambda function', async () => { // GIVEN @@ -797,7 +797,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateLambdaConfiguration() API when it receives difference in Environment field of a Lambda function', async () => { // GIVEN @@ -869,7 +869,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls both updateLambdaCode() and updateLambdaConfiguration() API when it receives both code and configuration change', async () => { // GIVEN @@ -929,7 +929,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'Lambda hotswap works properly with changes of environment variables and description with tokens', async () => { // GIVEN @@ -1021,7 +1021,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('S3ObjectVersion is hotswappable', async () => { + test('S3ObjectVersion is hotswappable', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { diff --git a/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts index 7adc4c007..e17208beb 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts @@ -2,8 +2,8 @@ import { UpdateFunctionCodeCommand } from '@aws-sdk/client-lambda'; import { Runtime } from 'aws-cdk-lib/aws-lambda'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); @@ -23,7 +23,7 @@ beforeEach(() => { describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])( 'these tests do not depend on the hotswap type', (hotswapMode) => { - silentTest( + test( 'calls the updateLambdaCode() API when it receives only a code difference in a Lambda function (Inline Node.js code)', async () => { // GIVEN @@ -71,7 +71,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])( }, ); - silentTest( + test( 'calls the updateLambdaCode() API when it receives only a code difference in a Lambda function (Inline Python code)', async () => { // GIVEN @@ -118,7 +118,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])( }, ); - silentTest('throw a CfnEvaluationException when it receives an unsupported function runtime', async () => { + test('throw a CfnEvaluationException when it receives an unsupported function runtime', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { diff --git a/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts index 5524339c7..6a1e30128 100644 --- a/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/lambda-versions-aliases-hotswap-deployments.test.ts @@ -1,8 +1,8 @@ import { PublishVersionCommand, UpdateAliasCommand } from '@aws-sdk/client-lambda'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + jest.mock('@aws-sdk/client-lambda', () => { const original = jest.requireActual('@aws-sdk/client-lambda'); @@ -20,7 +20,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('hotswaps a Version if it points to a changed Function, even if it itself is unchanged', async () => { + test('hotswaps a Version if it points to a changed Function, even if it itself is unchanged', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -75,7 +75,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('hotswaps a Version if it points to a changed Function, even if it itself is replaced', async () => { + test('hotswaps a Version if it points to a changed Function, even if it itself is replaced', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -130,7 +130,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('hotswaps a Version and an Alias if the Function they point to changed', async () => { + test('hotswaps a Version and an Alias if the Function they point to changed', async () => { // GIVEN mockLambdaClient.on(PublishVersionCommand).resolves({ Version: 'v2', diff --git a/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts b/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts index 2c48ecc18..0d3b41b7e 100644 --- a/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts +++ b/packages/aws-cdk/test/api/hotswap/nested-stacks-hotswap.test.ts @@ -2,13 +2,13 @@ import { PublishVersionCommand, UpdateFunctionCodeCommand } from '@aws-sdk/clien import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; import { testStack } from '../../_helpers/assembly'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('can hotswap a lambda function in a 1-level nested stack', async () => { + test('can hotswap a lambda function in a 1-level nested stack', async () => { // GIVEN hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('LambdaRoot'); @@ -76,7 +76,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('hotswappable changes do not override hotswappable changes in their ancestors', async () => { + test('hotswappable changes do not override hotswappable changes in their ancestors', async () => { // GIVEN hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('TwoLevelLambdaRoot'); @@ -194,7 +194,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'hotswappable changes in nested stacks do not override hotswappable changes in their parent stack', async () => { // GIVEN @@ -285,7 +285,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `non-hotswappable changes in nested stacks result in a full deployment, even if their parent contains a hotswappable change in CLASSIC mode, but perform a hotswap deployment in HOTSWAP_ONLY`, async () => { @@ -382,7 +382,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `deleting a nested stack results in a full deployment in CLASSIC mode, even if their parent contains a hotswappable change, but results in a hotswap deployment in HOTSWAP_ONLY mode`, async () => { @@ -478,7 +478,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `creating a nested stack results in a full deployment in CLASSIC mode, even if their parent contains a hotswappable change, but results in a hotswap deployment in HOTSWAP_ONLY mode`, async () => { @@ -543,7 +543,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `attempting to hotswap a newly created nested stack with the same logical ID as a resource with a different type results in a full deployment in CLASSIC mode and a hotswap deployment in HOTSWAP_ONLY mode`, async () => { @@ -621,7 +621,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('multi-sibling + 3-layer nested stack structure is hotswappable', async () => { + test('multi-sibling + 3-layer nested stack structure is hotswappable', async () => { // GIVEN hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('MultiLayerRoot'); @@ -774,7 +774,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('can hotswap a lambda function in a 1-level nested stack with asset parameters', async () => { + test('can hotswap a lambda function in a 1-level nested stack with asset parameters', async () => { // GIVEN hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('LambdaRoot'); @@ -863,7 +863,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'can hotswap a lambda function in a 2-level nested stack with dependency on an output of 2nd level sibling stack', async () => { // GIVEN: RootStack has one child stack `FirstLevelNestedStack` which further has two child stacks @@ -1023,7 +1023,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'can hotswap a lambda function in a 1-level nested stack and read default parameters value if not provided', async () => { // GIVEN: RootStack has one child stack `NestedStack`. `NestedStack` takes two @@ -1118,7 +1118,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('can hotswap a lambda function in a 2-level nested stack with asset parameters', async () => { + test('can hotswap a lambda function in a 2-level nested stack with asset parameters', async () => { // GIVEN hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('LambdaRoot'); @@ -1269,7 +1269,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('looking up objects in nested stacks works', async () => { + test('looking up objects in nested stacks works', async () => { hotswapMockSdkProvider = setup.setupHotswapNestedStackTests('LambdaRoot'); const rootStack = testStack({ diff --git a/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts index 484a9b866..3a47c6b44 100644 --- a/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/s3-bucket-hotswap-deployments.test.ts @@ -1,8 +1,8 @@ import { InvokeCommand } from '@aws-sdk/client-lambda'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockLambdaClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockLambdaClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -21,7 +21,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest( + test( 'calls the lambdaInvoke() API when it receives only an asset difference in an S3 bucket deployment and evaluates CFN expressions in S3 Deployment Properties', async () => { // GIVEN @@ -78,7 +78,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the invoke() API when a resource with type that is not Custom::CDKBucketDeployment but has the same properties is changed', async () => { // GIVEN @@ -124,7 +124,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the invokeLambda() api if the updated Policy has no Roles in CLASSIC mode but does in HOTSWAP_ONLY mode', async () => { // GIVEN @@ -227,7 +227,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('throws an error when the serviceToken fails evaluation in the template', async () => { + test('throws an error when the serviceToken fails evaluation in the template', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -409,7 +409,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot ); }); - silentTest( + test( 'calls the lambdaInvoke() API when it receives an asset difference in an S3 bucket deployment and an IAM Policy difference using old-style synthesis', async () => { // GIVEN @@ -457,7 +457,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `does not call the lambdaInvoke() API when the difference in the S3 deployment is referred to in one IAM policy change but not another in CLASSIC mode but does in HOTSWAP_ONLY`, async () => { @@ -527,7 +527,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `does not call the lambdaInvoke() API when the lambda that references the role is referred to by something other than an S3 deployment in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { @@ -600,7 +600,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the lambdaInvoke() API when it receives an asset difference in two S3 bucket deployments and IAM Policy differences using old-style synthesis', async () => { // GIVEN @@ -711,7 +711,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `does not call the lambdaInvoke() API when it receives an asset difference in an S3 bucket deployment that references two different policies in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { @@ -781,7 +781,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `does not call the lambdaInvoke() API when a policy is referenced by a resource that is not an S3 deployment in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { diff --git a/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts b/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts index 60427a458..0c44ae4a6 100644 --- a/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts +++ b/packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts @@ -1,8 +1,8 @@ import { UpdateStateMachineCommand } from '@aws-sdk/client-sfn'; import * as setup from '../_helpers/hotswap-test-setup'; import { HotswapMode } from '../../../lib/api/hotswap/common'; -import { mockStepFunctionsClient } from '../../util/mock-sdk'; -import { silentTest } from '../../util/silent'; +import { mockStepFunctionsClient } from '../../_helpers/mock-sdk'; + let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; @@ -11,7 +11,7 @@ beforeEach(() => { }); describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { - silentTest('returns undefined when a new StateMachine is added to the Stack', async () => { + test('returns undefined when a new StateMachine is added to the Stack', async () => { // GIVEN const cdkStackArtifact = setup.cdkStackArtifactOf({ template: { @@ -41,7 +41,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot } }); - silentTest( + test( 'calls the updateStateMachine() API when it receives only a definitionString change without Fn::Join in a state machine', async () => { // GIVEN @@ -82,7 +82,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateStateMachine() API when it receives only a definitionString change with Fn::Join in a state machine', async () => { // GIVEN @@ -164,7 +164,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'calls the updateStateMachine() API when it receives a change to the definitionString in a state machine that has no name', async () => { // GIVEN @@ -210,7 +210,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( `does not call the updateStateMachine() API when it receives a change to a property that is not the definitionString in a state machine alongside a hotswappable change in CLASSIC mode but does in HOTSWAP_ONLY mode`, async () => { @@ -273,7 +273,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( 'does not call the updateStateMachine() API when a resource has a DefinitionString property but is not an AWS::StepFunctions::StateMachine is changed', async () => { // GIVEN @@ -319,7 +319,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('can correctly hotswap old style synth changes', async () => { + test('can correctly hotswap old style synth changes', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Parameters: { AssetParam1: { Type: 'String' } }, @@ -368,7 +368,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest( + test( 'calls the updateStateMachine() API when it receives a change to the definitionString that uses Attributes in a state machine', async () => { // GIVEN @@ -439,7 +439,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it cannot find a Ref target (outside the state machine's name)", async () => { // GIVEN @@ -486,7 +486,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest( + test( "will not perform a hotswap deployment if it doesn't know how to handle a specific attribute (outside the state machines's name)", async () => { // GIVEN @@ -556,7 +556,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }, ); - silentTest('knows how to handle attributes of the AWS::Events::EventBus resource', async () => { + test('knows how to handle attributes of the AWS::Events::EventBus resource', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -636,7 +636,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('knows how to handle attributes of the AWS::DynamoDB::Table resource', async () => { + test('knows how to handle attributes of the AWS::DynamoDB::Table resource', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -718,7 +718,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('knows how to handle attributes of the AWS::KMS::Key resource', async () => { + test('knows how to handle attributes of the AWS::KMS::Key resource', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { @@ -776,7 +776,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot }); }); - silentTest('does not explode if the DependsOn changes', async () => { + test('does not explode if the DependsOn changes', async () => { // GIVEN setup.setCurrentCfnStackTemplate({ Resources: { diff --git a/packages/aws-cdk/test/api/lazy-list-stack-resources.test.ts b/packages/aws-cdk/test/api/lazy-list-stack-resources.test.ts index 0c7c4edcb..da6d7b65f 100644 --- a/packages/aws-cdk/test/api/lazy-list-stack-resources.test.ts +++ b/packages/aws-cdk/test/api/lazy-list-stack-resources.test.ts @@ -2,7 +2,7 @@ import 'aws-sdk-client-mock-jest'; import { ListStackResourcesCommand } from '@aws-sdk/client-cloudformation'; import { LazyListStackResources } from '../../lib/api/cloudformation'; -import { MockSdk, mockCloudFormationClient } from '../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient } from '../_helpers/mock-sdk'; describe('Lazy ListStackResources', () => { test('correctly caches calls to the CloudFormation API', async () => { diff --git a/packages/aws-cdk/test/api/lazy-lookup-export.test.ts b/packages/aws-cdk/test/api/lazy-lookup-export.test.ts index 9fbdb115b..7325ef741 100644 --- a/packages/aws-cdk/test/api/lazy-lookup-export.test.ts +++ b/packages/aws-cdk/test/api/lazy-lookup-export.test.ts @@ -1,6 +1,6 @@ import { ListExportsCommand } from '@aws-sdk/client-cloudformation'; import { LazyLookupExport } from '../../lib/api/cloudformation'; -import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; describe('LazyLookupExport', () => { const mockSdk = new MockSdk(); diff --git a/packages/aws-cdk/test/api/logs/find-cloudwatch-logs.test.ts b/packages/aws-cdk/test/api/log-monitor/find-cloudwatch-logs.test.ts similarity index 99% rename from packages/aws-cdk/test/api/logs/find-cloudwatch-logs.test.ts rename to packages/aws-cdk/test/api/log-monitor/find-cloudwatch-logs.test.ts index 8c5c4895b..dbf24594d 100644 --- a/packages/aws-cdk/test/api/logs/find-cloudwatch-logs.test.ts +++ b/packages/aws-cdk/test/api/log-monitor/find-cloudwatch-logs.test.ts @@ -15,7 +15,7 @@ import { MockSdkProvider, restoreSdkMocksToDefault, setDefaultSTSMocks, -} from '../../util/mock-sdk'; +} from '../../_helpers/mock-sdk'; let sdk: MockSdk; let logsMockSdkProvider: SdkProvider; diff --git a/packages/aws-cdk/test/api/logs/logging.test.ts b/packages/aws-cdk/test/api/log-monitor/logging.test.ts similarity index 100% rename from packages/aws-cdk/test/api/logs/logging.test.ts rename to packages/aws-cdk/test/api/log-monitor/logging.test.ts diff --git a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts b/packages/aws-cdk/test/api/log-monitor/logs-monitor.test.ts similarity index 89% rename from packages/aws-cdk/test/api/logs/logs-monitor.test.ts rename to packages/aws-cdk/test/api/log-monitor/logs-monitor.test.ts index b5d120720..eaeffd0ed 100644 --- a/packages/aws-cdk/test/api/logs/logs-monitor.test.ts +++ b/packages/aws-cdk/test/api/log-monitor/logs-monitor.test.ts @@ -1,8 +1,8 @@ import { FilterLogEventsCommand, type FilteredLogEvent } from '@aws-sdk/client-cloudwatch-logs'; import { CloudWatchLogEventMonitor } from '../../../lib/api/logs/logs-monitor'; import { sleep } from '../../_helpers/sleep'; -import { MockSdk, mockCloudWatchClient } from '../../util/mock-sdk'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { MockSdk, mockCloudWatchClient } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; // Helper function to strip ANSI codes const stripAnsi = (str: string): string => { @@ -15,16 +15,16 @@ let monitor: CloudWatchLogEventMonitor; let ioHost = new TestIoHost(); beforeEach(() => { monitor = new CloudWatchLogEventMonitor({ - ioHelper: asIoHelper(ioHost, 'deploy'), + ioHelper: ioHost.asHelper('deploy'), startTime: new Date(T100), }); sdk = new MockSdk(); }); -afterEach(() => { +afterEach(async () => { ioHost.notifySpy.mockReset(); ioHost.requestSpy.mockReset(); - monitor.deactivate(); + await monitor.deactivate(); }); test('process events', async () => { @@ -44,7 +44,7 @@ test('process events', async () => { ['loggroup'], ); // WHEN - monitor.activate(); + await monitor.activate(); // need time for the log processing to occur await sleep(1000); @@ -76,7 +76,7 @@ test('process truncated events', async () => { ['loggroup'], ); // WHEN - monitor.activate(); + await monitor.activate(); // need time for the log processing to occur await sleep(1000); diff --git a/packages/aws-cdk/test/notices.test.ts b/packages/aws-cdk/test/api/notices.test.ts similarity index 69% rename from packages/aws-cdk/test/notices.test.ts rename to packages/aws-cdk/test/api/notices.test.ts index 8bf66940f..ea6bb22c7 100644 --- a/packages/aws-cdk/test/notices.test.ts +++ b/packages/aws-cdk/test/api/notices.test.ts @@ -13,20 +13,23 @@ import { WebsiteNoticeDataSource, BootstrappedEnvironment, Component, -} from '../lib/notices'; -import * as version from '../lib/cli/version'; -import { Settings } from '../lib/api/settings'; -import { Context } from '../lib/api/context'; -import { asIoHelper, FakeIoHost, IoDefaultMessages } from '../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +} from '../../lib/notices'; +import * as version from '../../lib/cli/version'; +import { Settings } from '../../lib/api/settings'; +import { Context } from '../../lib/api/context'; +import { asIoHelper, IoDefaultMessages } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FakeIoHost } from '../_helpers/fake-io-host'; const BASIC_BOOTSTRAP_NOTICE = { title: 'Exccessive permissions on file asset publishing role', issueNumber: 16600, overview: 'FilePublishingRoleDefaultPolicy has too many permissions in {resolve:ENVIRONMENTS}', - components: [{ - name: 'bootstrap', - version: '<25', - }], + components: [ + { + name: 'bootstrap', + version: '<25', + }, + ], schemaVersion: '1', }; @@ -34,10 +37,12 @@ const BOOTSTRAP_NOTICE_V10 = { title: 'Bootstrap version 10 is no good', issueNumber: 16600, overview: 'overview', - components: [{ - name: 'bootstrap', - version: '=10', - }], + components: [ + { + name: 'bootstrap', + version: '=10', + }, + ], schemaVersion: '1', }; @@ -45,10 +50,12 @@ const BOOTSTRAP_NOTICE_V11 = { title: 'Bootstrap version 11 is no good', issueNumber: 16600, overview: 'overview', - components: [{ - name: 'bootstrap', - version: '=11', - }], + components: [ + { + name: 'bootstrap', + version: '=11', + }, + ], schemaVersion: '1', }; @@ -56,32 +63,40 @@ const BASIC_DYNAMIC_NOTICE = { title: 'Toggling off auto_delete_objects for Bucket empties the bucket', issueNumber: 16603, overview: '{resolve:DYNAMIC1} this is a notice with dynamic values {resolve:DYNAMIC2}', - components: [{ - name: 'cli', - version: '<=1.126.0', - }], + components: [ + { + name: 'cli', + version: '<=1.126.0', + }, + ], schemaVersion: '1', }; const BASIC_NOTICE = { title: 'Toggling off auto_delete_objects for Bucket empties the bucket', issueNumber: 16603, - overview: 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', - components: [{ - name: 'cli', - version: '<=1.126.0', - }], + overview: + 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', + components: [ + { + name: 'cli', + version: '<=1.126.0', + }, + ], schemaVersion: '1', }; const BASIC_WARNING_NOTICE = { title: 'Toggling off auto_delete_objects for Bucket empties the bucket', issueNumber: 16603, - overview: 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', - components: [{ - name: 'cli', - version: '<=1.126.0', - }], + overview: + 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', + components: [ + { + name: 'cli', + version: '<=1.126.0', + }, + ], schemaVersion: '1', severity: 'warning', }; @@ -89,11 +104,14 @@ const BASIC_WARNING_NOTICE = { const BASIC_ERROR_NOTICE = { title: 'Toggling off auto_delete_objects for Bucket empties the bucket', issueNumber: 16603, - overview: 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', - components: [{ - name: 'cli', - version: '<=1.126.0', - }], + overview: + 'If a stack is deployed with an S3 bucket with auto_delete_objects=True, and then re-deployed with auto_delete_objects=False, all the objects in the bucket will be deleted.', + components: [ + { + name: 'cli', + version: '<=1.126.0', + }, + ], schemaVersion: '1', severity: 'error', }; @@ -101,11 +119,14 @@ const BASIC_ERROR_NOTICE = { const MULTIPLE_AFFECTED_VERSIONS_NOTICE = { title: 'Error when building EKS cluster with monocdk import', issueNumber: 17061, - overview: 'When using monocdk/aws-eks to build a stack containing an EKS cluster, error is thrown about missing lambda-layer-node-proxy-agent/layer/package.json.', - components: [{ - name: 'cli', - version: '<1.130.0 >=1.126.0', - }], + overview: + 'When using monocdk/aws-eks to build a stack containing an EKS cluster, error is thrown about missing lambda-layer-node-proxy-agent/layer/package.json.', + components: [ + { + name: 'cli', + version: '<1.130.0 >=1.126.0', + }, + ], schemaVersion: '1', }; @@ -113,10 +134,12 @@ const FRAMEWORK_2_1_0_AFFECTED_NOTICE = { title: 'Regression on module foobar', issueNumber: 1234, overview: 'Some bug description', - components: [{ - name: 'framework', - version: '<= 2.1.0', - }], + components: [ + { + name: 'framework', + version: '<= 2.1.0', + }, + ], schemaVersion: '1', }; @@ -124,10 +147,12 @@ const NOTICE_FOR_APIGATEWAYV2 = { title: 'Regression on module foobar', issueNumber: 1234, overview: 'Some bug description', - components: [{ - name: '@aws-cdk/aws-apigatewayv2-alpha.', - version: '<= 2.13.0-alpha.0', - }], + components: [ + { + name: '@aws-cdk/aws-apigatewayv2-alpha.', + version: '<= 2.13.0-alpha.0', + }, + ], schemaVersion: '1', }; @@ -137,21 +162,23 @@ const NOTICES_FOR_IDENTITY_POOL = { overview: 'Some bug description', components: [ { - name: "@aws-cdk/aws-cognito-identitypool-alpha.IdentityPool", - version: ">=2.74.0-alpha.0 <2.179.0-alpha.0" - } + name: '@aws-cdk/aws-cognito-identitypool-alpha.IdentityPool', + version: '>=2.74.0-alpha.0 <2.179.0-alpha.0', + }, ], schemaVersion: '1', -} +}; const NOTICE_FOR_APIGATEWAY = { title: 'Regression on module foobar', issueNumber: 1234, overview: 'Some bug description', - components: [{ - name: '@aws-cdk/aws-apigateway', - version: '<= 2.13.0-alpha.0', - }], + components: [ + { + name: '@aws-cdk/aws-apigateway', + version: '<= 2.13.0-alpha.0', + }, + ], schemaVersion: '1', }; @@ -159,18 +186,22 @@ const NOTICE_FOR_APIGATEWAYV2_CFN_STAGE = { title: 'Regression on module foobar', issueNumber: 1234, overview: 'Some bug description', - components: [{ - name: 'aws-cdk-lib.aws_apigatewayv2.CfnStage', - version: '<= 2.13.0-alpha.0', - }], + components: [ + { + name: 'aws-cdk-lib.aws_apigatewayv2.CfnStage', + version: '<= 2.13.0-alpha.0', + }, + ], schemaVersion: '1', }; const ioHost = new FakeIoHost(); -const ioHelper = asIoHelper(ioHost, 'notices' as any) +const ioHelper = asIoHelper(ioHost, 'notices' as any); const ioHostEmitter = new IoDefaultMessages(ioHelper); const noticesFilter = new NoticesFilter(ioHostEmitter); +const fixtures = path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees'); + beforeEach(() => { jest.restoreAllMocks(); ioHost.clear(); @@ -235,12 +266,28 @@ describe(NoticesFilter, () => { const notices = [BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE]; // doesn't matter for this test because our data only has CLI notices - const outDir = path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0'); - - expect(noticesFilter.filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.0.0' }).map(f => f.notice)).toEqual([BASIC_NOTICE]); - expect(noticesFilter.filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.129.0' }).map(f => f.notice)).toEqual([MULTIPLE_AFFECTED_VERSIONS_NOTICE]); - expect(noticesFilter.filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.126.0' }).map(f => f.notice)).toEqual([BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE]); - expect(noticesFilter.filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.130.0' }).map(f => f.notice)).toEqual([]); + const outDir = path.join(fixtures, 'built-with-2_12_0'); + + expect( + noticesFilter + .filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.0.0' }) + .map((f) => f.notice), + ).toEqual([BASIC_NOTICE]); + expect( + noticesFilter + .filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.129.0' }) + .map((f) => f.notice), + ).toEqual([MULTIPLE_AFFECTED_VERSIONS_NOTICE]); + expect( + noticesFilter + .filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.126.0' }) + .map((f) => f.notice), + ).toEqual([BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE]); + expect( + noticesFilter + .filter({ data: notices, bootstrappedEnvironments: [], outDir, cliVersion: '1.130.0' }) + .map((f) => f.notice), + ).toEqual([]); }); test('framework', () => { @@ -249,8 +296,26 @@ describe(NoticesFilter, () => { // doesn't matter for this test because our data only has framework notices const cliVersion = '1.0.0'; - expect(noticesFilter.filter({ data: notices, cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0') }).map(f => f.notice)).toEqual([]); - expect(noticesFilter.filter({ data: notices, cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'built-with-1_144_0') }).map(f => f.notice)).toEqual([FRAMEWORK_2_1_0_AFFECTED_NOTICE]); + expect( + noticesFilter + .filter({ + data: notices, + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'built-with-2_12_0'), + }) + .map((f) => f.notice), + ).toEqual([]); + expect( + noticesFilter + .filter({ + data: notices, + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'built-with-1_144_0'), + }) + .map((f) => f.notice), + ).toEqual([FRAMEWORK_2_1_0_AFFECTED_NOTICE]); }); test('module', () => { @@ -258,15 +323,51 @@ describe(NoticesFilter, () => { const cliVersion = '1.0.0'; // module-level match - expect(noticesFilter.filter({ data: [NOTICE_FOR_APIGATEWAYV2], cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'experimental-module') }).map(f => f.notice)).toEqual([NOTICE_FOR_APIGATEWAYV2]); + expect( + noticesFilter + .filter({ + data: [NOTICE_FOR_APIGATEWAYV2], + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'experimental-module'), + }) + .map((f) => f.notice), + ).toEqual([NOTICE_FOR_APIGATEWAYV2]); // no apigatewayv2 in the tree - expect(noticesFilter.filter({ data: [NOTICE_FOR_APIGATEWAYV2], cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0') }).map(f => f.notice)).toEqual([]); + expect( + noticesFilter + .filter({ + data: [NOTICE_FOR_APIGATEWAYV2], + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'built-with-2_12_0'), + }) + .map((f) => f.notice), + ).toEqual([]); // module name mismatch: apigateway != apigatewayv2 - expect(noticesFilter.filter({ data: [NOTICE_FOR_APIGATEWAY], cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'experimental-module') }).map(f => f.notice)).toEqual([]); + expect( + noticesFilter + .filter({ + data: [NOTICE_FOR_APIGATEWAY], + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'experimental-module'), + }) + .map((f) => f.notice), + ).toEqual([]); // construct-level match - expect(noticesFilter.filter({ data: [NOTICE_FOR_APIGATEWAYV2_CFN_STAGE], cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'experimental-module') }).map(f => f.notice)).toEqual([NOTICE_FOR_APIGATEWAYV2_CFN_STAGE]); + expect( + noticesFilter + .filter({ + data: [NOTICE_FOR_APIGATEWAYV2_CFN_STAGE], + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'experimental-module'), + }) + .map((f) => f.notice), + ).toEqual([NOTICE_FOR_APIGATEWAYV2_CFN_STAGE]); }); test('module with pre-release version', () => { @@ -274,12 +375,21 @@ describe(NoticesFilter, () => { const cliVersion = '1.0.0'; // module-level match - expect(noticesFilter.filter({ data: [NOTICES_FOR_IDENTITY_POOL], cliVersion, bootstrappedEnvironments: [], outDir: path.join(__dirname, 'cloud-assembly-trees', 'experimental-module-pre-release-semver')}).map(f => f.notice)).toEqual([NOTICES_FOR_IDENTITY_POOL]); + expect( + noticesFilter + .filter({ + data: [NOTICES_FOR_IDENTITY_POOL], + cliVersion, + bootstrappedEnvironments: [], + outDir: path.join(fixtures, 'experimental-module-pre-release-semver'), + }) + .map((f) => f.notice), + ).toEqual([NOTICES_FOR_IDENTITY_POOL]); }); test('bootstrap', () => { // doesn't matter for this test because our data only has bootstrap notices - const outDir = path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0'); + const outDir = path.join(fixtures, 'built-with-2_12_0'); const cliVersion = '1.0.0'; const bootstrappedEnvironments: BootstrappedEnvironment[] = [ @@ -318,26 +428,32 @@ describe(NoticesFilter, () => { outDir, bootstrappedEnvironments: bootstrappedEnvironments, }); - expect(filtered.map(f => f.notice)).toEqual([BASIC_BOOTSTRAP_NOTICE]); - expect(filtered.map(f => f.format()).join('\n')).toContain('env1,env2'); + expect(filtered.map((f) => f.notice)).toEqual([BASIC_BOOTSTRAP_NOTICE]); + expect(filtered.map((f) => f.format()).join('\n')).toContain('env1,env2'); }); test('ignores invalid bootstrap versions', () => { // doesn't matter for this test because our data only has bootstrap notices - const outDir = path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0'); + const outDir = path.join(fixtures, 'built-with-2_12_0'); const cliVersion = '1.0.0'; - expect(noticesFilter.filter({ - data: [BASIC_BOOTSTRAP_NOTICE], - cliVersion, - outDir, - bootstrappedEnvironments: [{ bootstrapStackVersion: NaN, environment: { account: 'account', region: 'region', name: 'env' } }], - }).map(f => f.notice)).toEqual([]); + expect( + noticesFilter + .filter({ + data: [BASIC_BOOTSTRAP_NOTICE], + cliVersion, + outDir, + bootstrappedEnvironments: [ + { bootstrapStackVersion: NaN, environment: { account: 'account', region: 'region', name: 'env' } }, + ], + }) + .map((f) => f.notice), + ).toEqual([]); }); test('node version', () => { // can match node version - const outDir = path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0'); + const outDir = path.join(fixtures, 'built-with-2_12_0'); const cliVersion = '1.0.0'; const filtered = noticesFilter.filter({ @@ -352,7 +468,7 @@ describe(NoticesFilter, () => { name: 'node', version: '>= 14.x', }, - ] + ], }, { title: 'dontmatchme', @@ -364,7 +480,7 @@ describe(NoticesFilter, () => { name: 'node', version: '>= 999.x', }, - ] + ], }, ] satisfies Notice[], cliVersion, @@ -372,43 +488,25 @@ describe(NoticesFilter, () => { bootstrappedEnvironments: [], }); - expect(filtered.map(f => f.notice.title)).toEqual(['matchme']); + expect(filtered.map((f) => f.notice.title)).toEqual(['matchme']); const nodeVersion = process.version.replace(/^v/, ''); - expect(filtered.map(f => f.format()).join('\n')).toContain(`You are running ${nodeVersion}`); + expect(filtered.map((f) => f.format()).join('\n')).toContain(`You are running ${nodeVersion}`); }); test.each([ // No components => doesnt match - [ - [], - false, - ], + [[], false], // Multiple single-level components => treated as an OR, one of them is fine - [ - [['cli 1.0.0'], ['node >=999.x']], - true, - ], + [[['cli 1.0.0'], ['node >=999.x']], true], // OR of ANDS, all must match - [ - [['cli 1.0.0', 'node >=999.x']], - false, - ], - [ - [['cli 1.0.0', 'node >=14.x']], - true, - ], - [ - [['cli 1.0.0', 'node >=14.x'], ['cli >999.0.0']], - true, - ], + [[['cli 1.0.0', 'node >=999.x']], false], + [[['cli 1.0.0', 'node >=14.x']], true], + [[['cli 1.0.0', 'node >=14.x'], ['cli >999.0.0']], true], // Can combine matching against a construct and e.g. node version in the same query - [ - [['aws-cdk-lib.App ^2', 'node >=14.x']], - true, - ], + [[['aws-cdk-lib.App ^2', 'node >=14.x']], true], ])('disjunctive normal form: %j => %p', (components: string[][], shouldMatch) => { // can match node version - const outDir = path.join(__dirname, 'cloud-assembly-trees', 'built-with-2_12_0'); + const outDir = path.join(fixtures, 'built-with-2_12_0'); const cliVersion = '1.0.0'; // WHEN @@ -419,7 +517,7 @@ describe(NoticesFilter, () => { overview: 'match', issueNumber: 1, schemaVersion: '1', - components: components.map(ands => ands.map(parseTestComponent)), + components: components.map((ands) => ands.map(parseTestComponent)), }, ] satisfies Notice[], cliVersion, @@ -428,7 +526,7 @@ describe(NoticesFilter, () => { }); // THEN - expect(filtered.map(f => f.notice.title)).toEqual(shouldMatch ? ['match'] : []); + expect(filtered.map((f) => f.notice.title)).toEqual(shouldMatch ? ['match'] : []); }); }); }); @@ -447,7 +545,6 @@ function parseTestComponent(x: string): Component { }; } - describe(WebsiteNoticeDataSource, () => { const dataSource = new WebsiteNoticeDataSource(ioHelper); @@ -482,8 +579,9 @@ describe(WebsiteNoticeDataSource, () => { }); test('returns appropriate error when HTTPS call throws', async () => { - const mockGet = jest.spyOn(https, 'get') - .mockImplementation(() => { throw new Error('No connection'); }); + const mockGet = jest.spyOn(https, 'get').mockImplementation(() => { + throw new Error('No connection'); + }); const result = dataSource.fetch(); @@ -493,9 +591,7 @@ describe(WebsiteNoticeDataSource, () => { }); test('returns appropriate error when the request has an error', async () => { - nock('https://cli.cdk.dev-tools.aws.dev') - .get('/notices.json') - .replyWithError('DNS resolution failed'); + nock('https://cli.cdk.dev-tools.aws.dev').get('/notices.json').replyWithError('DNS resolution failed'); const result = dataSource.fetch(); @@ -529,9 +625,7 @@ describe(WebsiteNoticeDataSource, () => { }); function mockCall(statusCode: number, body: any): Promise { - nock('https://cli.cdk.dev-tools.aws.dev') - .get('/notices.json') - .reply(statusCode, body); + nock('https://cli.cdk.dev-tools.aws.dev').get('/notices.json').reply(statusCode, body); return dataSource.fetch(); } @@ -587,7 +681,6 @@ describe(CachedDataSource, () => { expect(notices).toEqual(freshData); expect(ioHost.messages).toEqual([]); - } finally { fs.rmSync(tmpDir, { recursive: true, force: true }); } @@ -633,7 +726,9 @@ describe(Notices, () => { beforeEach(() => { // disable caching jest.spyOn(CachedDataSource.prototype as any, 'save').mockImplementation((_: any) => Promise.resolve()); - jest.spyOn(CachedDataSource.prototype as any, 'load').mockImplementation(() => Promise.resolve({ expiration: 0, notices: [] })); + jest + .spyOn(CachedDataSource.prototype as any, 'load') + .mockImplementation(() => Promise.resolve({ expiration: 0, notices: [] })); }); afterEach(() => { @@ -643,8 +738,14 @@ describe(Notices, () => { describe('addBootstrapVersion', () => { test('can add multiple values', async () => { const notices = Notices.create({ context: new Context(), ioHost }); - notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } }); - notices.addBootstrappedEnvironment({ bootstrapStackVersion: 11, environment: { account: 'account', region: 'region', name: 'env' } }); + notices.addBootstrappedEnvironment({ + bootstrapStackVersion: 10, + environment: { account: 'account', region: 'region', name: 'env' }, + }); + notices.addBootstrappedEnvironment({ + bootstrapStackVersion: 11, + environment: { account: 'account', region: 'region', name: 'env' }, + }); await notices.refresh({ dataSource: { fetch: async () => [BOOTSTRAP_NOTICE_V10, BOOTSTRAP_NOTICE_V11] }, @@ -657,8 +758,14 @@ describe(Notices, () => { test('deduplicates', async () => { const notices = Notices.create({ ioHost, context: new Context() }); - notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } }); - notices.addBootstrappedEnvironment({ bootstrapStackVersion: 10, environment: { account: 'account', region: 'region', name: 'env' } }); + notices.addBootstrappedEnvironment({ + bootstrapStackVersion: 10, + environment: { account: 'account', region: 'region', name: 'env' }, + }); + notices.addBootstrappedEnvironment({ + bootstrapStackVersion: 10, + environment: { account: 'account', region: 'region', name: 'env' }, + }); // mock cli version number jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.0.0'); @@ -670,14 +777,16 @@ describe(Notices, () => { expect(filter).toHaveBeenCalledTimes(1); expect(filter).toHaveBeenCalledWith({ - bootstrappedEnvironments: [{ - bootstrapStackVersion: 10, - environment: { - account: 'account', - region: 'region', - name: 'env', + bootstrappedEnvironments: [ + { + bootstrapStackVersion: 10, + environment: { + account: 'account', + region: 'region', + name: 'env', + }, }, - }], + ], cliVersion: '1.0.0', data: [], outDir: 'cdk.out', @@ -727,7 +836,9 @@ describe(Notices, () => { // within the affected version range of both notices jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.126.0'); - const context = new Context({ bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }) }); + const context = new Context({ + bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), + }); const notices = Notices.create({ ioHost, context }); await notices.refresh({ @@ -736,14 +847,19 @@ describe(Notices, () => { notices.display(); ioHost.expectMessage({ containing: new FilteredNotice(BASIC_NOTICE).format() }); - ioHost.expectMessage({ containing: 'If you don’t want to see a notice anymore, use \"cdk acknowledge \". For example, \"cdk acknowledge 16603\".' }); + ioHost.expectMessage({ + containing: + 'If you don’t want to see a notice anymore, use "cdk acknowledge ". For example, "cdk acknowledge 16603".', + }); }); test('preserves acknowledged notices if requested', async () => { // within the affected version range of both notices jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.126.0'); - const context = new Context({ bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }) }); + const context = new Context({ + bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), + }); const notices = Notices.create({ ioHost, context, includeAcknowledged: true }); await notices.refresh({ @@ -767,8 +883,13 @@ describe(Notices, () => { }); notices.display(); - ioHost.expectMessage({ containing: 'NOTICES (What\'s this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)' }); - ioHost.expectMessage({ containing: 'If you don’t want to see a notice anymore, use \"cdk acknowledge \". For example, \"cdk acknowledge 16603\".' }); + ioHost.expectMessage({ + containing: "NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)", + }); + ioHost.expectMessage({ + containing: + 'If you don’t want to see a notice anymore, use "cdk acknowledge ". For example, "cdk acknowledge 16603".', + }); }); test('deduplicates notices', async () => { @@ -782,7 +903,10 @@ describe(Notices, () => { notices.display(); ioHost.expectMessage({ containing: new FilteredNotice(BASIC_NOTICE).format() }); - ioHost.expectMessage({ containing: 'If you don’t want to see a notice anymore, use \"cdk acknowledge \". For example, \"cdk acknowledge 16603\".' }); + ioHost.expectMessage({ + containing: + 'If you don’t want to see a notice anymore, use "cdk acknowledge ". For example, "cdk acknowledge 16603".', + }); }); test('nothing when there are no notices', async () => { @@ -840,7 +964,9 @@ describe(Notices, () => { // within the affected version range of both notices jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.126.0'); - const context = new Context({ bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }) }); + const context = new Context({ + bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), + }); const notices = Notices.create({ ioHost, context }); await notices.refresh({ @@ -855,7 +981,9 @@ describe(Notices, () => { // within the affected version range of both notices jest.spyOn(version, 'versionNumber').mockImplementation(() => '1.126.0'); - const context = new Context({ bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }) }); + const context = new Context({ + bag: new Settings({ 'acknowledged-issue-numbers': [MULTIPLE_AFFECTED_VERSIONS_NOTICE.issueNumber] }), + }); const notices = Notices.create({ ioHost, context, includeAcknowledged: true }); await notices.refresh({ dataSource: { fetch: async () => [BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE] }, diff --git a/packages/aws-cdk/test/api/resource-import/import.test.ts b/packages/aws-cdk/test/api/resource-import/import.test.ts index bb41f0e25..1c2e72049 100644 --- a/packages/aws-cdk/test/api/resource-import/import.test.ts +++ b/packages/aws-cdk/test/api/resource-import/import.test.ts @@ -18,8 +18,8 @@ import * as promptly from 'promptly'; import { Deployments } from '../../../lib/api/deployments'; import { ResourceImporter, ImportMap, ResourceImporterProps } from '../../../lib/api/resource-import'; import { testStack } from '../../_helpers/assembly'; -import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../util/mock-sdk'; -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; +import { TestIoHost } from '../../_helpers/io-host'; const promptlyConfirm = promptly.confirm as jest.Mock; const promptlyPrompt = promptly.prompt as jest.Mock; @@ -75,6 +75,7 @@ function stackWithKeySigningKey(props: Record) { let sdkProvider: MockSdkProvider; let deployments: Deployments; let ioHost = new TestIoHost(); +let ioHelper = ioHost.asHelper('deploy'); let props: ResourceImporterProps; beforeEach(() => { restoreSdkMocksToDefault(); @@ -82,11 +83,11 @@ beforeEach(() => { sdkProvider = new MockSdkProvider(); deployments = new Deployments({ sdkProvider, - ioHelper: asIoHelper(ioHost, 'deploy'), + ioHelper, }); props = { deployments, - ioHelper: asIoHelper(ioHost, 'deploy'), + ioHelper, }; }); diff --git a/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts b/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts index f9e45ce94..9ff9f388d 100644 --- a/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts +++ b/packages/aws-cdk/test/api/stack-events/stack-activity-monitor.test.ts @@ -4,7 +4,7 @@ import { type StackEvent, StackStatus, } from '@aws-sdk/client-cloudformation'; -import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient, restoreSdkMocksToDefault } from '../../_helpers/mock-sdk'; import { StackActivityMonitor } from '../../../lib/api/stack-events'; import { testStack } from '../../_helpers/assembly'; import { asIoHelper } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; diff --git a/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts b/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts index 1c4abd3fd..def1dd977 100644 --- a/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts +++ b/packages/aws-cdk/test/api/stack-events/stack-event-poller.test.ts @@ -1,6 +1,6 @@ import { DescribeStackEventsCommand, DescribeStackEventsCommandInput, StackEvent } from '@aws-sdk/client-cloudformation'; import { StackEventPoller } from '../../../lib/api/stack-events'; -import { MockSdk, mockCloudFormationClient } from '../../util/mock-sdk'; +import { MockSdk, mockCloudFormationClient } from '../../_helpers/mock-sdk'; beforeEach(() => { jest.resetAllMocks(); diff --git a/packages/aws-cdk/test/api/tree.test.ts b/packages/aws-cdk/test/api/tree.test.ts index 975725f2f..d3b720b69 100644 --- a/packages/aws-cdk/test/api/tree.test.ts +++ b/packages/aws-cdk/test/api/tree.test.ts @@ -104,12 +104,12 @@ describe('some', () => { describe('loadTreeFromDir', () => { test('can find tree', () => { - const tree = loadTreeFromDir(path.join(__dirname, '..', 'cloud-assembly-trees', 'built-with-1_144_0'), () => {}); + const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'built-with-1_144_0'), () => {}); expect(tree?.id).toEqual('App'); }); test('cannot find tree', () => { - const tree = loadTreeFromDir(path.join(__dirname, '..', 'cloud-assembly-trees', 'foo'), () => {}); + const tree = loadTreeFromDir(path.join(__dirname, '..', '_fixtures', 'cloud-assembly-trees', 'foo'), () => {}); expect(tree).toEqual(undefined); }); }); diff --git a/packages/aws-cdk/test/api/work-graph/work-graph.test.ts b/packages/aws-cdk/test/api/work-graph/work-graph.test.ts index fd7c2cc87..cd4a96150 100644 --- a/packages/aws-cdk/test/api/work-graph/work-graph.test.ts +++ b/packages/aws-cdk/test/api/work-graph/work-graph.test.ts @@ -1,4 +1,4 @@ -import { asIoHelper, TestIoHost } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { TestIoHost } from '../../_helpers/io-host'; import { WorkGraph, DeploymentState } from '../../../lib/api/work-graph'; import type { AssetBuildNode, AssetPublishNode, StackNode } from '../../../lib/api/work-graph'; @@ -246,7 +246,7 @@ describe('WorkGraph', () => { expected: ['c-build', 'c-publish', 'A', 'b-build', 'b-publish', 'B'], }, ])('Success - Concurrency: $concurrency - $scenario', async ({ concurrency, expected, toDeploy }) => { - const graph = new WorkGraph({}, asIoHelper(ioHost, 'deploy')); + const graph = new WorkGraph({}, ioHost.asHelper('deploy')); addTestArtifactsToGraph(toDeploy, graph); await graph.doParallel(concurrency, callbacks); @@ -255,7 +255,7 @@ describe('WorkGraph', () => { }); test('can remove unnecessary assets', async () => { - const graph = new WorkGraph({}, asIoHelper(ioHost, 'deploy')); + const graph = new WorkGraph({}, ioHost.asHelper('deploy')); addTestArtifactsToGraph([ { id: 'a', type: 'asset' }, { id: 'b', type: 'asset' }, @@ -378,7 +378,7 @@ describe('WorkGraph', () => { expected: ['b-build', 'C'], }, ])('Failure - Concurrency: $concurrency - $scenario', async ({ concurrency, expectedError, toDeploy, expected }) => { - const graph = new WorkGraph({}, asIoHelper(ioHost, 'deploy')); + const graph = new WorkGraph({}, ioHost.asHelper('deploy')); addTestArtifactsToGraph(toDeploy, graph); await expect(graph.doParallel(concurrency, callbacks)).rejects.toThrow(expectedError); @@ -414,7 +414,7 @@ describe('WorkGraph', () => { expectedError: 'B -> C -> D -> B', }, ])('Failure - Graph Circular Dependencies - $scenario', async ({ toDeploy, expectedError }) => { - const graph = new WorkGraph({}, asIoHelper(ioHost, 'deploy')); + const graph = new WorkGraph({}, ioHost.asHelper('deploy')); addTestArtifactsToGraph(toDeploy, graph); await expect(graph.doParallel(1, callbacks)).rejects.toThrow(new RegExp(`Unable to make progress.*${expectedError}`)); diff --git a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts index 7a801793d..6c9f2376c 100644 --- a/packages/aws-cdk/test/cli/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cli/cdk-toolkit.test.ts @@ -95,7 +95,7 @@ import { MockSdkProvider, mockSSMClient, restoreSdkMocksToDefault, -} from '../util/mock-sdk'; +} from '../_helpers/mock-sdk'; import { asIoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; import { StackActivityProgress } from '../../lib/commands/deploy'; import { Template } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api'; diff --git a/packages/aws-cdk/test/commands/migrate.test.ts b/packages/aws-cdk/test/commands/migrate.test.ts index 3cff68a91..c47b3455a 100644 --- a/packages/aws-cdk/test/commands/migrate.test.ts +++ b/packages/aws-cdk/test/commands/migrate.test.ts @@ -29,7 +29,7 @@ import { GenerateTemplateOptions, FromScan, } from '../../lib/commands/migrate'; -import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { MockSdkProvider, mockCloudFormationClient, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; jest.setTimeout(120_000); diff --git a/packages/aws-cdk/test/context-providers/amis.test.ts b/packages/aws-cdk/test/context-providers/amis.test.ts index 05f55b112..8297f338b 100644 --- a/packages/aws-cdk/test/context-providers/amis.test.ts +++ b/packages/aws-cdk/test/context-providers/amis.test.ts @@ -2,8 +2,8 @@ import 'aws-sdk-client-mock'; import { DescribeImagesCommand } from '@aws-sdk/client-ec2'; import { SDK, SdkForEnvironment } from '../../lib/api'; import { AmiContextProviderPlugin } from '../../lib/context-providers/ami'; -import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockEC2Client } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockEC2Client } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts b/packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts index b66083332..655d4b793 100644 --- a/packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts +++ b/packages/aws-cdk/test/context-providers/asymmetric-vpcs.test.ts @@ -5,7 +5,7 @@ import { DescribeVpnGatewaysCommand, } from '@aws-sdk/client-ec2'; import { VpcNetworkContextProviderPlugin } from '../../lib/context-providers/vpcs'; -import { MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; const mockMsg = { debug: jest.fn(), diff --git a/packages/aws-cdk/test/context-providers/availability-zones.test.ts b/packages/aws-cdk/test/context-providers/availability-zones.test.ts index b9f357aeb..09a4c37a6 100644 --- a/packages/aws-cdk/test/context-providers/availability-zones.test.ts +++ b/packages/aws-cdk/test/context-providers/availability-zones.test.ts @@ -1,8 +1,8 @@ import { DescribeAvailabilityZonesCommand } from '@aws-sdk/client-ec2'; import { SDK, SdkForEnvironment } from '../../lib/api'; import { AZContextProviderPlugin } from '../../lib/context-providers/availability-zones'; -import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts b/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts index 0c5a3df6c..fd1a19bcd 100644 --- a/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts +++ b/packages/aws-cdk/test/context-providers/cc-api-provider.test.ts @@ -1,6 +1,6 @@ import { GetResourceCommand, InvalidRequestException, ListResourcesCommand, ResourceNotFoundException } from '@aws-sdk/client-cloudcontrol'; import { CcApiContextProviderPlugin } from '../../lib/context-providers/cc-api-provider'; -import { mockCloudControlClient, MockSdkProvider, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { mockCloudControlClient, MockSdkProvider, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; let provider: CcApiContextProviderPlugin; diff --git a/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts b/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts index 396f7c533..80eaab8e5 100644 --- a/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts +++ b/packages/aws-cdk/test/context-providers/endpoint-service-availability-zones.test.ts @@ -3,8 +3,8 @@ import { SDK, SdkForEnvironment } from '../../lib/api'; import { EndpointServiceAZContextProviderPlugin, } from '../../lib/context-providers/endpoint-service-availability-zones'; -import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, mockEC2Client, MockSdkProvider } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/generic.test.ts b/packages/aws-cdk/test/context-providers/generic.test.ts index 60a4ee690..c1b3e7788 100644 --- a/packages/aws-cdk/test/context-providers/generic.test.ts +++ b/packages/aws-cdk/test/context-providers/generic.test.ts @@ -2,7 +2,7 @@ import { PluginHost } from '../../lib/api/plugin'; import * as contextproviders from '../../lib/context-providers'; import { Context, TRANSIENT_CONTEXT_KEY } from '../../lib/api/context'; -import { MockSdkProvider, setDefaultSTSMocks } from '../util/mock-sdk'; +import { MockSdkProvider, setDefaultSTSMocks } from '../_helpers/mock-sdk'; const mockSDK = new MockSdkProvider(); setDefaultSTSMocks(); diff --git a/packages/aws-cdk/test/context-providers/hosted-zones.test.ts b/packages/aws-cdk/test/context-providers/hosted-zones.test.ts index 6b630d1c4..539b3332f 100644 --- a/packages/aws-cdk/test/context-providers/hosted-zones.test.ts +++ b/packages/aws-cdk/test/context-providers/hosted-zones.test.ts @@ -1,8 +1,8 @@ import { GetHostedZoneCommand, ListHostedZonesByNameCommand } from '@aws-sdk/client-route-53'; import { SDK, SdkForEnvironment } from '../../lib/api'; import { HostedZoneContextProviderPlugin } from '../../lib/context-providers/hosted-zones'; -import { FAKE_CREDENTIAL_CHAIN, mockRoute53Client, MockSdkProvider } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, mockRoute53Client, MockSdkProvider } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/keys.test.ts b/packages/aws-cdk/test/context-providers/keys.test.ts index 9f2cdd797..45864a85e 100644 --- a/packages/aws-cdk/test/context-providers/keys.test.ts +++ b/packages/aws-cdk/test/context-providers/keys.test.ts @@ -1,6 +1,6 @@ import { ListAliasesCommand } from '@aws-sdk/client-kms'; import { KeyContextProviderPlugin } from '../../lib/context-providers/keys'; -import { mockKMSClient, MockSdkProvider, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { mockKMSClient, MockSdkProvider, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; let provider: KeyContextProviderPlugin; diff --git a/packages/aws-cdk/test/context-providers/load-balancers.test.ts b/packages/aws-cdk/test/context-providers/load-balancers.test.ts index 9fd0a21e5..42595d605 100644 --- a/packages/aws-cdk/test/context-providers/load-balancers.test.ts +++ b/packages/aws-cdk/test/context-providers/load-balancers.test.ts @@ -14,8 +14,8 @@ import { MockSdkProvider, mockElasticLoadBalancingV2Client, restoreSdkMocksToDefault, -} from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +} from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/security-groups.test.ts b/packages/aws-cdk/test/context-providers/security-groups.test.ts index 65b000b18..744cf1e1f 100644 --- a/packages/aws-cdk/test/context-providers/security-groups.test.ts +++ b/packages/aws-cdk/test/context-providers/security-groups.test.ts @@ -1,8 +1,8 @@ import { DescribeSecurityGroupsCommand } from '@aws-sdk/client-ec2'; import { SDK, type SdkForEnvironment } from '../../lib/api'; import { hasAllTrafficEgress, SecurityGroupContextProviderPlugin } from '../../lib/context-providers/security-groups'; -import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts b/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts index 1ffb6e66f..249bfbc97 100644 --- a/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts +++ b/packages/aws-cdk/test/context-providers/ssm-parameters.test.ts @@ -1,8 +1,8 @@ import { GetParameterCommand } from '@aws-sdk/client-ssm'; import { SDK, SdkForEnvironment } from '../../lib/api'; import { SSMContextProviderPlugin } from '../../lib/context-providers/ssm-parameters'; -import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockSSMClient, restoreSdkMocksToDefault } from '../util/mock-sdk'; -import { TestIoHost } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private'; +import { FAKE_CREDENTIAL_CHAIN, MockSdkProvider, mockSSMClient, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; +import { TestIoHost } from '../_helpers/io-host'; const mockSDK = new (class extends MockSdkProvider { public forEnvironment(): Promise { diff --git a/packages/aws-cdk/test/context-providers/vpcs.test.ts b/packages/aws-cdk/test/context-providers/vpcs.test.ts index bbad68d15..53c56f908 100644 --- a/packages/aws-cdk/test/context-providers/vpcs.test.ts +++ b/packages/aws-cdk/test/context-providers/vpcs.test.ts @@ -5,7 +5,7 @@ import { DescribeVpnGatewaysCommand, } from '@aws-sdk/client-ec2'; import { VpcNetworkContextProviderPlugin } from '../../lib/context-providers/vpcs'; -import { MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../util/mock-sdk'; +import { MockSdkProvider, mockEC2Client, restoreSdkMocksToDefault } from '../_helpers/mock-sdk'; const mockSDK = new MockSdkProvider(); const mockMsg = { diff --git a/packages/aws-cdk/test/util/silent.ts b/packages/aws-cdk/test/util/silent.ts deleted file mode 100644 index dff91132a..000000000 --- a/packages/aws-cdk/test/util/silent.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable jest/no-export */ -import * as logging from '../../lib/logging'; - -export function silentTest(name: string, callback: () => void | Promise, timeout?: number): void { - const spy = jest.spyOn(logging, 'info'); - if (process.env.CLI_TEST_VERBOSE) { - spy.mockRestore(); - } - test( - name, - async () => { - return callback(); - }, - timeout, - ); -}