Skip to content

[Test Migration] Pt 2 - move packages/core from Karma to Vitest#7709

Open
cameronjoyner wants to merge 32 commits intodevelopfrom
cj/vitest-core
Open

[Test Migration] Pt 2 - move packages/core from Karma to Vitest#7709
cameronjoyner wants to merge 32 commits intodevelopfrom
cj/vitest-core

Conversation

@cameronjoyner
Copy link
Contributor

@cameronjoyner cameronjoyner commented Jan 14, 2026

Background

Why Vitest instead of Karma?
Karma is a tool that allows you to execute JavaScript code in multiple real browsers. It was deprecated in April of 2023 and they even recommend moving to Jest or Vitest. Online you can find folks who maintain similar products pondering which to switch to [example 1, example 2]

Vitest’s documentation claims that their product can live in harmony with Jest, however it would be duplicative. They claim:

Vitest is an interesting option as it gives you a faster run for your unit tests and a jump in DX thanks to the default watch mode using Vite instant Hot Module Reload (HMR). Vitest offers compatibility with most of the Jest API and ecosystem libraries, so in most projects, it should be a drop-in replacement for Jest.

Moving away from Karma also aligns with the precedent set in packages/labs

Why not Jest?
Vitest intentionally mirrors Jest's API (describe, it, expect, mocking, etc), runs faster, and includes a built-in UI for browsing test results, better inline snapshots, and native support for features like concurrent test execution

Why move off of Chai?
Mocha is a test framework running on Node.js and in the browser. Mocha is a popular choice for server-side testing. Mocha is highly configurable and does not include certain features by default. For example, it does not come with an assertion library, which is why we use the popular Mocha assertions complement, Chai.

We originally introduced it in #1741, 8 years ago. I don’t see its usage/existence as a bad thing, but by moving off of Chai we may be able to naturally move off of Mocha.

Differences between Labs and Core

packages/core (Old) packages/labs (New)
Test Runner Karma + Mocha Vitest
File Naming *Tests.tsx *.test.tsx
File Location Separate test/ dir Colocated with source
Assertions Chai (.to.be.true) Vitest (.toBe(true))
Mocking Sinon (spy, stub) Vitest (vi.fn(), vi.spyOn())
Test Discovery Manual imports in test/index.ts Glob pattern auto-discovery
DOM Environment Real browser via Karma jsdom

FLUPs to this PR
Move tests to adhere to colocation standards in /labs then migrate other packages to vitest, rinse, repeat


Changes proposed in this pull request:

Migrate packages/core from Karma to Vitest


Must give due credit to Greg's initial exploration in gdouglas/vitest-experiment

@changelog-app
Copy link

changelog-app bot commented Jan 14, 2026

Generate changelog in packages/core/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[DRAFT] Migrate packages/core from Karma to Vitest


Generate changelog in packages/test-commons/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[DRAFT] Migrate packages/core from Karma to Vitest


Check the box to generate changelog(s)

  • Generate changelog entry

@svc-palantir-github
Copy link

ran pnpm format on overlay2Tests

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

noEmit and skipLibCheck

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

further simplications

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@cameronjoyner cameronjoyner marked this pull request as ready for review January 20, 2026 16:48
@cameronjoyner cameronjoyner changed the title [DRAFT] Migrate packages/core from Karma to Vitest Migrate packages/core from Karma to Vitest Jan 20, 2026
import { sleep } from "../utils";

describe("<ResizeSensor>", () => {
describe.skip("<ResizeSensor>", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a plan for how we should implement these sorts of tests that are more reliant on web APIs?

@svc-palantir-github
Copy link

centralize dependencies in one location

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

central naming

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Comment on lines 50 to 155
export function createBlueprintVitestConfig(options: BlueprintVitestOptions = {}) {
const { include = ["test/**/*Tests.{ts,tsx}"], exclude = [], includeEnzyme = true } = options;

const setupFile = includeEnzyme
? "@blueprintjs/test-commons/vitest.setup"
: "@blueprintjs/test-commons/vitest-setup-no-enzyme";

return defineConfig({
plugins: [react()],
test: {
environment: "jsdom",
exclude: ["lib/**", "node_modules/**", ...exclude],
include,
setupFiles: setupFile,
},
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@svc-palantir-github
Copy link

fixing lint

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

prettier

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

linter error + vitest coverage

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@cameronjoyner cameronjoyner changed the title Migrate packages/core from Karma to Vitest [Test Migration] Pt 2 - move packages/core from Karma to Vitest Jan 22, 2026
@svc-palantir-github
Copy link

Compressing to one commit

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@cameronjoyner cameronjoyner changed the base branch from develop to cj/package-json-alignment January 22, 2026 22:46
@svc-palantir-github
Copy link

pnpm install

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

fix lint

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

it("renders hotkey label", () => {
render(<Hotkey combo="cmd+C" label="test copy me" group="editing" />);
expect(screen.getByText("test copy me")).not.to.be.undefined;
expect(screen.getByText("test copy me")).to.not.be.undefined;
Copy link
Contributor

@ggdouglas ggdouglas Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Similar to above, I think this would be better described by:

Suggested change
expect(screen.getByText("test copy me")).to.not.be.undefined;
expect(screen.getByText("test copy me")).toBeInTheDocument();

see: https://testing-library.com/docs/guide-disappearance

"lib": ["dom", "dom.iterable", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"],
"noEmit": true
"noEmit": true,
"skipLibCheck": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the last PR, is there anything necessitating these changes to the tsconfig.json files? Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I added this back and want to reopen the discussion. I did this today to skip type-checking for .d.ts files.

I believe this has to do with moduleResolution.

In /core/src/design-tokens/tsconfig.json: "moduleResolution": "Bundler",

In /config/tsconfig.web.json: "moduleResolution": "node",

In /config/tsconfig.node.json: "moduleResolution": "node16",

packages/core/test/tsconfig.json
└── extends: ../src/tsconfig.json
└── extends: config/tsconfig.web.json

Still investigating. It seems that use of bundler is partially to blame for this.

"enzyme": "^3.11.0",
"karma": "^6.4.2",
"@vitejs/plugin-react": "catalog:",
"@vitest/coverage-v8": "catalog:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the @vitest/coverage-v8 dep used? Should it be included in the test-commons deps?

@svc-palantir-github
Copy link

responding to usage of toBeInTheDocument

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

dedupe

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

addressing usage of after() and before()

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

* Licensed under the Apache License, Version 2.0 (the "License");
*/

/// <reference types="@testing-library/jest-dom/vitest" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggdouglas I haven't worked a ton with *.d.ts files and am wondering if this file is unnecessarily exporting export { test, it, beforeAll, afterAll, describe, beforeEach, afterEach, expect, assert, vi } from "vitest";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that I can use /// <reference types="@testing-library/jest-dom/vitest" /> in a normal .ts file

@svc-palantir-github
Copy link

removing a dep from package.json

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

removing unused dep from /core

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

skip type-checking of declaration files (.d.ts)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

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.

3 participants