Skip to content

Commit 02b658a

Browse files
authored
test(parameters): migrate tests to vitest (#3304)
1 parent 003c654 commit 02b658a

27 files changed

+646
-860
lines changed

.github/workflows/reusable-run-linting-check-and-unit-tests.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
"packages/logger",
5050
"packages/tracer",
5151
"packages/parser",
52+
"packages/parameters",
5253
]
5354
fail-fast: false
5455
steps:
@@ -91,12 +92,10 @@ jobs:
9192
nodeVersion: ${{ matrix.version }}
9293
- name: Run linting
9394
run: |
94-
npm run lint -w packages/metrics \
95-
-w packages/parameters
95+
npm run lint -w packages/metrics
9696
- name: Run unit tests
9797
run: |
98-
npm t -w packages/metrics \
99-
-w packages/parameters
98+
npm t -w packages/metrics
10099
check-examples:
101100
runs-on: ubuntu-latest
102101
env:

.husky/pre-push

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
npm t \
2-
-w packages/metrics \
3-
-w packages/parameters
2+
-w packages/metrics
43

54
npx vitest --run \
65
--exclude tests/unit/layer-publisher.test.ts \

packages/parameters/jest.config.cjs

-35
This file was deleted.

packages/parameters/package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
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",
16-
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
17-
"test:e2e:nodejs20x": "RUNTIME=nodejs20x jest --group=e2e",
18-
"test:e2e": "jest --group=e2e",
19-
"watch": "jest --watch",
13+
"test": "vitest --run tests/unit",
14+
"test:unit": "vitest --run tests/unit",
15+
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
16+
"test:unit:types": "vitest --run tests/types --typecheck",
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/parameters/src/appconfig/AppConfigProvider.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,12 @@ class AppConfigProvider extends BaseProvider {
267267
/**
268268
* Retrieving multiple configurations is not supported by AWS AppConfig.
269269
*/
270-
public async getMultiple(path: string, _options?: unknown): Promise<void> {
270+
/* v8 ignore start */ public async getMultiple(
271+
path: string,
272+
_options?: unknown
273+
): Promise<void> {
271274
await super.getMultiple(path);
272-
}
275+
} /* v8 ignore stop */
273276

274277
/**
275278
* Retrieve a configuration from AWS AppConfig.

packages/parameters/src/secrets/SecretsProvider.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ class SecretsProvider extends BaseProvider {
208208
/**
209209
* Retrieving multiple parameter values is not supported with AWS Secrets Manager.
210210
*/
211-
public async getMultiple(path: string, _options?: unknown): Promise<void> {
211+
/* v8 ignore start */ public async getMultiple(
212+
path: string,
213+
_options?: unknown
214+
): Promise<void> {
212215
await super.getMultiple(path);
213-
}
216+
} /* v8 ignore stop */
214217

215218
/**
216219
* Retrieve a configuration from AWS Secrets Manager.

packages/parameters/tests/e2e/appConfigProvider.class.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test AppConfigProvider class
3-
*
4-
* @group e2e/parameters/appconfig/class
5-
*/
61
import { join } from 'node:path';
72
import {
83
TestInvocationLogs,
@@ -11,6 +6,7 @@ import {
116
} from '@aws-lambda-powertools/testing-utils';
127
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
138
import { toBase64 } from '@smithy/util-base64';
9+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1410
import { TestAppConfigWithProfiles } from '../helpers/resources.js';
1511
import {
1612
RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/dynamoDBProvider.class.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test DynamoDBProvider class
3-
*
4-
* @group e2e/parameters/dynamodb/class
5-
*/
61
import { join } from 'node:path';
72
import {
83
TestInvocationLogs,
@@ -11,6 +6,7 @@ import {
116
} from '@aws-lambda-powertools/testing-utils';
127
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
138
import { AttributeType } from 'aws-cdk-lib/aws-dynamodb';
9+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1410
import { TestDynamodbTableWithItems } from '../helpers/resources.js';
1511
import {
1612
RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/secretsProvider.class.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Test SecretsPorovider class
3-
*
4-
* @group e2e/parameters/secrets/class
5-
*/
61
import { join } from 'node:path';
72
import {
83
TestInvocationLogs,
@@ -11,6 +6,7 @@ import {
116
} from '@aws-lambda-powertools/testing-utils';
127
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
138
import { SecretValue } from 'aws-cdk-lib';
9+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1410
import { TestSecret } from '../helpers/resources.js';
1511
import {
1612
RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/ssmProvider.class.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
/**
2-
* Test SSMProvider class
3-
*
4-
* @group e2e/parameters/ssm/class
5-
*/
61
import { join } from 'node:path';
72
import {
83
TestInvocationLogs,
94
TestStack,
105
invokeFunctionOnce,
116
} from '@aws-lambda-powertools/testing-utils';
127
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
8+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
139
import {
1410
TestSecureStringParameter,
1511
TestStringParameter,

packages/parameters/tests/helpers/populateEnvironmentVariables.ts

-11
This file was deleted.
+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
4-
"rootDir": "../",
4+
"rootDir": "../../",
55
"noEmit": true
66
},
7-
"include": ["../src/**/*", "./**/*"]
8-
}
7+
"include": [
8+
"../../testing/src/setupEnv.ts",
9+
"../src/**/*",
10+
"./**/*",
11+
]
12+
}

0 commit comments

Comments
 (0)