Skip to content

Commit 6c79ef6

Browse files
committed
chore(test): migrate from Jest to node:test
1 parent 52f32bb commit 6c79ef6

File tree

75 files changed

+9929
-12164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9929
-12164
lines changed

Diff for: .github/dependabot.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ updates:
3939
patterns:
4040
- '@testing-library/*'
4141
- '@types/testing-library*'
42-
- '@types/jest'
43-
- 'jest'
44-
- 'jest-*'
42+
- 'tsx'
43+
- '@reporters/github'
44+
- 'jsdom'
45+
- 'global-jsdom'
4546
next-js:
4647
patterns:
4748
- 'next'

Diff for: .github/workflows/chromatic.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Security Notes
2+
# Only selected Actions are allowed within this repository. Please refer to (https://github.com/nodejs/nodejs.org/settings/actions)
3+
# for the full list of available actions. If you want to add a new one, please reach out a maintainer with Admin permissions.
4+
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
5+
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
6+
7+
name: Chromatic
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
pull_request_target:
14+
branches:
15+
- main
16+
types:
17+
- labeled
18+
merge_group:
19+
20+
defaults:
21+
run:
22+
# This ensures that the working directory is the root of the repository
23+
working-directory: ./
24+
25+
permissions:
26+
contents: read
27+
actions: read
28+
29+
env:
30+
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--force
31+
TURBO_FORCE: true
32+
33+
jobs:
34+
chromatic:
35+
# We only need to run Storybook Builds and Storybook Visual Regression Tests within Pull Requests that actually
36+
# introduce changes to the Storybook. Hence, we skip running these on Crowdin PRs and Dependabot PRs
37+
# sha reference has no stable git tag reference or URL. see https://github.com/chromaui/chromatic-cli/issues/797
38+
if: |
39+
github.event_name == 'push' ||
40+
(
41+
github.event_name == 'pull_request_target' &&
42+
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false &&
43+
github.event.pull_request.head.ref != 'chore/crowdin'
44+
)
45+
46+
name: Tests
47+
runs-on: ubuntu-latest
48+
49+
environment:
50+
name: Storybook
51+
url: ${{ steps.chromatic-deploy.outputs.storybookUrl }}
52+
53+
steps:
54+
- name: Harden Runner
55+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
56+
with:
57+
egress-policy: audit
58+
59+
- name: Git Checkout
60+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
61+
with:
62+
# Provides the Pull Request commit SHA or the GitHub merge group ref
63+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
64+
# The Chromatic (@chromaui/action) Action requires a full history of the current branch in order to be able to compare
65+
# previous changes and previous commits and determine which Storybooks should be tested against and what should be built
66+
fetch-depth: 0
67+
68+
- name: Set up Node.js
69+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
70+
with:
71+
# We want to ensure that the Node.js version running here respects our supported versions
72+
node-version-file: '.nvmrc'
73+
cache: 'npm'
74+
75+
- name: Install npm packages
76+
# We want to avoid npm from running the Audit Step and Funding messages on a CI environment
77+
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
78+
run: npm i --no-audit --no-fund --userconfig=/dev/null
79+
80+
- name: Start Visual Regression Tests (Chromatic)
81+
# This assigns the Environment Deployment for Storybook
82+
id: chromatic-deploy
83+
uses: chromaui/action@c93e0bc3a63aa176e14a75b61a31847cbfdd341c
84+
with:
85+
workingDir: packages/ui-components
86+
buildScriptName: storybook:build
87+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
88+
exitOnceUploaded: true
89+
onlyChanged: true

Diff for: .github/workflows/lint-and-tests.yml

+20-84
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
11
# Security Notes
22
# Only selected Actions are allowed within this repository. Please refer to (https://github.com/nodejs/nodejs.org/settings/actions)
33
# for the full list of available actions. If you want to add a new one, please reach out a maintainer with Admin permissions.
4-
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
4+
# REVIEWERS, please always double-check security practices before merging a PR that contains workflow changes!!
55
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
66

77
name: Linting and Tests
88

