@native-dom/vitest
v0.0.10
Published
Vitest environment backed by native-dom.
Downloads
114
Readme
@native-dom/vitest
Vitest environment for native-dom.
This package creates a Window from @native-dom/runtime, copies compatible host globals such as fetch, Blob, URL, and typed arrays into the window when needed, then uses Vitest's populateGlobal() helper to install browser globals for each test environment.
Usage
// vitest.config.ts
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "native-dom"
}
});Install vitest-environment-native-dom for the config above. Vitest resolves custom environments by package name, so environment: "native-dom" loads vitest-environment-native-dom, which re-exports this package.
For CLI experiments you can also point Vitest at the built environment file:
pnpm exec vitest run --environment ./node_modules/@native-dom/vitest/dist/index.jsProfiling
Set NATIVE_DOM_VITEST_PROFILE=1 to emit setup and teardown timing records to stderr:
NATIVE_DOM_VITEST_PROFILE=1 pnpm exec vitest runThe benchmark harness parses these records to track environment overhead in real-world suites.
Compatibility Switches
Set NATIVE_DOM_VITEST_DISABLE_MATCH_MEDIA=1 when a suite installs its own
matchMedia mock only if the API is missing. This keeps those suites on their
existing mock path while still using native-dom for the rest of the environment.
Legacy Entry
src/legacy.ts exports the same environment with transformMode: "web" for older Vitest suites that still depend on the legacy environment shape.
Development
pnpm --filter @native-dom/vitest build
pnpm --filter @native-dom/vitest typecheck
pnpm --filter @native-dom/vitest test