diff --git a/packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts b/packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts index bc770fe560..b0cd540189 100644 --- a/packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts +++ b/packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts @@ -9,23 +9,12 @@ const LOG_MSG = process.env.LOG_MSG || 'Hello World'; const logger = new Logger({ sampleRateValue: SAMPLE_RATE, }); -let firstInvocation = true; class Lambda implements LambdaInterface { - private readonly logMsg: string; + private readonly logMsg = LOG_MSG; - public constructor() { - this.logMsg = LOG_MSG; - } - - // Decorate your handler class method @logger.injectLambdaContext() public async handler(_event: TestEvent, context: Context): TestOutput { - if (firstInvocation) { - firstInvocation = false; - } else { - logger.refreshSampleRateCalculation(); - } this.printLogInAllLevels(); return { diff --git a/packages/testing/src/TestStack.ts b/packages/testing/src/TestStack.ts index 63b5a193c3..5ed69d1448 100644 --- a/packages/testing/src/TestStack.ts +++ b/packages/testing/src/TestStack.ts @@ -66,19 +66,63 @@ class TestStack { Service: 'Powertools-for-AWS-e2e-tests', }, }); + let lastCreateLog = 0; + let lastDestroyLog = 0; + const creationDeleteLogFrequency = 10000; // 10 seconds + const that = this; this.#cli = new Toolkit({ color: false, ioHost: { + /** + * Log messages to the console depending on the log level. + * + * If the `RUNNER_DEBUG` environment variable is set to `1`, all messages are logged. + * + * Otherwise, we log messages that are either warnings or errors as well as periodic + * updates on the stack creation and destruction process. + * + * @param msg - Message to log sent by the CDK CLI + */ async notify(msg) { + if (process.env.RUNNER_DEBUG === '1') { + testConsole.log(msg); + return; + } + if (msg.message.includes('destroyed') && msg.message.includes('✅')) { + testConsole.log(msg.message); + return; + } + if (msg.message.includes('✅') && !msg.message.includes('deployed')) { + testConsole.log(`${that.testName} deployed successfully`); + return; + } + if (msg.message.includes('CREATE_IN_PROGRESS')) { + if (Date.now() - lastCreateLog < creationDeleteLogFrequency) { + return; + } + lastCreateLog = Date.now(); + testConsole.log(`${that.testName} stack is being created...`); + return; + } + if (msg.message.includes('DELETE_IN_PROGRESS')) { + if (Date.now() - lastDestroyLog < creationDeleteLogFrequency) { + return; + } + lastDestroyLog = Date.now(); + testConsole.log(`${that.testName} stack is being destroyed...`); + return; + } + if (['warning', 'error'].includes(msg.level)) { + testConsole.log(msg); + } + }, + async requestResponse(msg) { if ( process.env.RUNNER_DEBUG === '1' || ['warning', 'error'].includes(msg.level) ) { testConsole.log(msg); } - }, - async requestResponse(msg) { - testConsole.log(msg); return msg.defaultResponse; }, },