9+
# This workflow should run either on `merge_groups`, `pull_request`, or `push` events
10+
# since we want to run lint checks against any changes on pull requests, or the final patch on merge groups
11+
# or if direct pushes happen to main (or when changes in general land on the `main` (default) branch)
12+
# Note that the reason why we run this on pushes against `main` is that on rare cases, maintainers might do direct pushes against `main`
913
on:
1014
push:
1115
branches:
1216
- main
13-
pull_request_target:
17+
pull_request:
1418
branches:
1519
- main
16-
types:
17-
- labeled
1820
merge_group:
1921

20-
defaults:
21-
run:
22-
# This ensures that the working directory is the root of the repository
23-
working-directory: ./
24-
2522
permissions:
2623
contents: read
2724
actions: read
28-
# This permission is required by `MishaKav/jest-coverage-comment`
29-
pull-requests: write
3025

3126
env:
3227
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--force
3328
TURBO_FORCE: true
3429

3530
jobs:
3631
lint:
37-
# This Job should run either on `merge_groups` or `push` events
38-
# or `pull_request_target` event with a `labeled` action with a label named `github_actions:pull-request`
39-
# since we want to run lint checks against any changes on pull requests, or the final patch on merge groups
40-
# or if direct pushes happen to main (or when changes in general land on the `main` (default) branch)
41-
# Note that the reason why we run this on pushes against `main` is that on rare cases, maintainers might do direct pushes against `main`
42-
if: |
43-
(github.event_name == 'push' || github.event_name == 'merge_group') ||
44-
(github.event_name == 'pull_request_target' &&
45-
github.event.label.name == 'github_actions:pull-request')
46-
4732
name: Quality checks
4833
runs-on: ubuntu-latest
4934

@@ -55,9 +40,6 @@ jobs:
5540

5641
- name: Git Checkout
5742
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
58-
with:
59-
# Provides the Pull Request commit SHA or the GitHub merge group ref
60-
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
6143

6244
- name: Restore Lint Cache
6345
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
@@ -96,10 +78,8 @@ jobs:
9678
# Note: Linting and Prettifying of files on Crowdin PRs is handled by the `translations-pr.yml` Workflow
9779
if: |
9880
(github.event_name == 'push' || github.event_name == 'merge_group') ||
99-
(github.event_name == 'pull_request_target' &&
100-
github.event.pull_request.head.ref != 'chore/crowdin')
101-
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
102-
run: npx --package=turbo@latest -- turbo lint check-types prettier
81+
(github.event_name == 'pull_request' && github.event.pull_request.head.ref != 'chore/crowdin')
82+
run: npx turbo lint check-types prettier
10383

