PostHog / PostHog/wizard

Migrate test runner from Jest to vitest

Open
#519 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

wizard-pain
Dominant language
TypeScript
Stars
197
Forks
51
Avg merge
1d 23h
Merged PRs (30d)
94

Description

Why

The wizard's source is already ESM ("type": "module" in package.json), but the test runner is still Jest. Jest's ESM support is opt-in and finicky, which is creating real friction now that the wizard depends on ESM-native packages.

Concrete pain point

The __mocks__/@posthog/warlock.ts file exists solely because Jest can't cleanly load the real @posthog/warlock package — it's ESM-only and loads a YARA-X WASM binary at runtime. The mock substitutes hand-written jest.fn() stand-ins for the real engine just so tests can import without crashing.

Sibling-repo precedent

Both PostHog projects in the same neighborhood already use vitest:

  • warlock: "test": "vitest run"
  • context-mill: "test": "vitest run scripts/plugins/tests scripts/lib/tests"

A migration would unify test tooling across the three repos.

What's in scope

  • Swap jest for vitest in devDependencies and package.json config
  • Convert jest.fn() / jest.mock() calls to vi.fn() / vi.mock() (mostly mechanical)
  • Re-evaluate the warlock mock — vitest's native ESM may eliminate most of it. (WASM-in-test is its own conversation; partial mock may still be needed.)
  • Make sure the smoke-test step in the postbuild flow still runs

What's out of scope

  • Browser-environment changes
  • Test rewrites beyond the framework swap

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with package.json to review the current Jest dependency, configuration, and test and postbuild scripts. Inspect mocks/@posthog/warlock.ts and the existing Jest calls, then run the test command and postbuild smoke-test step. Done means the Vitest suite passes, the smoke test still runs, and the warlock mock is reduced only where the migration permits.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.