fix(test): preload env-mock so server.ts can be imported in tests #5
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/3-mock-env-for-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Phase 2 of #3
Follow-up to PR #4 (which pinned
bun-version). Once setup-bun stopped failing, the next layer was exposed: server.ts:92 has a required-config guard that callsprocess.exit(1)when MOLECULE_PLATFORM_URL / MOLECULE_WORKSPACE_IDS / MOLECULE_WORKSPACE_TOKENS are unset.Test files import pure helpers (
formatRemovedWorkspaceErroretc.) from server.ts, and the mere act of importing executes the top-level guard — which killsbun testbefore any test runs.Fix
The orchestrator-preferred shape: test-only mock via preload, so local dev / CI behavior aligns and no workflow yaml changes are needed.
tests/setup.ts— sets fake env values via??=(only when unset, so a dev runningbun testwith a populated .env locally isn't overridden).bunfig.toml—[test].preloadruns setup.ts before any test file imports.Verification
Local
bun testreports13 pass / 0 fail / 15 expect() calls / 93ms. server.ts's startup logs are still printed (watchers spin up, can't connect to localhost:18080, log a warning) — that's expected; the pure-helper tests don't depend on the startup state.Test plan
Refs molecule-mcp-claude-channel#3.
Phase 2 of bun pin fix — preload env-mock for server.ts test import. CI green. Independent review.