fix(test): preload env-mock so server.ts can be imported in tests (closes #3 phase 2)
All checks were successful
Test / bun test (pull_request) Successful in 21s
All checks were successful
Test / bun test (pull_request) Successful in 21s
server.ts:92 has a required-config guard that calls process.exit(1) when MOLECULE_PLATFORM_URL / MOLECULE_WORKSPACE_IDS / MOLECULE_WORKSPACE_TOKENS are unset. Test files import pure helpers from server.ts (formatRemovedWorkspaceError + others), and the mere act of importing executes server.ts top-level — including that guard — which kills the test runner before any test runs. Fix: add tests/setup.ts that sets fake values via ??= (only when unset, so a dev running 'bun test' with a populated .env locally isn't overridden), and bunfig.toml [test].preload that runs setup.ts before any test file imports. Verified locally: 13 pass / 0 fail. The server.ts boot path still runs during tests (watchers spin up, fail to connect to localhost:18080, log a warning) but doesnt affect the pure-helper tests. Phase 2 of mcp-claude-channel#3 — Phase 1 was the bun-version pin in PR #4 (one CI hop earlier; setup-bun is no longer the failure point). This PR addresses the *test setup* failure that became visible once setup-bun stopped masking it.
This commit is contained in:
parent
25e1cc2770
commit
1a988eba1a
6
bunfig.toml
Normal file
6
bunfig.toml
Normal file
@ -0,0 +1,6 @@
|
||||
# bunfig.toml — preload the test env-mock setup so server.ts's
|
||||
# required-config guard doesn't call process.exit(1) when test files
|
||||
# import pure helpers from it. See tests/setup.ts for the full
|
||||
# rationale.
|
||||
[test]
|
||||
preload = ["./tests/setup.ts"]
|
||||
15
tests/setup.ts
Normal file
15
tests/setup.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// tests/setup.ts — preloaded by bunfig.toml's [test].preload before any
|
||||
// test file is imported. Sets fake values for the three env vars
|
||||
// server.ts requires at top-level (MOLECULE_PLATFORM_URL,
|
||||
// MOLECULE_WORKSPACE_IDS, MOLECULE_WORKSPACE_TOKENS). Without this,
|
||||
// importing server.ts (which the test files do, to pull
|
||||
// formatRemovedWorkspaceError + other pure helpers) hits the
|
||||
// required-config guard at server.ts:92 and calls process.exit(1) —
|
||||
// killing the test runner before any test runs.
|
||||
//
|
||||
// `??=` only assigns when the var is unset, so a developer running
|
||||
// `bun test` locally with a populated .env file isn't overridden.
|
||||
|
||||
process.env.MOLECULE_PLATFORM_URL ??= 'http://localhost:18080'
|
||||
process.env.MOLECULE_WORKSPACE_IDS ??= 'ws-test-00000000-0000-0000-0000-000000000001'
|
||||
process.env.MOLECULE_WORKSPACE_TOKENS ??= 'tok-test'
|
||||
Loading…
Reference in New Issue
Block a user