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

+1-1
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

+1-1
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

+302-293
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
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

+13-12
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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', () => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Working with keys', () => {
1414
...ENVIRONMENT_VARIABLES,
1515
POWERTOOLS_DEV: 'true',
1616
};
17-
vi.resetAllMocks();
17+
vi.clearAllMocks();
1818
});
1919

2020
it.each([

packages/metrics/tests/unit/coldStartMetric.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('ColdStart metric', () => {
1111
POWERTOOLS_DEV: 'true',
1212
POWERTOOLS_METRICS_DISABLED: 'false',
1313
};
14-
vi.resetAllMocks();
14+
vi.clearAllMocks();
1515
});
1616

1717
it('emits a cold start metric', () => {

packages/metrics/tests/unit/creatingMetrics.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Creating metrics', () => {
1515
POWERTOOLS_DEV: 'true',
1616
POWERTOOLS_METRICS_DISABLED: 'false',
1717
};
18-
vi.resetAllMocks();
18+
vi.clearAllMocks();
1919
});
2020

2121
it('creates a compliant CloudWatch EMF metric', () => {

packages/metrics/tests/unit/customTimestamp.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Setting custom timestamp', () => {
1515
POWERTOOLS_DEV: 'true',
1616
POWERTOOLS_METRICS_DISABLED: 'false',
1717
};
18-
vi.resetAllMocks();
18+
vi.clearAllMocks();
1919
vi.useFakeTimers().setSystemTime(new Date());
2020
});
2121

packages/metrics/tests/unit/dimensions.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Working with dimensions', () => {
1111
POWERTOOLS_DEV: 'true',
1212
POWERTOOLS_METRICS_DISABLED: 'false',
1313
};
14-
vi.resetAllMocks();
14+
vi.clearAllMocks();
1515
});
1616

1717
it('adds default dimensions to the metric via constructor', () => {

packages/metrics/tests/unit/initializeMetrics.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Initialize Metrics', () => {
1212
POWERTOOLS_DEV: 'true',
1313
POWERTOOLS_METRICS_DISABLED: 'false',
1414
};
15-
vi.resetAllMocks();
15+
vi.clearAllMocks();
1616
});
1717

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

packages/metrics/tests/unit/logMetrics.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('LogMetrics decorator & Middy.js middleware', () => {
1515
POWERTOOLS_DEV: 'true',
1616
POWERTOOLS_METRICS_DISABLED: 'false',
1717
};
18-
vi.resetAllMocks();
18+
vi.clearAllMocks();
1919
});
2020

2121
it('captures the cold start metric on the first invocation', async () => {

packages/metrics/tests/unit/metadata.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Working with metadata', () => {
1010
POWERTOOLS_DEV: 'true',
1111
POWERTOOLS_METRICS_DISABLED: 'false',
1212
};
13-
vi.resetAllMocks();
13+
vi.clearAllMocks();
1414
});
1515

