Skip to content

Commit 75bc904

Browse files
authored
chore: remove jest from codebase (#3379)
1 parent 0dc4de1 commit 75bc904

30 files changed

+422
-2895
lines changed

Diff for: .devcontainer/devcontainer.json

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// Add the ids of extensions you want installed when the container is created.
1616
"extensions": [
1717
"biomejs.biome",
18-
"firsttris.vscode-jest-runner",
1918
"vitest.explorer"
2019
],
2120
"vscode": {

Diff for: .github/boring-cyborg.yml

-11
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,24 @@ labelPRBasedOnFilePath:
4040
tests:
4141
- packages/logger/tests/*
4242
- packages/logger/tests/**/*
43-
- packages/logger/jest.config.cjs
4443
- packages/tracer/tests/*
4544
- packages/tracer/tests/**/*
46-
- packages/tracer/jest.config.cjs
4745
- packages/metrics/tests/*
4846
- packages/metrics/tests/**/*
49-
- packages/metrics/jest.config.cjs
5047
- packages/idempotency/tests/*
5148
- packages/idempotency/tests/**/*
52-
- packages/idempotency/jest.config.cjs
5349
- packages/parameters/tests/*
5450
- packages/parameters/tests/**/*
55-
- packages/parameters/jest.config.cjs
5651
- packages/parser/tests/*
5752
- packages/parser/tests/**/*
58-
- packages/parser/jest.config.cjs
5953
- packages/event-handler/tests/*
6054
- packages/event-handler/tests/**/*
61-
- packages/event-handler/jest.config.cjs
6255
- packages/validator/tests/*
6356
- packages/validator/tests/**/*
64-
- packages/validator/jest.config.cjs
6557
- packages/batch/tests/*
6658
- packages/batch/tests/**/*
67-
- packages/batch/jest.config.cjs
6859
- packages/commons/tests/*
6960
- packages/commons/tests/**/*
70-
- packages/commons/jest.config.cjs
71-
- layers/jest.config.cjs
7261
- layers/tests/*
7362
- layers/tests/**/*
7463

Diff for: .github/dependabot.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ updates:
4141
- "@aws-sdk/*"
4242
- "@smithy/*"
4343
- "aws-sdk-client-mock"
44-
- "aws-sdk-client-mock-jest"
44+
- "aws-sdk-client-mock-vitest"
4545
aws-cdk:
4646
patterns:
4747
- "@aws-cdk/cli-lib-alpha"
4848
- "aws-cdk-lib"
4949
- "aws-cdk"
50-
typedoc:
50+
typescript:
5151
patterns:
5252
- "typedoc"
53-
- "typedoc-plugin-*"
53+
- "typedoc-plugin-*"
54+
- "typescript"
55+
vitest:
56+
patterns:
57+
- "vitest"
58+
- "@vitest/*"

Diff for: .github/workflows/quality_check.yml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Code quality
2+
3+
# USAGE
4+
#
5+
# Automatically triggered when a PR is added to the merge queue.
6+
7+
on:
8+
merge_group:
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
code-quality:
17+
runs-on: ubuntu-latest
18+
env:
19+
NODE_ENV: dev
20+
strategy:
21+
matrix:
22+
version: [18, 20, 22]
23+
workspace: [
24+
"packages/batch",
25+
"packages/commons",
26+
"packages/event-handler",
27+
"packages/idempotency",
28+
"packages/jmespath",
29+
"packages/logger",
30+
"packages/tracer",
31+
"packages/parser",
32+
"packages/parameters",
33+
"packages/metrics"
34+
]
35+
fail-fast: false
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
- name: Setup NodeJS
40+
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
41+
with:
42+
node-version: ${{ matrix.version }}
43+
cache: "npm"
44+
- name: Setup dependencies
45+
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
46+
with:
47+
nodeVersion: ${{ matrix.version }}
48+
- name: Linting
49+
run: npm run lint -w ${{ matrix.workspace }}
50+
- name: Unit tests
51+
run: |
52+
npm run test:unit:coverage -w ${{ matrix.workspace }}
53+
npm run test:unit:types -w ${{ matrix.workspace }}
54+
check-examples:
55+
runs-on: ubuntu-latest
56+
env:
57+
NODE_ENV: dev
58+
strategy:
59+
matrix:
60+
example: ["app"]
61+
fail-fast: false
62+
defaults:
63+
run:
64+
working-directory: examples/${{ matrix.example }}
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
68+
- name: Setup NodeJS
69+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
70+
with:
71+
node-version: 22
72+
cache: "npm"
73+
- name: Setup dependencies
74+
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
75+
- name: Run linting
76+
run: npm run lint
77+
- name: Run tests
78+
run: npm t
79+
check-layer-publisher:
80+
runs-on: ubuntu-latest
81+
env:
82+
NODE_ENV: dev
83+
steps:
84+
- name: Checkout code
85+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
86+
- name: Setup NodeJS
87+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
88+
with:
89+
node-version: 22
90+
cache: "npm"
91+
- name: Setup dependencies
92+
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
93+
- name: Run linting
94+
run: npm run lint -w layers
95+
- name: Run tests
96+
run: npm run test:unit -w layers
97+
check-docs-snippets:
98+
runs-on: ubuntu-latest
99+
env:
100+
NODE_ENV: dev
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
104+
- name: Setup NodeJS
105+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
106+
with:
107+
node-version: 22
108+
cache: "npm"
109+
- name: Setup dependencies
110+
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
111+
- name: Run linting
112+
run: npm run lint -w examples/snippets
113+
check-docs:
114+
runs-on: ubuntu-latest
115+
env:
116+
NODE_ENV: dev
117+
steps:
118+
- name: Checkout code
119+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
120+
- name: Setup NodeJS
121+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
122+
with:
123+
node-version: 22
124+
cache: "npm"
125+
- name: Setup dependencies
126+
uses: aws-powertools/actions/.github/actions/cached-node-modules@d406bac5563f1d8c793519a3eedfe620f6a14872
127+
- name: Run linting
128+
run: npm run lint:markdown

Diff for: .npmignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ coverage
1212
tslint.json
1313
tsconfig.json
1414
MakeFile
15-
jest.config.cjs
15+
vitest.config.ts
16+
vitest.workspace.ts
1617
.npmignore
1718
.eslintignore
1819
.huskyrc.js

Diff for: docs/contributing/testing.md

+9-20
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,7 @@ Tests are defined alongside the code they test, and can be found under the `test
1313

1414
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`.
1515

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.
2717

2818
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`.
2919

@@ -67,7 +57,6 @@ To run unit tests, you can use of the following commands from the root folder:
6757
* `npm test -ws` to run all the unit tests for all the modules sequentially
6858
* `npm run test:parallel` to run all the unit tests for all the modules in parallel
6959
* `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
7160

7261
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.
7362

@@ -93,12 +82,12 @@ Below is a diagram that shows the flow of the integration tests:
9382

9483
```mermaid
9584
sequenceDiagram
96-
Dev Environment / CI->>+Jest: npm run test:e2e
97-
Jest-->Jest: Synthetize CloudFormation Stack
98-
Jest->>+AWS: Deploy Stack
99-
Jest->>+AWS: Invoke Lambda function
100-
AWS->>Jest: Report logs / results
101-
Jest-->Jest: Assert logs/result
102-
Jest->>+AWS: Destroy Stack
103-
Jest->>+Dev Environment / CI: show test results
85+
Dev Environment / CI->>+Vitest: npm run test:e2e
86+
Vitest-->Vitest: Synthetize CloudFormation Stack
87+
Vitest->>+AWS: Deploy Stack
88+
Vitest->>+AWS: Invoke Lambda function
89+
AWS->>Vitest: Report logs / results
90+
Vitest-->Vitest: Assert logs/result
91+
Vitest->>+AWS: Destroy Stack
92+
Vitest->>+Dev Environment / CI: show test results
10493
```

Diff for: docs/core/logger.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,20 @@ When you extend the default JSON serializer, we will call your custom serializer
828828

829829
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.
830830

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:
832832

833833
=== "handler.test.ts"
834834

835835
```typescript
836836
--8<-- "examples/snippets/logger/unitTesting.ts"
837837
```
838838

839-
### Suppress logs with Jest
839+
### Suppress logs
840840

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.
842842

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
845845
```
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.

Diff for: docs/core/metrics.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -473,20 +473,11 @@ To make it easier to test your code, you can set the `POWERTOOLS_DEV` environmen
473473

474474
This allows you to spy on the logs emitted by the utility and assert that the metrics are being emitted correctly.
475475

476-
```typescript title="Spying on emitted metrics"
477-
describe('Metrics tests', () => {
478-
beforeAll(() => {
479-
process.env.POWERTOOLS_DEV = 'true';
480-
})
481-
482-
it('function metrics properly', async () => {
483-
// Prepare
484-
const metricsSpy = jest.spyOn(console, 'log').mockImplementation();
485-
486-
// Act & Assess
487-
});
488-
});
489-
```
476+
=== "Spying on emitted metrics"
477+
478+
```typescript hl_lines="4 10"
479+
--8<-- "examples/snippets/metrics/testingMetrics.ts"
480+
```
490481

491482
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.
492483

Diff for: docs/utilities/idempotency.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -832,21 +832,21 @@ The idempotency utility provides several routes to test your code.
832832

833833
### Disabling the idempotency utility
834834

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.
836836

837837
### Testing with local DynamoDB
838838

839839
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"}.
840840

841841
=== "handler.test.ts"
842842

843-
```typescript hl_lines="7-9"
843+
```typescript hl_lines="18"
844844
--8<-- "examples/snippets/idempotency/workingWithLocalDynamoDB.test.ts"
845845
```
846846

847847
=== "handler.ts"
848848

849-
```typescript hl_lines="7-9"
849+
```typescript
850850
--8<-- "examples/snippets/idempotency/workingWithLocalDynamoDB.ts"
851851
```
852852

Diff for: docs/utilities/parameters.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ The **`clientConfig`** parameter enables you to pass in a custom [config object]
450450

451451
### Mocking parameter values
452452

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.
454454

455455
=== "handler.test.ts"
456-
```typescript hl_lines="2 4-9 13 18"
457-
--8<-- "examples/snippets/parameters/testingYourCodeFunctionsJestMock.ts"
456+
```typescript hl_lines="4-6 12 22"
457+
--8<-- "examples/snippets/parameters/testingYourCodeFunctionsMock.ts"
458458
```
459459

460460
=== "handler.ts"
@@ -464,23 +464,23 @@ For unit testing your applications, you can mock the calls to the parameters uti
464464

465465
With this pattern in place, you can customize the return values of the mocked function to test different scenarios without calling AWS APIs.
466466

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.
468468

469469
=== "handler.test.ts"
470-
```typescript hl_lines="2 5 8 19 26-27"
471-
--8<-- "examples/snippets/parameters/testingYourCodeProvidersJestMock.ts"
470+
```typescript hl_lines="2 7 21-23"
471+
--8<-- "examples/snippets/parameters/testingYourCodeProvidersMock.ts"
472472
```
473473

474474
=== "handler.ts"
475475
```typescript
476476
--8<-- "examples/snippets/parameters/testingYourCodeProvidersHandler.ts"
477477
```
478478

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-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.
480480

481481
=== "handler.test.ts"
482-
```typescript hl_lines="2-8 11 14 18 23-30"
483-
--8<-- "examples/snippets/parameters/testingYourCodeClientJestMock.ts"
482+
```typescript hl_lines="2-7 12 16 21-28"
483+
--8<-- "examples/snippets/parameters/testingYourCodeClientMock.ts"
484484
```
485485

486486
=== "handler.ts"
@@ -495,6 +495,6 @@ Parameters utility caches all parameter values for performance and cost reasons.
495495
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.
496496

497497
=== "handler.test.ts"
498-
```typescript hl_lines="1 9"
498+
```typescript hl_lines="1 6"
499499
--8<-- "examples/snippets/parameters/testingYourCodeClearCache.ts"
500500
```

Diff for: examples/app/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.js
22
!.eslintrc.js
3-
!jest.config.js
3+
!vitest.config.js
44
*.d.ts
55
node_modules
66

0 commit comments

Comments
 (0)