Skip to content

Commit 4538d73

Browse files
authored
chore: migrate to vitest v3 (#3561)
1 parent e3f935c commit 4538d73

37 files changed

+405
-364
lines changed

examples/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"source-map-support": "^0.5.21",
3636
"tsx": "^4.19.2",
3737
"typescript": "^5.7.3",
38-
"vitest": "^2.0.5"
38+
"vitest": "^3.0.5"
3939
},
4040
"dependencies": {
4141
"@aws-lambda-powertools/batch": "^2.13.1",

layers/tests/unit/layer-publisher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ describe('Class: LayerPublisherStack', () => {
4040
Name: '/layers/powertools-layer-arn',
4141
Type: 'String',
4242
});
43-
});
43+
}, 120000);
4444
});

package-lock.json

Lines changed: 302 additions & 293 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@biomejs/biome": "^1.9.4",
5454
"@types/aws-lambda": "^8.10.147",
5555
"@types/node": "^22.12.0",
56-
"@vitest/coverage-v8": "^2.1.8",
56+
"@vitest/coverage-v8": "^3.0.5",
5757
"husky": "^9.1.7",
5858
"lerna": "8.1.2",
5959
"lint-staged": "^15.4.3",
@@ -65,7 +65,7 @@
6565
"typedoc-plugin-missing-exports": "^3.1.0",
6666
"typedoc-plugin-zod": "^1.3.1",
6767
"typescript": "^5.7.3",
68-
"vitest": "^2.0.5"
68+
"vitest": "^3.0.5"
6969
},
7070
"lint-staged": {
7171
"*.{js,ts}": "biome check --write",

packages/idempotency/tests/unit/persistence/DynamoDbPersistenceLayer.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ describe('Class: DynamoDBPersistenceLayer', () => {
5050

5151
afterEach(() => {
5252
vi.clearAllMocks();
53-
vi.resetAllMocks();
5453
client.reset();
5554
});
5655

@@ -306,9 +305,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
306305

307306
it('puts record in DynamoDB table when using payload validation', async () => {
308307
// Prepare
309-
vi.spyOn(persistenceLayer, 'isPayloadValidationEnabled').mockReturnValue(
310-
true
311-
);
308+
const persistenceLayerSpy = vi
309+
.spyOn(persistenceLayer, 'isPayloadValidationEnabled')
310+
.mockReturnValue(true);
312311
const status = IdempotencyRecordStatus.EXPIRED;
313312
const expiryTimestamp = 0;
314313
const record = new IdempotencyRecord({
@@ -344,6 +343,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
344343
ConditionExpression:
345344
'attribute_not_exists(#id) OR #expiry < :now OR (#status = :inprogress AND attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now_in_millis)',
346345
});
346+
persistenceLayerSpy.mockRestore();
347347
});
348348

349349
it('throws when called with a record that fails any condition', async () => {
@@ -353,6 +353,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
353353
status: IdempotencyRecordStatus.EXPIRED,
354354
expiryTimestamp: 0,
355355
});
356+
const expiration = Date.now();
356357
client.on(PutItemCommand).rejects(
357358
new ConditionalCheckFailedException({
358359
$metadata: {
@@ -363,7 +364,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
363364
Item: {
364365
id: { S: 'test-key' },
365366
status: { S: 'INPROGRESS' },
366-
expiration: { N: Date.now().toString() },
367+
expiration: { N: expiration.toString() },
367368
},
368369
})
369370
);
@@ -373,9 +374,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
373374
new IdempotencyItemAlreadyExistsError(
374375
`Failed to put record for already existing idempotency key: ${record.idempotencyKey}`,
375376
new IdempotencyRecord({
376-
idempotencyKey: record.idempotencyKey,
377-
status: IdempotencyRecordStatus.EXPIRED,
378-
expiryTimestamp: Date.now() / 1000 - 1,
377+
idempotencyKey: 'test-key',
378+
status: IdempotencyRecordStatus.INPROGRESS,
379+
expiryTimestamp: expiration,
379380
})
380381
)
381382
);
@@ -575,10 +576,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
575576

576577
it('uses the payload hash in the expression when payload validation is enabled', async () => {
577578
// Prepare
578-
vi.spyOn(
579-
persistenceLayer,
580-
'isPayloadValidationEnabled'
581-
).mockImplementation(() => true);
579+
const persistenceLayerSpy = vi
580+
.spyOn(persistenceLayer, 'isPayloadValidationEnabled')
581+
.mockImplementation(() => true);
582582
const expiryTimestamp = Date.now();
583583
const record = new IdempotencyRecord({
584584
idempotencyKey: dummyKey,
@@ -612,6 +612,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
612612
':validation_key': record.payloadHash,
613613
}),
614614
});
615+
persistenceLayerSpy.mockRestore();
615616
});
616617
});
617618

packages/logger/tests/unit/formatters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Formatters', () => {
107107
process.env = { ...ENVIRONMENT_VARIABLES };
108108
const mockDate = new Date(1466424490000);
109109
vi.useFakeTimers().setSystemTime(mockDate);
110-
vi.resetAllMocks();
110+
vi.clearAllMocks();
111111
unformattedAttributes.timestamp = mockDate;
112112
});
113113

packages/logger/tests/unit/initializeLogger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Log levels', () => {
77

88
beforeEach(() => {
99
process.env = { ...ENVIRONMENT_VARIABLES, POWERTOOLS_DEV: 'true' };
10-
vi.resetAllMocks();
10+
vi.clearAllMocks();
1111
});
1212

1313
it('uses the default service name when none is provided', () => {

packages/logger/tests/unit/injectLambdaContext.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Inject Lambda Context', () => {
2626
...ENVIRONMENT_VARIABLES,
2727
POWERTOOLS_DEV: 'true',
2828
};
29-
vi.resetAllMocks();
29+
vi.clearAllMocks();
3030
});
3131

3232
it('adds the context to log messages when the feature is enabled', () => {

packages/logger/tests/unit/logEvent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Log event', () => {
1818
POWERTOOLS_LOGGER_LOG_EVENT: 'true',
1919
POWERTOOLS_DEV: 'true',
2020
};
21-
vi.resetAllMocks();
21+
vi.clearAllMocks();
2222
});
2323

2424
it('logs the event with the correct log level and message', () => {

packages/logger/tests/unit/logLevels.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Log levels', () => {
3434

3535
beforeEach(() => {
3636
process.env = { ...ENVIRONMENT_VARIABLES, POWERTOOLS_DEV: 'true' };
37-
vi.resetAllMocks();
37+
vi.clearAllMocks();
3838
});
3939

4040
it('sets the correct log level when initialized with a log level', () => {

0 commit comments

Comments
 (0)