Skip to content

chore: fail fast on dev builds, stop running shared tests twice - #264

Merged
Musiker15 merged 3 commits into
mainfrom
chore/build-guard-and-test-dist
Sep 16, 2026
Merged

Musiker15 merged 3 commits into
mainfrom
chore/build-guard-and-test-dist

Conversation

@Musiker15

@Musiker15 Musiker15 commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Two small fixes for things that cost time before.

Build guard for NODE_ENV (apps/web)

pnpm build now runs scripts/assert-build-env.mjs first. If NODE_ENV is set to anything other than production, it stops with a short explanation and the right command.

Background (2026-09-01): the local .env sets NODE_ENV=development for pnpm dev. Sourcing it to get DATABASE_URL made the production build load React's development bundle, and the prerender of /_global-error failed with Cannot read properties of null (reading 'useContext'). That message looks like a duplicate React or a Windows problem, and it took two wrong guesses to find the real cause. CI and the deploy never set NODE_ENV, so neither is affected.

Checked: exits 1 with NODE_ENV=development, 0 when unset and 0 with production.

Tests ran twice from dist

packages/shared builds with plain tsc, its tsconfig includes the test files, so dist/*.test.js gets emitted. test depends on ^build in turbo, and vitest no longer excludes dist by default, so CI collected every shared suite twice and local counts changed depending on whether dist existed.

  • packages/shared/vitest.config.ts limits collection to src/**/*.test.ts.
  • The same config (src/**/*.test.ts, .tsx for ui) is added to the other packages that emit into dist/: packages/db, packages/ui, packages/i18n, apps/realtime. None of them has tests yet, so nothing runs twice there today, but the first test added would. apps/bot (tsc --noEmit) and apps/web (next build, noEmit) don't emit and are not affected.

I left the test files in the tsc build. dist/ is not consumed by anything (all packages export their sources), and excluding them would need a separate build tsconfig so typecheck keeps covering the tests.

Verification

rm -rf dist alone is not enough to reproduce this locally. tsconfig.base.json sets incremental: true and the tsconfig.tsbuildinfo sits next to dist/, not in it, so after deleting only dist/ a tsc build considers itself up to date and emits nothing. The checks below therefore delete both.

rm -rf packages/shared/dist packages/shared/tsconfig.tsbuildinfo
pnpm --filter @msk-forms/shared build     # 10 *.test.js files in dist
Test files Tests
without the config 20 188
with the config 10 94

With the compiled test files present, vitest run --reporter=verbose lists only src/*.test.ts files. After a clean build of db, ui, i18n and realtime, none of them has *.test.js in dist and each reports "No test files found" as before. bot still runs its 3 files.

(The counts are from this branch, which predates form-definition.test.ts from #261. With that merged it is 11 files.)

- apps/web: `pnpm build` now aborts with a clear message when NODE_ENV is set
  to anything other than production. A sourced local .env (NODE_ENV=
  development) otherwise breaks the prerender of /_global-error with a React
  useContext error that points in the wrong direction. CI and the deploy
  never set NODE_ENV, so they are unaffected.
- packages/shared: vitest only collects src/**/*.test.ts. `tsc` emits the
  test files into dist/, which vitest collected as well, so CI ran every
  shared suite twice and local counts depended on whether dist existed.
db, ui, i18n and realtime also compile with tsc into dist/ and have no
vitest config. They have no tests today, so nothing runs twice yet, but the
first test added to any of them would also run from its compiled copy, the
same way packages/shared did. bot and web don't emit (noEmit / next build).
@Musiker15
Musiker15 merged commit 944f0a7 into main Sep 16, 2026
4 checks passed
@Musiker15
Musiker15 deleted the chore/build-guard-and-test-dist branch September 16, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant