Repository navigation
Migrate browser tests from karma to Vitest browser mode - #304
Merged
Merged
Conversation
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.
Merged
typeof window === "undefined" also matches Web Workers and Deno. Check for Buffer directly, and use process.versions.node for node:zlib.
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
vitest.config.mtsdefines two projects,nodeandbrowser, over the same test files:npm test:vitest run --project nodenpm run test:browser:vitest run --project browserkarma,karma-*,mocha, and@types/mocha. karma is deprecated, and karma-typescript runs out of memory with TypeScript >= 5.3.browser.ymlnow sets up Node 24 and installs Chromium vianpx playwright install --with-deps chromium.Test changes
Node built-ins are no longer polyfilled in the browser, so:
node:assertcalls are replaced with Vitest'sexpect. The conversion was mechanical, done with an AST-based codemod:deepStrictEqual→toStrictEqual,ok→toBeTruthy,throws→toThrow, and so on.Buffervariants of the test suites run only on Node. In the browser, only theUint8Arrayvariants run.Buffer:Buffer.alloc/Buffer.from(hex)→Uint8Array/hexToBuf, and expected buffers usefactory.Bug fix: the zlib wrapper test returned early on
instanceof Uint8Array, which is also true forBuffer, so it never actually ran. It now runs on Node for both variants.Testing
npm test: 166 passednpm run test:browser: 82 passed, 1 skipped (zlib)npm run buildandnpm run formatpass