Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

CI: actually run the tests, and hold the locales to one key set

Duarte Santos051a37abbfc4
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 000000000..4abd9e710
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,43 @@
+# Runs on pull requests too — the other two workflows only fire on push to main, so
+# contributed changes used to reach main without anything ever having been run.
+name: Tests
+
+on:
+ pull_request:
+ paths:
+ - 'frontend/**'
+ - '.github/workflows/test.yml'
+ push:
+ branches: [main]
+ paths:
+ - 'frontend/**'
+ - '.github/workflows/test.yml'
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: test-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ # node:22-alpine in web/Dockerfile and api/Dockerfile — CI must match production.
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ cache-dependency-path: frontend/package-lock.json
+ - run: npm ci
+ working-directory: frontend
+ - run: npm test
+ working-directory: frontend
+ # A broken import or bad JSX fails the build long before any test covers it.
+ - run: npm run build
+ working-directory: frontend
+ - run: node scripts/check-locales.mjs
+ working-directory: frontend
diff --git a/frontend/scripts/check-locales.mjs b/frontend/scripts/check-locales.mjs
new file mode 100644
index 000000000..ffc00360a
--- /dev/null
+++ b/frontend/scripts/check-locales.mjs
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+// Guards the one invariant every locale in src/locales/ shares: the same key set.
+// English is the source language and has no locale file, so a key that exists in only
+// some locales falls back to English silently, mid-sentence, with nothing failing
+// anywhere. This catches that at review time instead of in the app.
+//
+// node scripts/check-locales.mjs
+//
+// The reference is the union of all locales, not one blessed file: a key added to a
+// single locale then flags the other ten instead of passing unnoticed.
+
+import { readdirSync } from 'node:fs'
+import { dirname, join } from 'node:path'
+import { fileURLToPath, pathToFileURL } from 'node:url'
+
+const localesDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'src', 'locales')
+const files = readdirSync(localesDir).filter(f => f.endsWith('.js')).sort()
+
+if (!files.length) {
+ console.error(`No locale files found in ${localesDir}`)
+ process.exit(1)
+}
+
+const locales = new Map()
+for (const file of files) {
+ const { default: dict } = await import(pathToFileURL(join(localesDir, file)).href)
+ if (!dict || typeof dict !== 'object') {
+ console.error(`${file}: no default-exported object`)
+ process.exit(1)
+ }
+ locales.set(file.replace(/\.js$/, ''), new Set(Object.keys(dict)))
+}
+
+// How many locales carry each key — 1 means the key was added to a single file only,
+// which is the usual shape of the bug and worth naming separately from plain gaps.
+const seen = new Map()
+for (const keys of locales.values()) for (const k of keys) seen.set(k, (seen.get(k) || 0) + 1)
+const union = [...seen.keys()]
+
+let failed = false
+for (const [lang, keys] of locales) {
+ const missing = union.filter(k => !keys.has(k))
+ const orphans = union.filter(k => keys.has(k) && seen.get(k) === 1)
+ if (missing.length || orphans.length) {
+ failed = true
+ console.error(`\n${lang}.js: ${keys.size}/${union.length} keys`)
+ for (const k of missing) console.error(` missing: ${JSON.stringify(k)}`)
+ for (const k of orphans) console.error(` only here: ${JSON.stringify(k)}`)
+ }
+}
+
+if (failed) {
+ console.error('\nLocale key sets differ. Every locale must carry the same keys.')
+ process.exit(1)
+}
+
+console.log(`${locales.size} locales, ${union.length} keys each — in sync.`)