Skip to content

Commit

Permalink
chore: save the logs (#31274)
Browse files Browse the repository at this point in the history
The tests for init are finding the cli's readme instead of the one it would be generating for a new app/library. When run in the cli, it's quite nice to have the README output, when we run the tests and get the cli's entire README it makes our build/test output unreadably long.

This change doesn't get rid of quite all the unnecessary logs but it does decrease the log output by about 30,000 lines.


### Checklist
- [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
TheRealAmazonKendra authored Sep 3, 2024
1 parent 1c63070 commit a6c2ad6
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 130 deletions.
7 changes: 6 additions & 1 deletion packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ async function initializeProject(
await template.addMigrateContext(workDir);
}
if (await fs.pathExists('README.md')) {
print(chalk.green(await fs.readFile('README.md', { encoding: 'utf-8' })));
const readme = await fs.readFile('README.md', { encoding: 'utf-8' });
// Save the logs!
// Without this statement, the readme of the CLI is printed in every init test
if (!readme.startsWith('# AWS CDK Toolkit')) {
print(chalk.green(readme));
}
}

if (!generateOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { AppSync, S3 } from 'aws-sdk';
import * as setup from './hotswap-test-setup';
import { HotswapMode } from '../../../lib/api/hotswap/common';
import { silentTest } from '../../util/silent';

let hotswapMockSdkProvider: setup.HotswapMockSdkProvider;
let mockUpdateResolver: (params: AppSync.UpdateResolverRequest) => AppSync.UpdateResolverResponse;
Expand All @@ -22,11 +23,10 @@ beforeEach(() => {
updateApiKey: mockUpdateApiKey,
startSchemaCreation: mockStartSchemaCreation,
});

});

describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => {
test(`A new Resolver being added to the Stack returns undefined in CLASSIC mode and
silentTest(`A new Resolver being added to the Stack returns undefined in CLASSIC mode and
returns a noOp in HOTSWAP_ONLY mode`,
async () => {
// GIVEN
Expand Down Expand Up @@ -56,7 +56,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test('calls the updateResolver() API when it receives only a mapping template difference in a Unit Resolver', async () => {
silentTest('calls the updateResolver() API when it receives only a mapping template difference in a Unit Resolver', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -122,7 +122,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateResolver() API when it receives only a mapping template difference s3 location in a Unit Resolver', async () => {
silentTest('calls the updateResolver() API when it receives only a mapping template difference s3 location in a Unit Resolver', async () => {
// GIVEN
mockS3GetObject = jest.fn().mockImplementation(async () => {
return { Body: 'template defined in s3' };
Expand Down Expand Up @@ -196,7 +196,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateResolver() API when it receives only a code s3 location in a Pipeline Resolver', async () => {
silentTest('calls the updateResolver() API when it receives only a code s3 location in a Pipeline Resolver', async () => {
// GIVEN
mockS3GetObject = jest.fn().mockImplementation(async () => {
return { Body: 'code defined in s3' };
Expand Down Expand Up @@ -267,7 +267,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateResolver() API when it receives only a code difference in a Pipeline Resolver', async () => {
silentTest('calls the updateResolver() API when it receives only a code difference in a Pipeline Resolver', async () => {
// GIVEN
hotswapMockSdkProvider.stubS3({ getObject: mockS3GetObject });
setup.setCurrentCfnStackTemplate({
Expand Down Expand Up @@ -331,7 +331,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateResolver() API when it receives only a mapping template difference in a Pipeline Resolver', async () => {
silentTest('calls the updateResolver() API when it receives only a mapping template difference in a Pipeline Resolver', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -399,7 +399,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

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
silentTest(`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 () => {
// GIVEN
Expand Down Expand Up @@ -465,7 +465,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

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 () => {
silentTest('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
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -511,7 +511,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test('calls the updateFunction() API when it receives only a mapping template difference in a Function', async () => {
silentTest('calls the updateFunction() API when it receives only a mapping template difference in a Function', async () => {
// GIVEN
const mockListFunctions = jest.fn().mockReturnValue({ functions: [{ name: 'my-function', functionId: 'functionId' }] });
hotswapMockSdkProvider.stubAppSync({ listFunctions: mockListFunctions, updateFunction: mockUpdateFunction });
Expand Down Expand Up @@ -571,7 +571,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateFunction() API with function version when it receives both function version and runtime with a mapping template in a Function', async () => {
silentTest('calls the updateFunction() API with function version when it receives both function version and runtime with a mapping template in a Function', async () => {
// GIVEN
const mockListFunctions = jest.fn().mockReturnValue({ functions: [{ name: 'my-function', functionId: 'functionId' }] });
hotswapMockSdkProvider.stubAppSync({ listFunctions: mockListFunctions, updateFunction: mockUpdateFunction });
Expand Down Expand Up @@ -633,7 +633,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateFunction() API with runtime when it receives both function version and runtime with code in a Function', async () => {
silentTest('calls the updateFunction() API with runtime when it receives both function version and runtime with code in a Function', async () => {
// GIVEN
const mockListFunctions = jest.fn().mockReturnValue({ functions: [{ name: 'my-function', functionId: 'functionId' }] });
hotswapMockSdkProvider.stubAppSync({ listFunctions: mockListFunctions, updateFunction: mockUpdateFunction });
Expand Down Expand Up @@ -692,7 +692,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateFunction() API when it receives only a mapping template s3 location difference in a Function', async () => {
silentTest('calls the updateFunction() API when it receives only a mapping template s3 location difference in a Function', async () => {
// GIVEN
mockS3GetObject = jest.fn().mockImplementation(async () => {
return { Body: 'template defined in s3' };
Expand Down Expand Up @@ -760,7 +760,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

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
silentTest(`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 () => {
// GIVEN
Expand Down Expand Up @@ -823,7 +823,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

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 () => {
silentTest('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
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -871,7 +871,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test('calls the startSchemaCreation() API when it receives only a definition difference in a graphql schema', async () => {
silentTest('calls the startSchemaCreation() API when it receives only a definition difference in a graphql schema', async () => {
// GIVEN
mockStartSchemaCreation = jest.fn().mockReturnValueOnce({ status: 'SUCCESS' });
hotswapMockSdkProvider.stubAppSync({ startSchemaCreation: mockStartSchemaCreation });
Expand Down Expand Up @@ -925,7 +925,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the startSchemaCreation() API when it receives only a definition s3 location difference in a graphql schema', async () => {
silentTest('calls the startSchemaCreation() API when it receives only a definition s3 location difference in a graphql schema', async () => {
// GIVEN
mockS3GetObject = jest.fn().mockImplementation(async () => {
return { Body: 'schema defined in s3' };
Expand Down Expand Up @@ -988,7 +988,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

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 () => {
silentTest('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
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -1042,7 +1042,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test('calls the startSchemaCreation() and waits for schema creation to stabilize before finishing', async () => {
silentTest('calls the startSchemaCreation() and waits for schema creation to stabilize before finishing', async () => {
// GIVEN
mockStartSchemaCreation = jest.fn().mockReturnValueOnce({ status: 'PROCESSING' });
const mockGetSchemaCreation = jest.fn().mockReturnValueOnce({ status: 'SUCCESS' });
Expand Down Expand Up @@ -1100,7 +1100,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the startSchemaCreation() and throws if schema creation fails', async () => {
silentTest('calls the startSchemaCreation() and throws if schema creation fails', async () => {
// GIVEN
mockStartSchemaCreation = jest.fn().mockReturnValueOnce({ status: 'PROCESSING' });
const mockGetSchemaCreation = jest.fn().mockReturnValueOnce({ status: 'FAILED', details: 'invalid schema' });
Expand Down Expand Up @@ -1157,7 +1157,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateApiKey() API when it receives only a expires property difference in an AppSync ApiKey', async () => {
silentTest('calls the updateApiKey() API when it receives only a expires property difference in an AppSync ApiKey', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -1211,7 +1211,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateApiKey() API when it receives only a expires property difference and no api-key-id in an AppSync ApiKey', async () => {
silentTest('calls the updateApiKey() API when it receives only a expires property difference and no api-key-id in an AppSync ApiKey', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/order */
import { CodeBuild } from 'aws-sdk';
import * as setup from './hotswap-test-setup';
import { HotswapMode } from '../../../lib/api/hotswap/common';
import { silentTest } from '../../util/silent';

let hotswapMockSdkProvider: setup.HotswapMockSdkProvider;
let mockUpdateProject: (params: CodeBuild.UpdateProjectInput) => CodeBuild.UpdateProjectOutput;
Expand All @@ -13,7 +13,7 @@ beforeEach(() => {
});

describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => {
test('returns undefined when a new CodeBuild Project is added to the Stack', async () => {
silentTest('returns undefined when a new CodeBuild Project is added to the Stack', async () => {
// GIVEN
const cdkStackArtifact = setup.cdkStackArtifactOf({
template: {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test('calls the updateProject() API when it receives only a source difference in a CodeBuild project', async () => {
silentTest('calls the updateProject() API when it receives only a source difference in a CodeBuild project', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateProject() API when it receives only a source version difference in a CodeBuild project', async () => {
silentTest('calls the updateProject() API when it receives only a source version difference in a CodeBuild project', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test('calls the updateProject() API when it receives only an environment difference in a CodeBuild project', async () => {
silentTest('calls the updateProject() API when it receives only an environment difference in a CodeBuild project', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -254,7 +254,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test("correctly evaluates the project's name when it references a different resource from the template", async () => {
silentTest("correctly evaluates the project's name when it references a different resource from the template", async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -324,7 +324,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test("correctly falls back to taking the project's name from the current stack if it can't evaluate it in the template", async () => {
silentTest("correctly falls back to taking the project's name from the current stack if it can't evaluate it in the template", async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Parameters: {
Expand Down Expand Up @@ -386,7 +386,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

test("will not perform a hotswap deployment if it cannot find a Ref target (outside the project's name)", async () => {
silentTest("will not perform a hotswap deployment if it cannot find a Ref target (outside the project's name)", async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Parameters: {
Expand Down Expand Up @@ -436,7 +436,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
).rejects.toThrow(/Parameter or resource 'Param1' could not be found for evaluation/);
});

test("will not perform a hotswap deployment if it doesn't know how to handle a specific attribute (outside the project's name)", async () => {
silentTest("will not perform a hotswap deployment if it doesn't know how to handle a specific attribute (outside the project's name)", async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -489,7 +489,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
).rejects.toThrow("We don't support the 'UnknownAttribute' attribute of the 'AWS::S3::Bucket' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose");
});

test('calls the updateProject() API when it receives a difference in a CodeBuild project with no name', async () => {
silentTest('calls the updateProject() API when it receives a difference in a CodeBuild project with no name', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -541,7 +541,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
});

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 () => {
silentTest('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
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down Expand Up @@ -592,7 +592,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
}
});

test(`when it receives a change that is not Source, SourceVersion, or Environment difference in a CodeBuild project alongside a hotswappable change,
silentTest(`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 () => {
// GIVEN
Expand Down Expand Up @@ -650,7 +650,7 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
});
}
});
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 () => {
silentTest('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
setup.setCurrentCfnStackTemplate({
Resources: {
Expand Down
Loading

0 comments on commit a6c2ad6

Please sign in to comment.