Skip to content

feat(scalajs): Overridable test-time JS env (bunTestJsEnv)#11

Merged
arcaputo3 merged 1 commit into
mainfrom
fix/bun-test-node-env
Apr 17, 2026
Merged

feat(scalajs): Overridable test-time JS env (bunTestJsEnv)#11
arcaputo3 merged 1 commit into
mainfrom
fix/bun-test-node-env

Conversation

@arcaputo3
Copy link
Copy Markdown
Contributor

@arcaputo3 arcaputo3 commented Apr 17, 2026

Summary

Adds an opt-in hook so downstream Scala.js tests can diverge their process environment from production bunRun without having to rebuild the whole test bridge.

  • New: BunScalaJSTests.bunTestJsEnv: T[Map[String, String]] — test-scoped override for the Scala.js test process environment.
  • New: BunScalaJSTests.jsEnvConfig override sources its env from bunTestJsEnv so customizing that map is enough to diverge test env.
  • Default: outer.bunJsEnv() unchanged — no behavior change for existing consumers.

Why

Tests that spin up an in-process Bun.serve({...}) typically want NODE_ENV=production so Bun's development option defaults to false. Otherwise Bun's dev-mode error overlay rewrites any fetch-handler Promise rejection into a ~100 KB HTML BunError React-overlay Response. The test then asserts against overlay HTML instead of the real error, which hides real bugs.

Downstream opt-in:

object test extends BunScalaJSTests:
  override def bunTestJsEnv = Task {
    super.bunTestJsEnv() + ("NODE_ENV" -> "production")
  }

Verification

  • ./mill millbun.compile clean
  • ./mill millbun.publishLocal publishes com.tjclp:mill-bun_mill1_3:0.2.1-SNAPSHOT (via PUBLISH_VERSION env)
  • Downstream consumer (fast-mcp-scala) confirmed: previously-blocked Scala.js HTTP test that POSTs an MCP initialize against Bun.serve now passes once NODE_ENV=production is injected via the new hook.

Follow-up

Suitable for a 0.2.1 patch release. CHANGELOG entry included.

🤖 Generated with Claude Code

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>
@arcaputo3 arcaputo3 merged commit 2dcca20 into main Apr 17, 2026
2 checks passed
@arcaputo3 arcaputo3 deleted the fix/bun-test-node-env branch April 17, 2026 21:29
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