1616
it('adds metadata to the metric', () => {

packages/parameters/tests/unit/AppConfigProvider.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ describe('Class: AppConfigProvider', () => {
6060
const provider = new AppConfigProvider(options);
6161

6262
// Assess
63-
expect(provider.client.config.region()).resolves.toEqual('eu-south-2');
63+
await expect(provider.client.config.region()).resolves.toEqual(
64+
'eu-south-2'
65+
);
6466
expect(addUserAgentMiddleware).toHaveBeenCalled();
6567
});
6668

@@ -96,7 +98,6 @@ describe('Class: AppConfigProvider', () => {
9698
environment: 'MyAppProdEnv',
9799
awsSdkV3Client: awsSdkV3Client as AppConfigDataClient,
98100
};
99-
const consoleWarnSpy = vi.spyOn(console, 'warn');
100101

101102
// Act
102103
const provider = new AppConfigProvider(options);
@@ -107,7 +108,7 @@ describe('Class: AppConfigProvider', () => {
107108
serviceId: 'AppConfigData',
108109
})
109110
);
110-
expect(consoleWarnSpy).toHaveBeenNthCalledWith(
111+
expect(console.warn).toHaveBeenNthCalledWith(
111112
1,
112113
'awsSdkV3Client is not an AWS SDK v3 client, using default client'
113114
);

packages/parameters/tests/unit/DynamoDBProvider.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ describe('Class: DynamoDBProvider', () => {
5858
const provider = new DynamoDBProvider(options);
5959

6060
// Assess
61-
expect(provider.client.config.region()).resolves.toEqual('eu-south-2');
61+
await expect(provider.client.config.region()).resolves.toEqual(
62+
'eu-south-2'
63+
);
6264
expect(addUserAgentMiddleware).toHaveBeenCalled();
6365
});
6466

@@ -92,7 +94,6 @@ describe('Class: DynamoDBProvider', () => {
9294
tableName: 'test-table',
9395
awsSdkV3Client: awsSdkV3Client as DynamoDBClient,
9496
};
95-
const consoleWarnSpy = vi.spyOn(console, 'warn');
9697

9798
// Act
9899
const provider = new DynamoDBProvider(options);
@@ -103,7 +104,7 @@ describe('Class: DynamoDBProvider', () => {
103104
serviceId: 'DynamoDB',
104105
})
105106
);
106-
expect(consoleWarnSpy).toHaveBeenNthCalledWith(
107+
expect(console.warn).toHaveBeenNthCalledWith(
107108
1,
108109
'awsSdkV3Client is not an AWS SDK v3 client, using default client'
109110
);

packages/parameters/tests/unit/SSMProvider.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ describe('Class: SSMProvider', () => {
6464
const provider = new SSMProvider(options);
6565

6666
// Assess
67-
expect(provider.client.config.region()).resolves.toEqual('eu-south-2');
67+
await expect(provider.client.config.region()).resolves.toEqual(
68+
'eu-south-2'
69+
);
6870
expect(addUserAgentMiddleware).toHaveBeenCalled();
6971
});
7072

@@ -96,7 +98,6 @@ describe('Class: SSMProvider', () => {
9698
const options: SSMProviderOptions = {
9799
awsSdkV3Client: awsSdkV3Client as SSMClient,
98100
};
99-
const consoleWarnSpy = vi.spyOn(console, 'warn');
100101

101102
// Act
102103
const provider = new SSMProvider(options);
@@ -107,7 +108,7 @@ describe('Class: SSMProvider', () => {
107108
serviceId: 'SSM',
108109
})
109110
);
110-
expect(consoleWarnSpy).toHaveBeenNthCalledWith(
111+
expect(console.warn).toHaveBeenNthCalledWith(
111112
1,
112113
'awsSdkV3Client is not an AWS SDK v3 client, using default client'
113114
);

packages/parameters/tests/unit/SecretsProvider.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ describe('Class: SecretsProvider', () => {
5151
const provider = new SecretsProvider(options);
5252

5353
// Assess
54-
expect(provider.client.config.region()).resolves.toEqual('eu-south-2');
54+
await expect(provider.client.config.region()).resolves.toEqual(
55+
'eu-south-2'
56+
);
5557
expect(addUserAgentMiddleware).toHaveBeenCalled();
5658
});
5759

@@ -83,7 +85,6 @@ describe('Class: SecretsProvider', () => {
8385
const options: SecretsProviderOptions = {
8486
awsSdkV3Client: awsSdkV3Client as SecretsManagerClient,
8587
};
86-
const consoleWarnSpy = vi.spyOn(console, 'warn');
8788

8889
// Act
8990
const provider = new SecretsProvider(options);
@@ -94,7 +95,7 @@ describe('Class: SecretsProvider', () => {
9495
serviceId: 'Secrets Manager',
9596
})
9697
);
97-
expect(consoleWarnSpy).toHaveBeenNthCalledWith(
98+
expect(console.warn).toHaveBeenNthCalledWith(
9899
1,
99100
'awsSdkV3Client is not an AWS SDK v3 client, using default client'
100101
);

packages/parser/tests/unit/envelopes/apigw.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('Envelope: API Gateway REST', () => {
108108
const result = ApiGatewayEnvelope.safeParse(event, schema);
109109

110110
// Assess
111-
expect(result).toEqual({
111+
expect(result).be.deep.equal({
112112
success: false,
113113
error: new ParseError('Failed to parse API Gateway body', {
114114
cause: new ZodError([

packages/parser/tests/unit/envelopes/apigwv2.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Envelope: API Gateway HTTP', () => {
109109
const result = ApiGatewayV2Envelope.safeParse(event, schema);
110110

111111
// Assess
112-
expect(result).toEqual({
112+
expect(result).be.deep.equal({
113113
success: false,
114114
error: new ParseError('Failed to parse API Gateway HTTP body', {
115115
cause: new ZodError([

packages/parser/tests/unit/envelopes/cloudwatch.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('Envelope: CloudWatch', () => {
203203
);
204204

205205
// Assess
206-
expect(result).toStrictEqual({
206+
expect(result).be.deep.equal({
207207
success: false,
208208
error: new ParseError(
209209
'Failed to parse CloudWatch Log message at index 0',
@@ -234,7 +234,7 @@ describe('Envelope: CloudWatch', () => {
234234
);
235235

236236
// Assess
237-
expect(result).toStrictEqual({
237+
expect(result).be.deep.equal({
238238
success: false,
239239
error: new ParseError(
240240
'Failed to parse CloudWatch Log messages at indexes 0, 1, 2',

0 commit comments

Comments
 (0)