Skip to content

fix: switch vitest environment from happy-dom to node#53

Merged
i8ramin merged 1 commit into
mainfrom
fix/vitest-node-environment
Jun 1, 2026
Merged

fix: switch vitest environment from happy-dom to node#53
i8ramin merged 1 commit into
mainfrom
fix/vitest-node-environment

Conversation

@chocothebot

Copy link
Copy Markdown
Collaborator

Problem

9 test suites were failing with Error: No such built-in module: node: because vitest was running them in happy-dom environment, which does not support Node.js built-in modules like crypto.

Root Cause

vitest.config.ts had environment: happy-dom as the default. BOTCHA is a backend/Cloudflare Workers library with zero DOM dependencies (confirmed by grep across all test files), so happy-dom was incorrect.

Fix

One-line change: happy-domnode. Node 22 includes all Web APIs (fetch, crypto.subtle, URL, TextEncoder, etc.) that happy-dom provided, so no existing tests break.

Results

Before After
Test suites 39 ✅ / 9 ❌ 48 ✅ / 0 ❌
Tests 1070 1286 (+216 previously untested)

9 test suites were failing with 'No such built-in module: node:' because
the happy-dom environment doesn't support Node.js built-in modules like
crypto. BOTCHA is a backend/Cloudflare Workers library with no DOM
dependencies, so node environment is correct.

Before: 39 suites passing, 9 failing (1070 tests)
After:  48 suites passing, 0 failing (1286 tests)
@i8ramin i8ramin merged commit 068b4b0 into main Jun 1, 2026
@i8ramin i8ramin deleted the fix/vitest-node-environment branch June 1, 2026 12:21
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

🧹 Preview worker botcha-pr-53 deleted (PR merged).

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.

2 participants