Skip to content

Commit 937c716

Browse files
committed
chore(batch): move tests to vitest
1 parent c6ccb3a commit 937c716

12 files changed

+101
-262
lines changed

packages/batch/jest.config.cjs

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/batch/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"access": "public"
1111
},
1212
"scripts": {
13-
"test": "npm run test:unit",
14-
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
15-
"jest": "jest --detectOpenHandles --verbose",
13+
"test": "vitest --run",
14+
"test:unit": "vitest --run",
1615
"test:e2e:nodejs18x": "echo 'Not Implemented'",
1716
"test:e2e:nodejs20x": "echo 'Not Implemented'",
1817
"test:e2e": "echo 'Not Implemented'",
@@ -75,4 +74,4 @@
7574
"devDependencies": {
7675
"@aws-lambda-powertools/testing-utils": "file:../testing"
7776
}
78-
}
77+
}

packages/batch/tests/helpers/populateEnvironmentVariables.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/batch/tests/unit/BasePartialProcessor.test.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* Test BasePartialBatchProcessor class
3-
*
4-
* @group unit/batch/class/basepartialbatchprocessor
5-
*/
1+
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
62
import { BasePartialBatchProcessor, EventType } from '../../src/index.js';
73
import type {
84
BaseRecord,
@@ -16,8 +12,7 @@ describe('Class: BasePartialBatchProcessor', () => {
1612
const ENVIRONMENT_VARIABLES = process.env;
1713

1814
beforeEach(() => {
19-
jest.clearAllMocks();
20-
jest.resetModules();
15+
vi.clearAllMocks();
2116
process.env = { ...ENVIRONMENT_VARIABLES };
2217
});
2318

@@ -46,19 +41,19 @@ describe('Class: BasePartialBatchProcessor', () => {
4641
}
4742

4843
describe('create custom batch partial processor', () => {
49-
it('should create a custom batch partial processor', () => {
44+
it('creates a custom batch partial processor', () => {
5045
// Act
5146
const processor = new MyPartialProcessor();
5247

5348
// Assess
5449
expect(processor).toBeInstanceOf(BasePartialBatchProcessor);
5550
});
5651

57-
it('should process a batch of records', () => {
52+
it('processes a batch of records', () => {
5853
// Prepare
5954
const processor = new MyPartialProcessor();
6055
const records = [sqsRecordFactory('success')];
61-
const consoleSpy = jest.spyOn(console, 'log');
56+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
6257

6358
// Act
6459
processor.register(records, sqsRecordHandler);

packages/batch/tests/unit/BatchProcessor.test.ts

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/**
2-
* Test BatchProcessor class
3-
*
4-
* @group unit/batch/class/batchprocessor
5-
*/
61
import context from '@aws-lambda-powertools/testing-utils/context';
72
import type { Context } from 'aws-lambda';
3+
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
84
import {
95
BatchProcessingError,
106
BatchProcessor,
@@ -31,8 +27,7 @@ describe('Class: AsyncBatchProcessor', () => {
3127
};
3228

3329
beforeEach(() => {
34-
jest.clearAllMocks();
35-
jest.resetModules();
30+
vi.clearAllMocks();
3631
process.env = { ...ENVIRONMENT_VARIABLES };
3732
});
3833

@@ -41,7 +36,7 @@ describe('Class: AsyncBatchProcessor', () => {
4136
});
4237

4338
describe('Asynchronously processing SQS Records', () => {
44-
test('Batch processing SQS records with no failures', async () => {
39+
it('completes processing with no failures', async () => {
4540
// Prepare
4641
const firstRecord = sqsRecordFactory('success');
4742
const secondRecord = sqsRecordFactory('success');
@@ -59,7 +54,7 @@ describe('Class: AsyncBatchProcessor', () => {
5954
]);
6055
});
6156

62-
test('Batch processing SQS records with some failures', async () => {
57+
it('completes processing with with some failures', async () => {
6358
// Prepare
6459
const firstRecord = sqsRecordFactory('failure');
6560
const secondRecord = sqsRecordFactory('success');
@@ -86,7 +81,7 @@ describe('Class: AsyncBatchProcessor', () => {
8681
});
8782
});
8883

89-
test('Batch processing SQS records with all failures', async () => {
84+
it('completes processing with all failures', async () => {
9085
// Prepare
9186
const firstRecord = sqsRecordFactory('failure');
9287
const secondRecord = sqsRecordFactory('failure');
@@ -106,7 +101,7 @@ describe('Class: AsyncBatchProcessor', () => {
106101
});
107102

108103
describe('Asynchronously processing Kinesis Records', () => {
109-
test('Batch processing Kinesis records with no failures', async () => {
104+
it('completes processing with no failures', async () => {
110105
// Prepare
111106
const firstRecord = kinesisRecordFactory('success');
112107
const secondRecord = kinesisRecordFactory('success');
@@ -124,7 +119,7 @@ describe('Class: AsyncBatchProcessor', () => {
124119
]);
125120
});
126121

127-
test('Batch processing Kinesis records with some failures', async () => {
122+
it('completes processing with some failures', async () => {
128123
// Prepare
129124
const firstRecord = kinesisRecordFactory('failure');
130125
const secondRecord = kinesisRecordFactory('success');
@@ -151,7 +146,7 @@ describe('Class: AsyncBatchProcessor', () => {
151146
});
152147
});
153148

154-
test('Batch processing Kinesis records with all failures', async () => {
149+
it('completes processing with all failures', async () => {
155150
// Prepare
156151
const firstRecord = kinesisRecordFactory('failure');
157152
const secondRecord = kinesisRecordFactory('failure');
@@ -171,7 +166,7 @@ describe('Class: AsyncBatchProcessor', () => {
171166
});
172167

173168
describe('Asynchronously processing DynamoDB Records', () => {
174-
test('Batch processing DynamoDB records with no failures', async () => {
169+
it('completes processing with no failures', async () => {
175170
// Prepare
176171
const firstRecord = dynamodbRecordFactory('success');
177172
const secondRecord = dynamodbRecordFactory('success');
@@ -189,7 +184,7 @@ describe('Class: AsyncBatchProcessor', () => {
189184
]);
190185
});
191186

192-
test('Batch processing DynamoDB records with some failures', async () => {
187+
it('completes processing with some failures', async () => {
193188
// Prepare
194189
const firstRecord = dynamodbRecordFactory('failure');
195190
const secondRecord = dynamodbRecordFactory('success');
@@ -216,7 +211,7 @@ describe('Class: AsyncBatchProcessor', () => {
216211
});
217212
});
218213

219-
test('Batch processing DynamoDB records with all failures', async () => {
214+
it('completes processing with all failures', async () => {
220215
// Prepare
221216
const firstRecord = dynamodbRecordFactory('failure');
222217
const secondRecord = dynamodbRecordFactory('failure');
@@ -236,7 +231,7 @@ describe('Class: AsyncBatchProcessor', () => {
236231
});
237232

238233
describe('Batch processing with Lambda context', () => {
239-
test('Batch processing when context is provided and handler accepts', async () => {
234+
it('passes the context to the record handler', async () => {
240235
// Prepare
241236
const firstRecord = sqsRecordFactory('success');
242237
const secondRecord = sqsRecordFactory('success');
@@ -254,25 +249,7 @@ describe('Class: AsyncBatchProcessor', () => {
254249
]);
255250
});
256251

257-
test('Batch processing when context is provided and handler does not accept', async () => {
258-
// Prepare
259-
const firstRecord = sqsRecordFactory('success');
260-
const secondRecord = sqsRecordFactory('success');
261-
const records = [firstRecord, secondRecord];
262-
const processor = new BatchProcessor(EventType.SQS);
263-
264-
// Act
265-
processor.register(records, asyncSqsRecordHandler, options);
266-
const processedMessages = await processor.process();
267-
268-
// Assess
269-
expect(processedMessages).toStrictEqual([
270-
['success', firstRecord.body, firstRecord],
271-
['success', secondRecord.body, secondRecord],
272-
]);
273-
});
274-
275-
test('Batch processing when malformed context is provided and handler attempts to use', async () => {
252+
it('throws an error when passing an invalid context object', async () => {
276253
// Prepare
277254
const firstRecord = sqsRecordFactory('success');
278255
const secondRecord = sqsRecordFactory('success');
@@ -289,7 +266,7 @@ describe('Class: AsyncBatchProcessor', () => {
289266
});
290267
});
291268

292-
test('When calling the sync process method, it should throw an error', () => {
269+
it('throws an error when the sync process method is called', () => {
293270
// Prepare
294271
const processor = new BatchProcessor(EventType.SQS);
295272

packages/batch/tests/unit/BatchProcessorSync.test.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/**
2-
* Test BatchProcessorSync class
3-
*
4-
* @group unit/batch/class/batchprocessorsync
5-
*/
61
import context from '@aws-lambda-powertools/testing-utils/context';
72
import type { Context } from 'aws-lambda';
3+
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
84
import {
95
BatchProcessingError,
106
BatchProcessorSync,
@@ -31,8 +27,7 @@ describe('Class: BatchProcessor', () => {
3127
};
3228

3329
beforeEach(() => {
34-
jest.clearAllMocks();
35-
jest.resetModules();
30+
vi.clearAllMocks();
3631
process.env = { ...ENVIRONMENT_VARIABLES };
3732
});
3833

@@ -41,7 +36,7 @@ describe('Class: BatchProcessor', () => {
4136
});
4237

4338
describe('Synchronously processing SQS Records', () => {
44-
test('Batch processing SQS records with no failures', () => {
39+
it('Batch processing SQS records with no failures', () => {
4540
// Prepare
4641
const firstRecord = sqsRecordFactory('success');
4742
const secondRecord = sqsRecordFactory('success');
@@ -59,7 +54,7 @@ describe('Class: BatchProcessor', () => {
5954
]);
6055
});
6156

62-
test('Batch processing SQS records with some failures', () => {
57+
it('Batch processing SQS records with some failures', () => {
6358
// Prepare
6459
const firstRecord = sqsRecordFactory('failure');
6560
const secondRecord = sqsRecordFactory('success');
@@ -86,7 +81,7 @@ describe('Class: BatchProcessor', () => {
8681
});
8782
});
8883

89-
test('Batch processing SQS records with all failures', () => {
84+
it('Batch processing SQS records with all failures', () => {
9085
// Prepare
9186
const firstRecord = sqsRecordFactory('failure');
9287
const secondRecord = sqsRecordFactory('failure');
@@ -102,7 +97,7 @@ describe('Class: BatchProcessor', () => {
10297
});
10398

10499
describe('Synchronously processing Kinesis Records', () => {
105-
test('Batch processing Kinesis records with no failures', () => {
100+
it('Batch processing Kinesis records with no failures', () => {
106101
// Prepare
107102
const firstRecord = kinesisRecordFactory('success');
108103
const secondRecord = kinesisRecordFactory('success');
@@ -120,7 +115,7 @@ describe('Class: BatchProcessor', () => {
120115
]);
121116
});
122117

123-
test('Batch processing Kinesis records with some failures', () => {
118+
it('Batch processing Kinesis records with some failures', () => {
124119
// Prepare
125120
const firstRecord = kinesisRecordFactory('failure');
126121
const secondRecord = kinesisRecordFactory('success');
@@ -147,7 +142,7 @@ describe('Class: BatchProcessor', () => {
147142
});
148143
});
149144

150-
test('Batch processing Kinesis records with all failures', () => {
145+
it('Batch processing Kinesis records with all failures', () => {
151146
const firstRecord = kinesisRecordFactory('failure');
152147
const secondRecord = kinesisRecordFactory('failure');
153148
const thirdRecord = kinesisRecordFactory('fail');
@@ -164,7 +159,7 @@ describe('Class: BatchProcessor', () => {
164159
});
165160

166161
describe('Synchronously processing DynamoDB Records', () => {
167-
test('Batch processing DynamoDB records with no failures', () => {
162+
it('Batch processing DynamoDB records with no failures', () => {
168163
// Prepare
169164
const firstRecord = dynamodbRecordFactory('success');
170165
const secondRecord = dynamodbRecordFactory('success');
@@ -182,7 +177,7 @@ describe('Class: BatchProcessor', () => {
182177
]);
183178
});
184179

185-
test('Batch processing DynamoDB records with some failures', () => {
180+
it('Batch processing DynamoDB records with some failures', () => {
186181
// Prepare
187182
const firstRecord = dynamodbRecordFactory('failure');
188183
const secondRecord = dynamodbRecordFactory('success');
@@ -209,7 +204,7 @@ describe('Class: BatchProcessor', () => {
209204
});
210205
});
211206

212-
test('Batch processing DynamoDB records with all failures', () => {
207+
it('Batch processing DynamoDB records with all failures', () => {
213208
// Prepare
214209
const firstRecord = dynamodbRecordFactory('failure');
215210
const secondRecord = dynamodbRecordFactory('failure');
@@ -227,7 +222,7 @@ describe('Class: BatchProcessor', () => {
227222
});
228223

229224
describe('Batch processing with Lambda context', () => {
230-
test('Batch processing when context is provided and handler accepts', () => {
225+
it('Batch processing when context is provided and handler accepts', () => {
231226
// Prepare
232227
const firstRecord = sqsRecordFactory('success');
233228
const secondRecord = sqsRecordFactory('success');
@@ -245,7 +240,7 @@ describe('Class: BatchProcessor', () => {
245240
]);
246241
});
247242

248-
test('Batch processing when context is provided and handler does not accept', () => {
243+
it('Batch processing when context is provided and handler does not accept', () => {
249244
// Prepare
250245
const firstRecord = sqsRecordFactory('success');
251246
const secondRecord = sqsRecordFactory('success');
@@ -263,7 +258,7 @@ describe('Class: BatchProcessor', () => {
263258
]);
264259
});
265260

266-
test('Batch processing when malformed context is provided and handler attempts to use', () => {
261+
it('Batch processing when malformed context is provided and handler attempts to use', () => {
267262
// Prepare
268263
const firstRecord = sqsRecordFactory('success');
269264
const secondRecord = sqsRecordFactory('success');
@@ -274,11 +269,13 @@ describe('Class: BatchProcessor', () => {
274269

275270
// Act
276271
processor.register(records, handlerWithContext, badOptions);
272+
273+
// Assess
277274
expect(() => processor.processSync()).toThrowError(FullBatchFailureError);
278275
});
279276
});
280277

281-
test('When calling the async process method, it should throw an error', async () => {
278+
it('throws an error when calling the async method', async () => {
282279
// Prepare
283280
const processor = new BatchProcessorSync(EventType.SQS);
284281

0 commit comments

Comments
 (0)