Skip to content

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Feb 25, 2025

Ref #11084

Before: 6.437 s

After: 1.23s

The first thing we did was migrate the pretest.ts script to use a vitest global setup instead. This is cleaner, and should ensure it never gets lost in refactors either.

After that we did the conversion. The trickiest thing to change was packages/gatsby/test/gatsby-node.test.ts, as gatsby-node.js is a CJS file. This is tricky to patch properly with vitest for the spy. To get around this, we monkeypatch Module._load temporarily to load a stub which we defined in vi.hoisted (which hoists it to the top so it's always available).

@AbhiPrasad AbhiPrasad requested review from timfish and a team February 25, 2025 17:43
@AbhiPrasad AbhiPrasad self-assigned this Feb 25, 2025
@AbhiPrasad AbhiPrasad requested review from stephanie-anderson and chargome and removed request for a team February 25, 2025 17:43
@AbhiPrasad AbhiPrasad merged commit 06d2479 into develop Feb 25, 2025
28 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-vitest-gatsby branch February 25, 2025 20:05
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