Skip to main content

Getting My Website's Unit Tests from 12 to 4 Seconds

Created: 2026-11-17
3 min read
Vitest
Next.js
Vercel
Tooling
Meta

I have written about this website's build times before. More recently, I switched from ESLint with eslint-config-next and typescript-eslint to Oxlint. The ESLint setup was slower in this project, and the installed typescript-eslint version did not support native TypeScript 7.0 because it depended on the JavaScript compiler API that release did not provide.

Native Oxlint rules removed that blocker and let me upgrade to TypeScript 7, with type checking still handled separately by tsc --noEmit. With linting faster, I looked at the unit tests.

In the latest production comparison, execution time for the same 1,407 tests across 154 files fell from 12.14 to 4.01 seconds. A surprisingly large part of the improvement came from one test fixture.

A test fixture with too many dependencies

My lint-policy tests create a temporary project and run Oxlint against small programs to verify which patterns the rules accept or reject. That project also had a symlink to the repository's entire node_modules directory.

The symlink came from the first stage of my ESLint-to-Oxlint migration. The temporary configuration still loaded JavaScript compatibility plugins for React, Hooks, and Next.js, so it needed access to those installed packages. When I switched to native Oxlint rules, I removed the plugins but left the symlink behind.

By the time I profiled the tests, the fixtures only needed their source files, the lint configuration, and the Oxlint executable, which was already called through an absolute path.

Removing the symlink reduced that suite's reported time from 9.753 to 0.159 seconds in two Vercel preview runs. All 29 policy cases still ran.

Retuning Vitest after fixing the fixture

Vitest was limited to four workers on a 30-core build machine. In the first comparison, eight workers beat sixteen. After removing the fixture's dependency link, sixteen became faster, so that is what I kept:

TypeScript
import { defineConfig } from 'vitest/config';

export default defineConfig({
    test: {
        pool: 'threads',
        maxWorkers: 16,
    },
});

That ordering mattered. Tuning workers before fixing the expensive fixture gave me a different answer.

Per-file isolation stays enabled. Disabling it caused existing tests to fail, so I dropped that experiment.

Importing only the Google APIs I use

I found more unnecessary dependency loading in the sitemap utility: the root googleapis import loaded every generated API. Switching to the Webmasters and Search Console entry points from the same package cut compiler memory in fresh local TypeScript checks from about 1.54 GB to 0.65 GB. Cached preview builds did not show a further speedup.

The production numbers

MeasurementBeforeAfter
Unit test stage12.14s4.01s
Vercel's Build Completed log duration29s19s
Build start until deployment ready37.9s30.3s

These are individual production runs, both with a restored cache on the same 30-core machine. The build-log duration fell by about 34%; the full time from build start until the deployment was ready fell by about 20%.

The build still runs lint, all unit tests, blog validation, RSS generation, Next.js compilation, and both TypeScript checks in sequence.