velxio/.github/workflows/frontend-tests.yml

54 lines
1.9 KiB
YAML

name: Frontend Tests
on:
push:
branches: [master, main]
pull_request:
branches: [master, main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js 22
uses: actions/setup-node@v4
with:
node-version: '22'
# The metadata generator scans wokwi-elements/src/, which only ships in
# the upstream repo (not on npm). Clone it once for the freshness check.
- name: Clone wokwi-elements (for metadata regeneration only)
run: git clone --depth=1 https://github.com/wokwi/wokwi-elements.git third-party/wokwi-elements
# No node_modules cache. Lock files are gitignored (see .gitignore) so
# a cache key tied to package-lock.json never invalidates and ends up
# restoring stale links to old `file:` deps from previous commits
# (e.g. wokwi-elements pre-npm migration). Fresh install every run is
# ~30s slower but actually correct.
- name: Install frontend dependencies
run: cd frontend && npm install --no-audit --no-fund --include=optional
- name: Install root dev dependencies
run: npm install --no-audit --no-fund
# Regenerate metadata and fail if committed JSON is stale. Catches PRs
# that modify component-overrides.json without running generate:metadata.
- name: Regenerate component metadata
run: cd frontend && npm run generate:metadata
- name: Fail if components-metadata.json is out of date
run: |
if ! git diff --quiet frontend/public/components-metadata.json; then
echo "::error::components-metadata.json is stale. Run 'cd frontend && npm run generate:metadata' and commit the result."
git diff frontend/public/components-metadata.json | head -100
exit 1
fi
- name: Run tests
run: cd frontend && npm test