Skip to content

Migrate browser tests from karma to Vitest browser mode - #304

Merged
keichi merged 2 commits into
masterfrom
migrate-browser-tests-to-vitest
Oct 15, 2026
Merged

keichi merged 2 commits into
masterfrom
migrate-browser-tests-to-vitest

Conversation

@keichi

@keichi keichi commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Run the browser tests with Vitest browser mode (Playwright, headless Chromium) instead of karma. vitest.config.mts defines two projects, node and browser, over the same test files:
    • npm test: vitest run --project node
    • npm run test:browser: vitest run --project browser
  • Remove karma, karma-*, mocha, and @types/mocha. karma is deprecated, and karma-typescript runs out of memory with TypeScript >= 5.3.
  • browser.yml now sets up Node 24 and installs Chromium via npx playwright install --with-deps chromium.

Test changes

Node built-ins are no longer polyfilled in the browser, so:

  • node:assert calls are replaced with Vitest's expect. The conversion was mechanical, done with an AST-based codemod: deepStrictEqual → toStrictEqual, ok → toBeTruthy, throws → toThrow, and so on.
  • The Buffer variants of the test suites run only on Node. In the browser, only the Uint8Array variants run.
  • Test data no longer depends on Buffer: Buffer.alloc / Buffer.from(hex) → Uint8Array / hexToBuf, and expected buffers use factory.
  • The zlib wrapper test is skipped in the browser.

Bug fix: the zlib wrapper test returned early on instanceof Uint8Array, which is also true for Buffer, so it never actually ran. It now runs on Node for both variants.

Testing

  • npm test: 166 passed
  • npm run test:browser: 82 passed, 1 skipped (zlib)
  • npm run build and npm run format pass

karma is deprecated and karma-typescript runs out of memory with
TypeScript >= 5.3. Run the same test files in Chromium via Vitest browser
mode (Playwright) and remove karma and mocha.

- Replace node:assert with Vitest's expect, since Node built-ins are not
  polyfilled in the browser.
- Run the Buffer variants and the zlib wrapper test only on Node.
- The zlib wrapper test returned early for every factory (Buffer is also a
  Uint8Array), so it never actually ran. It now runs on Node.
@keichi keichi mentioned this pull request Oct 15, 2026
typeof window === "undefined" also matches Web Workers and Deno. Check
for Buffer directly, and use process.versions.node for node:zlib.
@keichi
keichi merged commit 0b7e472 into master Oct 15, 2026
6 checks passed
@keichi
keichi deleted the migrate-browser-tests-to-vitest branch October 15, 2026 14:14
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