Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
run: npm run lint:js -- --format compact --quiet --prune-suppressions

- name: Test agent skill setup
run: npm run test:unit -- tools/agents/test/setup-skills.test.js --runInBand
run: npm run test:unit:vitest -- --project=node tools/agents/test/setup-skills.test.js

- name: Lint Styles
if: ${{ matrix.annotations }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
# dimension so flakiness.io keeps a separate history per Node
# version in the matrix.
FK_ENV_NODEJS: ${{ matrix.node }}
run: npm run test:unit:date -- --ci --maxWorkers="$(nproc)" --cacheDirectory="$HOME/.jest-cache"
run: npm run test:unit:date -- --maxWorkers="$(nproc)"

compute-previous-wordpress-version:
name: Compute previous WordPress version
Expand Down
2 changes: 1 addition & 1 deletion bin/unit-test-date.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for timezone in "${timezones[@]}"; do
TZ=$timezone LANG=$locale \
FK_ENV_TZ=$timezone FK_ENV_LANG=$locale \
FLAKINESS_OUTPUT_DIR="flakiness-report-$timezone-$locale" \
npm run test:unit -- packages/date "$@" &
npm run test:unit:vitest -- packages/date "$@" &
pids+=($!)
pidsTimezones+=($timezone)
pidsLocales+=($locale)
Expand Down
32 changes: 25 additions & 7 deletions docs/contributors/code/testing-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ During the Jest-to-Vitest migration, run both `npm run test:unit` and `npm run t

Keep your tests in a `test` folder in your working directory. The test file should have the same name as the test subject file.

Use `*.jsdom.test.*` for tests that only require a virtual DOM. Use `*.browser.test.*` for tests that require Vitest Browser Mode. Leave Node-compatible test names without an environment suffix. The filename selects the test environment in both Jest and Vitest. During the migration, the manifest only selects the runner. Do not use per-file environment overrides.
Use `*.jsdom.test.*` for tests that only require a virtual DOM. Use `*.browser.test.*` for tests that require Vitest Browser Mode. Leave Node-compatible test names without an environment suffix. Node tests run in Vitest automatically. The filename selects the test environment in both Jest and Vitest. During the remaining migration, the manifest selects the runner only for JSDOM and Browser Mode tests. Do not use per-file environment overrides.

```
+-- test
Expand Down Expand Up @@ -325,8 +325,12 @@ When a snapshot test fails, it just means that a component's rendering has chang
However, if the change was intentional, follow these steps to update the snapshot. Run the following to update the snapshots:

```sh
# --testPathPatterns is optional but will be much faster by only running matching tests
npm run test:unit -- --updateSnapshot --testPathPatterns path/to/tests
# Update snapshots for Node or Vitest-owned DOM tests
npm run test:unit:vitest:update -- path/to/tests

# Update snapshots for Jest-owned JSDOM tests
# --testPathPatterns is optional but runs only matching tests
npm run test:unit:update -- --testPathPatterns path/to/tests

# Update snapshot for e2e tests
npm run test:e2e -- --update-snapshots path/to/spec
Expand Down Expand Up @@ -402,15 +406,29 @@ Reducer tests are also a great fit for snapshots. They are often large, complex

#### Working with snapshots

You might be blindsided by CI tests failing when snapshots don't match. You'll need to [update snapshots] if the changes are expected. The quick and dirty solution is to invoke Jest with `--updateSnapshot`. That can be done as follows:
You might be blindsided by CI tests failing when snapshots don't match. You'll need to [update snapshots] if the changes are expected. Use the command for the test's runner:

```sh
npm run test:unit -- --updateSnapshot --testPathPatterns path/to/tests
# Node or Vitest-owned DOM tests
npm run test:unit:vitest:update -- path/to/tests

# Jest-owned JSDOM tests
npm run test:unit:update -- --testPathPatterns path/to/tests
```

`--testPathPatterns` is not required, but specifying a path will speed things up by running a subset of tests.
The path is not required, but specifying one runs only matching tests and is faster.

Keep the applicable watch command running in the background as you work:

```sh
# Node or Vitest-owned DOM tests
npm run test:unit:vitest:watch -- path/to/tests

# Jest-owned JSDOM tests
npm run test:unit:watch -- --testPathPatterns path/to/tests
```

It's a great idea to keep `npm run test:unit:watch` running in the background as you work. Jest will run only the relevant tests for changed files, and when snapshot tests fail, just hit `u` to update a snapshot!
When a snapshot test fails in either runner, press `u` to update the snapshot.

#### Pain points

Expand Down
Loading
Loading