Skip to content

Commit 57601a6

Browse files
committed
chore(maintenance): extend e2e assertions
1 parent 7336b2d commit 57601a6

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

packages/idempotency/tests/e2e/idempotentDecorator.test.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1+
import { createHash } from 'node:crypto';
2+
import { join } from 'node:path';
3+
import {
4+
TestInvocationLogs,
5+
TestStack,
6+
invokeFunction,
7+
} from '@aws-lambda-powertools/testing-utils';
18
/**
29
* Test idempotency decorator
310
*
411
* @group e2e/idempotency/decorator
512
*/
613
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
14+
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
15+
import { Duration } from 'aws-cdk-lib';
16+
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
17+
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
718
import {
819
RESOURCE_NAME_PREFIX,
920
SETUP_TIMEOUT,
1021
TEARDOWN_TIMEOUT,
1122
TEST_CASE_TIMEOUT,
1223
} from './constants.js';
13-
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
14-
import { createHash } from 'node:crypto';
15-
import {
16-
invokeFunction,
17-
TestInvocationLogs,
18-
TestStack,
19-
} from '@aws-lambda-powertools/testing-utils';
20-
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
21-
import { join } from 'node:path';
22-
import { Duration } from 'aws-cdk-lib';
23-
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
2424

2525
const dynamoDBClient = new DynamoDBClient({});
2626

@@ -289,9 +289,15 @@ describe('Idempotency e2e test decorator, default settings', () => {
289289
});
290290
expect(idempotencyRecord.Items?.[0].status).toEqual('COMPLETED');
291291

292-
// During the first invocation the handler should be called, so the logs should contain 1 log
293-
expect(functionLogs[0]).toHaveLength(2);
294-
expect(functionLogs[0][0]).toContain('Task timed out after');
292+
try {
293+
// During the first invocation the handler should be called, so the logs should contain 1 log
294+
expect(functionLogs[0]).toHaveLength(2);
295+
expect(functionLogs[0][0]).toContain('Task timed out after');
296+
} catch {
297+
// During the first invocation the function should timeout so the logs should not contain any log and the report log should contain a timeout message
298+
expect(functionLogs[0]).toHaveLength(0);
299+
expect(logs[0].getReportLog()).toMatch(/Status: timeout$/);
300+
}
295301

296302
expect(functionLogs[1]).toHaveLength(1);
297303
expect(TestInvocationLogs.parseFunctionLog(functionLogs[1][0])).toEqual(

packages/testing/src/TestInvocationLogs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ class TestInvocationLogs {
109109
);
110110
}
111111

112+
/**
113+
* Return the log that contains the report of the function `REPORT RequestId`
114+
*/
115+
public getReportLog(): string {
116+
const endLogIndex = TestInvocationLogs.getReportLogIndex(this.logs);
117+
118+
return this.logs[endLogIndex];
119+
}
120+
112121
/**
113122
* Return the index of the log that contains `REPORT RequestId`
114123
* @param logs

0 commit comments

Comments
 (0)