Skip to content

Commit c97d379

Browse files
authored
test(idempotency): switch e2e tests to vitest (#3149)
1 parent 876a703 commit c97d379

File tree

5 files changed

+33
-75
lines changed

5 files changed

+33
-75
lines changed

packages/idempotency/jest.config.cjs

-31
This file was deleted.

packages/idempotency/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"access": "public"
1111
},
1212
"scripts": {
13-
"test": "vitest --run",
14-
"test:unit": "vitest --run",
13+
"test": "vitest --run tests/unit",
14+
"test:unit": "vitest --run tests/unit",
1515
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
1616
"test:unit:types": "echo 'Not Implemented'",
17-
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
18-
"test:e2e:nodejs20x": "RUNTIME=nodejs20x jest --group=e2e",
19-
"test:e2e": "jest --group=e2e",
17+
"test:unit:watch": "vitest tests/unit",
18+
"test:e2e:nodejs18x": "RUNTIME=nodejs18x vitest --run tests/e2e",
19+
"test:e2e:nodejs20x": "RUNTIME=nodejs20x vitest --run tests/e2e",
20+
"test:e2e": "vitest --run tests/e2e",
2021
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
2122
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
2223
"build": "npm run build:esm & npm run build:cjs",

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

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test idempotency decorator
3-
*
4-
* @group e2e/idempotency/decorator
5-
*/
61
import { createHash } from 'node:crypto';
72
import { join } from 'node:path';
83
import {
@@ -14,6 +9,7 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
149
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
1510
import { Duration } from 'aws-cdk-lib';
1611
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
12+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1713
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
1814
import {
1915
RESOURCE_NAME_PREFIX,
@@ -166,8 +162,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
166162
tableNameDataIndex = testStack.findAndGetStackOutputValue('dataIndexTable');
167163
}, SETUP_TIMEOUT);
168164

169-
test(
170-
'when called twice with the same payload, it returns the same result and runs the handler once',
165+
it(
166+
'returns the same result and runs the handler once when called multiple times',
171167
async () => {
172168
const payload = { foo: 'bar' };
173169

@@ -208,8 +204,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
208204
TEST_CASE_TIMEOUT
209205
);
210206

211-
test(
212-
'when called twice in parallel, the handler is called only once',
207+
it(
208+
'handles parallel invocations correctly',
213209
async () => {
214210
const payload = { foo: 'bar' };
215211
const payloadHash = createHash('md5')
@@ -256,8 +252,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
256252
TEST_CASE_TIMEOUT
257253
);
258254

259-
test(
260-
'when the function times out, the second request is processed correctly by the handler',
255+
it(
256+
'recovers from a timed out request and processes the next one',
261257
async () => {
262258
const payload = { foo: 'bar' };
263259
const payloadHash = createHash('md5')
@@ -311,8 +307,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
311307
TEST_CASE_TIMEOUT
312308
);
313309

314-
test(
315-
'when the idempotency record is expired, the second request is processed correctly by the handler',
310+
it(
311+
'recovers from an expired idempotency record and processes the next request',
316312
async () => {
317313
const payload = {
318314
foo: 'baz',
@@ -385,8 +381,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
385381
TEST_CASE_TIMEOUT
386382
);
387383

388-
test(
389-
'when called with customized function wrapper, it creates ddb entry with custom attributes',
384+
it(
385+
'uses the provided custom idempotency record attributes',
390386
async () => {
391387
const payload = { foo: 'bar' };
392388
const payloadHash = createHash('md5')
@@ -425,8 +421,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
425421
TEST_CASE_TIMEOUT
426422
);
427423

428-
test(
429-
'when called twice for with different payload using data index arugment, it returns the same result and runs the handler once',
424+
it(
425+
'takes the data index argument into account when making the function idempotent',
430426
async () => {
431427
const payload = [{ id: '1234' }, { id: '5678' }];
432428
const payloadHash = createHash('md5')

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

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test makeHandlerIdempotent middleware
3-
*
4-
* @group e2e/idempotency/makeHandlerIdempotent
5-
*/
61
import { createHash } from 'node:crypto';
72
import { join } from 'node:path';
83
import {
@@ -13,6 +8,7 @@ import {
138
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
149
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
1510
import { Duration } from 'aws-cdk-lib';
11+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1612
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
1713
import {
1814
RESOURCE_NAME_PREFIX,
@@ -116,8 +112,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
116112
tableNameExpired = testStack.findAndGetStackOutputValue('expiredTable');
117113
}, SETUP_TIMEOUT);
118114

119-
test(
120-
'when called twice with the same payload, it returns the same result and runs the handler once',
115+
it(
116+
'returns the same result and runs the handler once when called multiple times',
121117
async () => {
122118
// Prepare
123119
const payload = {
@@ -166,8 +162,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
166162
TEST_CASE_TIMEOUT
167163
);
168164

169-
test(
170-
'when two identical requests are sent in parallel, the handler is called only once',
165+
it(
166+
'handles parallel invocations correctly',
171167
async () => {
172168
// Prepare
173169
const payload = {
@@ -224,8 +220,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
224220
TEST_CASE_TIMEOUT
225221
);
226222

227-
test(
228-
'when the function times out, the second request is processed correctly by the handler',
223+
it(
224+
'recovers from a timed out request and processes the next one',
229225
async () => {
230226
// Prepare
231227
const payload = {
@@ -287,8 +283,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
287283
TEST_CASE_TIMEOUT
288284
);
289285

290-
test(
291-
'when the idempotency record is expired, the second request is processed correctly by the handler',
286+
it(
287+
'recovers from an expired idempotency record and processes the next request',
292288
async () => {
293289
// Prepare
294290
const payload = {

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test makeIdempotent function
3-
*
4-
* @group e2e/idempotency/makeIdempotent
5-
*/
61
import { createHash } from 'node:crypto';
72
import { join } from 'node:path';
83
import {
@@ -13,6 +8,7 @@ import {
138
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
149
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
1510
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
11+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1612
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
1713
import {
1814
RESOURCE_NAME_PREFIX,
@@ -167,8 +163,8 @@ describe('Idempotency E2E tests, wrapper function usage', () => {
167163
TEST_CASE_TIMEOUT
168164
);
169165

170-
test(
171-
'when called with customized function wrapper, it creates ddb entry with custom attributes',
166+
it(
167+
'creates a DynamoDB item with the correct attributes',
172168
async () => {
173169
// Prepare
174170
const payload = {
@@ -281,8 +277,8 @@ describe('Idempotency E2E tests, wrapper function usage', () => {
281277
TEST_CASE_TIMEOUT
282278
);
283279

284-
test(
285-
'when called twice with the same payload, it returns the same result and runs the handler once',
280+
it(
281+
'calls the wrapped function once and always returns the same result when called multiple times',
286282
async () => {
287283
// Prepare
288284
const payload = {

0 commit comments

Comments
 (0)