Files
Ashley Hunter 1b743f8019 test: migrate from jest to vitest with browser testing for brain/helm
Replace Jest with Vitest across the workspace. The brain and helm Angular suites
now run in a real browser (Playwright/Chromium via Vitest browser mode) so they
exercise real layout, focus, pointer events and computed styles that jsdom could
not. The cli, tools, mcp, registry and cli-smoke suites run on Vitest's node
environment.

- Add per-project vite configs and switch test targets to @nx/vitest:test
- Convert jest APIs to vi.* and jest module mocks to vi.mock with importOriginal
- Replace jest-axe with a browser-native axe-core helper and toHaveNoViolations
- Regenerate snapshots in vitest format (content unchanged, format-only)
- Remove all jest packages, configs, the preset and the @nx/jest target default
- Install Playwright Chromium in the CI unit job for the browser suites

Also fixes a brain avatar test that asserted inside a fire-and-forget setTimeout,
which passed vacuously under jsdom and only surfaced once a real browser loaded
the image.
2026-06-13 15:16:45 +01:00

124 lines
4.6 KiB
YAML

name: ci
on:
push:
branches:
- main
pull_request: {}
# Cancel superseded runs on the same ref (e.g. rapid pushes / force-pushes to a PR) so CI minutes
# are not spent finishing builds that are already out of date.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# The docs app build prerenders many pages and needs a larger heap.
NODE_OPTIONS: --max-old-space-size=6000
jobs:
commitlint:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
# Required by wagoid/commitlint-github-action
pull-requests: read
steps:
- uses: actions/checkout@v6
with:
# Required by wagoid/commitlint-github-action
fetch-depth: 0
- name: Install Node
uses: actions/setup-node@v6
with:
node-version-file: .node-version
- name: Lint commit messages
uses: wagoid/commitlint-github-action@v5
with:
failOnWarnings: true
helpURL: https://github.com/goetzrobin/spartan/blob/main/CONTRIBUTING.md#-commit-message-guidelines
format-and-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
# Full commit history so nx-set-shas can compute the affected base. `blob:none` keeps the
# whole commit graph (affected still diffs correctly) but downloads file contents lazily -
# a win for this light job that only touches the affected projects' files.
fetch-depth: 0
filter: blob:none
- uses: ./.github/actions/setup
- uses: nrwl/nx-set-shas@v5
- name: format
run: pnpm nx format:check --base=$NX_BASE --head=$NX_HEAD
- name: lint
run: pnpm nx affected -t lint --parallel=3
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- uses: nrwl/nx-set-shas@v5
- name: Build
run: pnpm nx affected -t build --parallel=1
unit:
runs-on: ubuntu-latest
# No longer gated on `build`: vitest runs against source, so unit tests start immediately and
# run in parallel with the build instead of waiting ~13 min for it.
steps:
- uses: actions/checkout@v6
with:
# Blobless full-history clone: nx-set-shas needs the graph; vitest only reads the
# affected projects' files, fetched lazily.
fetch-depth: 0
filter: blob:none
- uses: ./.github/actions/setup
- uses: nrwl/nx-set-shas@v5
# The brain/helm suites run in a real browser via Vitest browser mode (Playwright/Chromium),
# so the Chromium binary must be present. Cache it across runs (keyed on the lockfile, which
# pins the playwright version) to avoid re-downloading ~150 MB each time.
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: playwright-${{ runner.os }}-
- name: Install Playwright Chromium
# On a cache hit the browser is already present; still run install to pull any missing OS
# libraries (--with-deps), which are not part of the cached browser directory.
run: pnpm exec playwright install --with-deps chromium
- name: Test
run: pnpm nx affected -t test --parallel=3
e2e:
runs-on: ubuntu-latest
# Not gated on `build`: the e2e suite runs cypress against storybook (its cypress executor's
# devServerTarget is ui-storybook:static-storybook), so it builds/serves storybook itself and
# is independent of the docs-app build. It runs in parallel with the build job.
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
# Restore the Cypress binary cache before install so a cypress postinstall is a no-op too.
- name: Cache Cypress binary
uses: actions/cache@v5
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: cypress-${{ runner.os }}-
- uses: ./.github/actions/setup
- uses: nrwl/nx-set-shas@v5
- name: Install Cypress
run: npx cypress install
- name: End-to-end test
# Exclude trpc-app-e2e: it is not tagged scope:e2e and was never run in CI (it needs a
# database/health endpoint that is not provisioned here). Only the storybook e2e runs.
run: pnpm nx affected -t e2e --exclude=trpc-app-e2e --parallel=1 --outputStyle=stream