10484
- name: Save Lint Cache
10585
# We only want to save caches on `push` events or `pull_request_target` events
@@ -109,7 +89,7 @@ jobs:
10989
# other Pull Requests and PRs coming from forks
11090
if: |
11191
github.event_name == 'push' ||
112-
(github.event_name == 'pull_request_target' &&
92+
(github.event_name == 'pull_request' &&
11393
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false &&
11494
github.event.pull_request.head.ref != 'chore/crowdin')
11595
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
@@ -123,22 +103,9 @@ jobs:
123103
key: cache-lint-${{ hashFiles('package-lock.json') }}-${{ hashFiles('.turbo/cache/**') }}
124104

125105
tests:
126-
# This Job should run either on `merge_groups` or `push` events
127-
# or `pull_request_target` event with a `labeled` action with a label named `github_actions:pull-request`
128-
# since we want to run lint checks against any changes on pull requests and on final patches against a pull request.
129-
# We don't need to execute the tests again on pushes against (`main`) as the merge group should already handle that
130-
if: |
131-
(github.event_name == 'push' || github.event_name == 'merge_group') ||
132-
(github.event_name == 'pull_request_target' &&
133-
github.event.label.name == 'github_actions:pull-request')
134-
135106
name: Tests
136107
runs-on: ubuntu-latest
137108

138-
environment:
139-
name: Storybook
140-
url: ${{ steps.chromatic-deploy.outputs.storybookUrl }}
141-
142109
steps:
143110
- name: Harden Runner
144111
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
@@ -147,12 +114,6 @@ jobs:
147114

148115
- name: Git Checkout
149116
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
150-
with:
151-
# Provides the Pull Request commit SHA or the GitHub merge group ref
152-
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
153-
# The Chromatic (@chromaui/action) Action requires a full history of the current branch in order to be able to compare
154-
# previous changes and previous commits and determine which Storybooks should be tested against and what should be built
155-
fetch-depth: 0
156117

157118
- name: Set up Node.js
158119
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
@@ -169,41 +130,16 @@ jobs:
169130
- name: Run Unit Tests
170131
# We want to run Unit Tests in every circumstance, including Crowdin PRs and Dependabot PRs to ensure
171132
# that changes to dependencies or translations don't break the Unit Tests
172-
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
173-
run: npx --package=turbo@latest -- turbo test:unit -- --ci --coverage
174-
175-
- name: Start Visual Regression Tests (Chromatic)
176-
# This assigns the Environment Deployment for Storybook
177-
id: chromatic-deploy
178-
# We only need to run Storybook Builds and Storybook Visual Regression Tests within Pull Requests that actually
179-
# introduce changes to the Storybook. Hence, we skip running these on Crowdin PRs and Dependabot PRs
180-
if: |
181-
github.event_name == 'push' ||
182-
(github.event_name == 'pull_request_target' &&
183-
startsWith(github.event.pull_request.head.ref, 'dependabot/') == false &&
184-
github.event.pull_request.head.ref != 'chore/crowdin')
185-
# sha reference has no stable git tag reference or URL. see https://github.com/chromaui/chromatic-cli/issues/797
186-
uses: chromaui/action@c93e0bc3a63aa176e14a75b61a31847cbfdd341c
133+
run: npm run test:ci
134+
135+
- name: Upload test coverage to Codecov
136+
if: ${{ !cancelled() }}
137+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
187138
with:
188-
workingDir: packages/ui-components
189-
buildScriptName: storybook:build
190-
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
191-
exitOnceUploaded: true
192-
onlyChanged: true
193-
194-
- name: Jest Coverage Comment
195-
# We don't need to post the Jest Coverage comment on Crowdin PRs and Dependabot PRs
196-
# as in general they introduce no changes to the Unit Tests and the Codebase
197-
# We reuse the checks from the Chromatic Deploy step as they're the same conditions
198-
if: steps.chromatic-deploy.outcome == 'success'
199-
# This comments the current Jest Coverage Report containing JUnit XML reports
200-
# and a Code Coverage Summary
201-
uses: MishaKav/jest-coverage-comment@d74238813c33e6ea20530ff91b5ea37953d11c91 # v1.0.27
139+
files: ./apps/site/lcov.info,./packages/ui-components/lcov.info
140+
141+
- name: Upload test results to Codecov
142+
if: ${{ !cancelled() }}
143+
uses: codecov/test-results-action@f2dba722c67b86c6caa034178c6e4d35335f6706 # v1.1.0
202144
with:
203-
title: 'Unit Test Coverage Report'
204-
multiple-junitxml-files: |
205-
@node-core/ui-components, ./packages/ui-components/junit.xml
206-
@nodejs/website, ./apps/site/junit.xml
207-
multiple-files: |
208-
@node-core/ui-components, ./packages/ui-components/coverage/coverage-summary.json
209-
@nodejs/website, ./apps/site/coverage/coverage-summary.json
145+
files: ./apps/site/junit.xml,./packages/ui-components/junit.xml

Diff for: .gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ npm-debug.log
88
.next
99
build
1010

11-
# Jest
12-
coverage
13-
.swc
11+
# Test Runner
1412
junit.xml
13+
lcov.info
1514

1615
# Storybook
1716
storybook-static

Diff for: .prettierignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ build
1010
# Next.js Generated Files
1111
public/static/documents
1212

13-
# Jest
14-
coverage
15-
.swc
13+
# Test Runner
1614
junit.xml
15+
lcov.info
1716

1817
# Storybook
1918
storybook-static

Diff for: COLLABORATOR_GUIDE.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ You can add a PACKAGE_MANAGER the same way as adding an INSTALLATION_METHOD (fro
419419
## Unit Tests and Storybooks
420420

421421
Each new feature or bug fix should be accompanied by a unit test (when deemed valuable).
422-
We use [Jest][] as our test runner and [React Testing Library][] for our React unit tests.
422+
We use [`node:test`][] as our test runner and [React Testing Library][] for our React unit tests.
423423

424424
We also use [Storybook][] to document our components.
425425
Components within `packages/ui-components` should have a storybook story that documents the component's usage.
@@ -435,8 +435,6 @@ Unit Tests are fundamental to ensure that code changes do not disrupt the functi
435435
- Unit Tests should ensure that a given change's functionality is working as expected.
436436
- When creating unit tests for React components, we recommend that the tests cover all the possible states of the component.
437437
- We also recommend mocking external dependencies, if unsure about how to mock a particular dependency, raise the question on your Pull Request.
438-
- We recommend using [Jest's Mock Functions](https://jestjs.io/docs/en/mock-functions) for mocking dependencies.
439-
- We recommend using [Jest's Mock Modules](https://jestjs.io/docs/en/manual-mocks) for mocking dependencies unavailable on the Node.js runtime.
440438
- Common Providers and Contexts from the lifecycle of our App, such as [`next-intl`][] should not be mocked but given an empty or fake context whenever possible.
441439
- We recommend reading previous unit tests from the codebase for inspiration and code guidelines.
442440

@@ -644,7 +642,7 @@ A lot of the current structure is due to retro-compatibility, keeping a simple a
644642

645643
If you're unfamiliar or curious about something, we recommend opening a Discussion on this GitHub Repository.
646644

647-
[Jest]: https://jestjs.io/
645+
[`node:test`]: https://nodejs.org/api/test.html
648646
[React Testing Library]: https://testing-library.com/docs/react-testing-library/intro/
649647
[Storybook]: https://storybook.js.org/
650648
[`next-intl`]: https://next-intl-docs.vercel.app

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ This repository contains several scripts and commands for performing numerous ta
160160
- `npx turbo storybook` starts Storybook's local server
161161
- `npx turbo storybook:build` builds Storybook as a static web application for publishing
162162
- `npm run test` runs all tests locally
163-
- `npx turbo test:unit` runs jest (unit-tests) locally
163+
- `npx turbo test:unit` runs unit-tests locally
164164

165165
</details>
166166

Diff for: DEPENDENCY_PINNING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ The following recommendations are in order when adding a new dependency:
1212
- Some non-code dependencies are required for the bootstrap of the repository. They are either used on basic build scripts or Git Hooks. Examples include `husky`, `lint-staged` and others.
1313
- A dependency should be a `devDependencies` if it is not invoked anywhere within the codebase.
1414
- This applies to runtimes, tooling, utility/dev-only commands, type packages and others
15-
- Sometimes, a dependency should be a `devDependency` even if invoked within the codebase, but only used within a development environment or during a test runner. Examples include `jest`, `storybook` and others.
15+
- Sometimes, a dependency should be a `devDependency` even if invoked within the codebase, but only used within a development environment or during a test runner. Examples include `storybook` and others.
1616
- A dependency should be a `peerDependencies` if it is a runtime dependency of the Website, but the Website itself does not install it. Examples include `react`, `react-dom` and others.
1717

1818
### When pinning dependencies
1919

2020
When adding dependencies, you should consider if that dependency should be saved as an exact dependency (`--save-exact`) or use either a `^` or `~` version range operator. The following guidelines are in order:
2121

22-
- A dependency, in general, should be pinned to its exact dependency if it's either a tooling or a CLI dependency. Examples include `husky`, `prettier`, `jest` and others.
22+
- A dependency, in general, should be pinned to its exact dependency if it's either a tooling or a CLI dependency. Examples include `husky`, `prettier`, and others.
2323
- A dependency should generally use `~` if we're interested in patch updates (such as hot-fixes and bug-fixes) and the package is part of the Development or Testing Environment. (Such as `storybook`, for example)
2424
- A dependency should generally use `^` if they're part of the Website Application itself, such as `react`, `next-intl` etc. This is done because we intentionally want to get these dependencies' latest features and bug-fixes.
2525
- If we're not interested in getting the latest features and bug fixes, we should consider using `~` instead.

Diff for: apps/site/.stylelintignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ build
77
# Public Folder
88
public
99

10-
# Jest
11-
coverage
10+
# Test Runner
11+
junit.xml
12+
lcov.info
1213

1314
# Old Styles
1415
styles/old

0 commit comments

Comments
 (0)