Skip to content

test(idempotency): switch e2e tests to vitest #3149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions packages/idempotency/jest.config.cjs

This file was deleted.

11 changes: 6 additions & 5 deletions packages/idempotency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"access": "public"
},
"scripts": {
"test": "vitest --run",
"test:unit": "vitest --run",
"test": "vitest --run tests/unit",
"test:unit": "vitest --run tests/unit",
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
"test:unit:types": "echo 'Not Implemented'",
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
"test:e2e:nodejs20x": "RUNTIME=nodejs20x jest --group=e2e",
"test:e2e": "jest --group=e2e",
"test:unit:watch": "vitest tests/unit",
"test:e2e:nodejs18x": "RUNTIME=nodejs18x vitest --run tests/e2e",
"test:e2e:nodejs20x": "RUNTIME=nodejs20x vitest --run tests/e2e",
"test:e2e": "vitest --run tests/e2e",
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
"build": "npm run build:esm & npm run build:cjs",
Expand Down
30 changes: 13 additions & 17 deletions packages/idempotency/tests/e2e/idempotentDecorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Test idempotency decorator
*
* @group e2e/idempotency/decorator
*/
import { createHash } from 'node:crypto';
import { join } from 'node:path';
import {
Expand All @@ -14,6 +9,7 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
import { Duration } from 'aws-cdk-lib';
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down Expand Up @@ -166,8 +162,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
tableNameDataIndex = testStack.findAndGetStackOutputValue('dataIndexTable');
}, SETUP_TIMEOUT);

test(
'when called twice with the same payload, it returns the same result and runs the handler once',
it(
'returns the same result and runs the handler once when called multiple times',
async () => {
const payload = { foo: 'bar' };

Expand Down Expand Up @@ -208,8 +204,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
TEST_CASE_TIMEOUT
);

test(
'when called twice in parallel, the handler is called only once',
it(
'handles parallel invocations correctly',
async () => {
const payload = { foo: 'bar' };
const payloadHash = createHash('md5')
Expand Down Expand Up @@ -256,8 +252,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
TEST_CASE_TIMEOUT
);

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

test(
'when the idempotency record is expired, the second request is processed correctly by the handler',
it(
'recovers from an expired idempotency record and processes the next request',
async () => {
const payload = {
foo: 'baz',
Expand Down Expand Up @@ -385,8 +381,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
TEST_CASE_TIMEOUT
);

test(
'when called with customized function wrapper, it creates ddb entry with custom attributes',
it(
'uses the provided custom idempotency record attributes',
async () => {
const payload = { foo: 'bar' };
const payloadHash = createHash('md5')
Expand Down Expand Up @@ -425,8 +421,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
TEST_CASE_TIMEOUT
);

test(
'when called twice for with different payload using data index arugment, it returns the same result and runs the handler once',
it(
'takes the data index argument into account when making the function idempotent',
async () => {
const payload = [{ id: '1234' }, { id: '5678' }];
const payloadHash = createHash('md5')
Expand Down
22 changes: 9 additions & 13 deletions packages/idempotency/tests/e2e/makeHandlerIdempotent.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Test makeHandlerIdempotent middleware
*
* @group e2e/idempotency/makeHandlerIdempotent
*/
import { createHash } from 'node:crypto';
import { join } from 'node:path';
import {
Expand All @@ -13,6 +8,7 @@ import {
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
import { Duration } from 'aws-cdk-lib';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down Expand Up @@ -116,8 +112,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
tableNameExpired = testStack.findAndGetStackOutputValue('expiredTable');
}, SETUP_TIMEOUT);

test(
'when called twice with the same payload, it returns the same result and runs the handler once',
it(
'returns the same result and runs the handler once',
async () => {
// Prepare
const payload = {
Expand Down Expand Up @@ -166,8 +162,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
TEST_CASE_TIMEOUT
);

test(
'when two identical requests are sent in parallel, the handler is called only once',
it(
'handles idempotent requests sent in parallel',
async () => {
// Prepare
const payload = {
Expand Down Expand Up @@ -224,8 +220,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
TEST_CASE_TIMEOUT
);

test(
'when the function times out, the second request is processed correctly by the handler',
it(
'recovers from a timed out request and processes the second request correctly',
async () => {
// Prepare
const payload = {
Expand Down Expand Up @@ -287,8 +283,8 @@ describe('Idempotency E2E tests, middy middleware usage', () => {
TEST_CASE_TIMEOUT
);

test(
'when the idempotency record is expired, the second request is processed correctly by the handler',
it(
'recovers from an expired idempotency record and processes the subsequent request correctly',
async () => {
// Prepare
const payload = {
Expand Down
14 changes: 5 additions & 9 deletions packages/idempotency/tests/e2e/makeIdempotent.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Test makeIdempotent function
*
* @group e2e/idempotency/makeIdempotent
*/
import { createHash } from 'node:crypto';
import { join } from 'node:path';
import {
Expand All @@ -13,6 +8,7 @@ import {
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { IdempotencyTestNodejsFunctionAndDynamoTable } from '../helpers/resources.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down Expand Up @@ -167,8 +163,8 @@ describe('Idempotency E2E tests, wrapper function usage', () => {
TEST_CASE_TIMEOUT
);

test(
'when called with customized function wrapper, it creates ddb entry with custom attributes',
it(
'creates a DynamoDB item with the correct attributes',
async () => {
// Prepare
const payload = {
Expand Down Expand Up @@ -281,8 +277,8 @@ describe('Idempotency E2E tests, wrapper function usage', () => {
TEST_CASE_TIMEOUT
);

test(
'when called twice with the same payload, it returns the same result and runs the handler once',
it(
'calls the wrapped function once and always returns the same result when called multiple times',
async () => {
// Prepare
const payload = {
Expand Down