feat(scalajs): Overridable test-time JS env (bunTestJsEnv)#11
Merged
Conversation
Exposes a new `BunScalaJSTests.bunTestJsEnv: T[Map[String, String]]`
task that feeds the Scala.js test process's environment, and overrides
`jsEnvConfig` inside `BunScalaJSTests` so tests source their env from it.
Defaults to `outer.bunJsEnv()` unchanged — no behavior change for
existing users. Opt-in downstream overrides look like:
object test extends BunScalaJSTests:
override def bunTestJsEnv = Task {
super.bunTestJsEnv() + ("NODE_ENV" -> "production")
}
The motivating case: tests that spin up an in-process `Bun.serve({...})`
want `NODE_ENV=production` so Bun's `development` option defaults to
`false`. Otherwise any fetch-handler Promise rejection gets rewritten
into a ~100 KB HTML `BunError` React-overlay `Response`, and the test
asserts against the overlay HTML instead of the real error — masking
the bug. Giving tests their own env map surfaces those rejections as
proper errors without disturbing `bunRun`/production invocations on
the outer module.
Also adds a CHANGELOG entry documenting the 0.2.1 semantics.
Verified via a downstream `fast-mcp-scala` `publishLocal` round-trip —
a previously-blocked Scala.js HTTP test that POSTs an MCP initialize
request to an in-process `Bun.serve` now passes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in hook so downstream Scala.js tests can diverge their process environment from production
bunRunwithout having to rebuild the whole test bridge.BunScalaJSTests.bunTestJsEnv: T[Map[String, String]]— test-scoped override for the Scala.js test process environment.BunScalaJSTests.jsEnvConfigoverride sources itsenvfrombunTestJsEnvso customizing that map is enough to diverge test env.outer.bunJsEnv()unchanged — no behavior change for existing consumers.Why
Tests that spin up an in-process
Bun.serve({...})typically wantNODE_ENV=productionso Bun'sdevelopmentoption defaults tofalse. Otherwise Bun's dev-mode error overlay rewrites any fetch-handler Promise rejection into a ~100 KB HTMLBunErrorReact-overlayResponse. The test then asserts against overlay HTML instead of the real error, which hides real bugs.Downstream opt-in:
Verification
./mill millbun.compileclean./mill millbun.publishLocalpublishescom.tjclp:mill-bun_mill1_3:0.2.1-SNAPSHOT(viaPUBLISH_VERSIONenv)initializeagainstBun.servenow passes onceNODE_ENV=productionis injected via the new hook.Follow-up
Suitable for a 0.2.1 patch release. CHANGELOG entry included.
🤖 Generated with Claude Code