You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/contributing/testing.md
+9-20Lines changed: 9 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,17 +13,7 @@ Tests are defined alongside the code they test, and can be found under the `test
13
13
14
14
Each test type has its own folder, and each test file is named after the feature it tests. For example, the tests for the `@aws-lambda-powertools/logger` module can be found under `packages/logger/tests/unit` and `packages/logger/tests/e2e`.
15
15
16
-
Tests are written using [Jest](https://jestjs.io) and are grouped into categories. You can run each group separately or all together thanks to [jest-runner-groups](https://www.npmjs.com/package/jest-runner-groups).
17
-
18
-
Each test file needs to be tagged with the proper group, otherwise, it won't be executed. The group is defined in the header of the file, and it follows this convention:
19
-
20
-
```typescript
21
-
/**
22
-
* Tests metrics
23
-
*
24
-
* @group unit/<YOUR CATEGORY>/<YOUR SUB CATEGORY>
25
-
*/
26
-
```
16
+
Tests use [Vitest](http://vitest.dev) as test runner and are grouped by packages and type. You can run each group separately or all together by passing extra arguments to the test command.
27
17
28
18
The test file should contain one or more tests organized using the `describe` and `it` functions. Each test should be named after the feature it tests, and should be as descriptive as possible. For example, the test for the `Logger` class `info` method is named `should log info message`.
29
19
@@ -67,7 +57,6 @@ To run unit tests, you can use of the following commands from the root folder:
67
57
*`npm test -ws` to run all the unit tests for all the modules sequentially
68
58
*`npm run test:parallel` to run all the unit tests for all the modules in parallel
69
59
*`npm test -w packages/metrics` to run all the unit tests for the `metrics` module
70
-
*`npm run jest -w packages/metrics -- --group=unit/metrics/middleware` to run all the unit tests for the `metrics` module that are tagged with the `unit/metrics/middleware` group
71
60
72
61
We enforce 100% code coverage for unit tests. The test command will fail if the coverage is not 100% both on your local machine and in CI.
73
62
@@ -93,12 +82,12 @@ Below is a diagram that shows the flow of the integration tests:
Copy file name to clipboardExpand all lines: docs/core/logger.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -828,18 +828,20 @@ When you extend the default JSON serializer, we will call your custom serializer
828
828
829
829
When unit testing your code that makes use of `logger.addContext()` or `injectLambdaContext` middleware and decorator, you can optionally pass a dummy Lambda Context if you want your logs to contain this information.
830
830
831
-
This is a Jest sample that provides the minimum information necessary for Logger to inject context data:
831
+
This is a sample that provides the minimum information necessary for Logger to inject context data:
832
832
833
833
=== "handler.test.ts"
834
834
835
835
```typescript
836
836
--8<-- "examples/snippets/logger/unitTesting.ts"
837
837
```
838
838
839
-
### Suppress logs with Jest
839
+
### Suppress logs
840
840
841
-
When unit testing your code with [Jest](https://jestjs.io) you can use the `POWERTOOLS_DEV` environment variable in conjunction with the Jest`--silent` CLI option to suppress logs from Logger.
841
+
When unit testing your code with [Jest](https://jestjs.io)or [Vitest](http://vitest.dev)you can use the `POWERTOOLS_DEV` environment variable in conjunction with the `--silent` CLI option to suppress logs from Logger.
842
842
843
-
```bash title="Disabling logs while testing with Jest"
844
-
export POWERTOOLS_DEV=true && npx jest --silent
843
+
```bash title="Disabling logs while testing with Vitest"
844
+
export POWERTOOLS_DEV=true && npx vitest --silent
845
845
```
846
+
847
+
Alternatively, you can also set the `POWERTOOLS_DEV` environment variable to `true` in your test setup file, or in a hoisted block at the top of your test file.
When running your tests with both [Jest](https://jestjs.io) and [Vitest](http://vitest.dev), you can use the `--silent` flag to silence the logs emitted by the utility.
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -832,21 +832,21 @@ The idempotency utility provides several routes to test your code.
832
832
833
833
### Disabling the idempotency utility
834
834
835
-
When testing your code, you may wish to disable the idempotency logic altogether and focus on testing your business logic. To do this, you can set the environment variable POWERTOOLS_IDEMPOTENCY_DISABLED with a truthy value.
835
+
When testing your code, you may wish to disable the idempotency logic altogether and focus on testing your business logic. To do this, you can set the environment variable `POWERTOOLS_IDEMPOTENCY_DISABLED` with a truthy value.
836
836
837
837
### Testing with local DynamoDB
838
838
839
839
When testing your Lambda function locally, you can use a local DynamoDB instance to test the idempotency feature. You can use [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html) or [LocalStack](https://localstack.cloud/){target="_blank"}.
Copy file name to clipboardExpand all lines: docs/utilities/parameters.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -450,11 +450,11 @@ The **`clientConfig`** parameter enables you to pass in a custom [config object]
450
450
451
451
### Mocking parameter values
452
452
453
-
For unit testing your applications, you can mock the calls to the parameters utility to avoid calling AWS APIs. This can be achieved in a number of ways - in this example, we use [Jest mock functions](https://jestjs.io/docs/es6-class-mocks#the-4-ways-to-create-an-es6-class-mock) to patch the `getParameters` function.
453
+
For unit testing your applications, you can mock the calls to the parameters utility to avoid calling AWS APIs. This can be achieved in a number of ways - in this example, we mock the module import to patch the `getParameters` function.
@@ -464,23 +464,23 @@ For unit testing your applications, you can mock the calls to the parameters uti
464
464
465
465
With this pattern in place, you can customize the return values of the mocked function to test different scenarios without calling AWS APIs.
466
466
467
-
A similar pattern can be applied also to any of the built-in provider classes - in this other example, we use [Jest spyOn method](https://jestjs.io/docs/es6-class-mocks#mocking-a-specific-method-of-a-class) to patch the `get` function of the `AppConfigProvider` class. This is useful also when you want to test that the correct arguments are being passed to the Parameters utility.
467
+
A similar pattern can be applied also to any of the built-in provider classes - in this other example, we use spies to patch the `get` function of the `AppConfigProvider` class. This is useful also when you want to test that the correct arguments are being passed to the Parameters utility.
For when you want to mock the AWS SDK v3 client directly, we recommend using the [`aws-sdk-client-mock`](https://www.npmjs.com/package/aws-sdk-client-mock) and [`aws-sdk-client-mock-jest`](https://www.npmjs.com/package/aws-sdk-client-mock-jest) libraries. This is useful when you want to test how your code behaves when the AWS SDK v3 client throws an error or a specific response.
479
+
For when you want to mock the AWS SDK v3 client directly, we recommend using the [`aws-sdk-client-mock`](https://www.npmjs.com/package/aws-sdk-client-mock) and [`aws-sdk-client-mock-vitest`](https://www.npmjs.com/package/aws-sdk-client-mock-vitest) libraries. This is useful when you want to test how your code behaves when the AWS SDK v3 client throws an error or a specific response.
@@ -495,6 +495,6 @@ Parameters utility caches all parameter values for performance and cost reasons.
495
495
Within your tests, you can use `clearCache` method available in [every provider](#built-in-provider-class). When using multiple providers or higher level functions like `getParameter`, use the `clearCaches` standalone function to clear cache globally.
0 commit comments