Standard Toolkit
Tooling@accelint/vitest-config

no-dom

Base Vitest configuration for Node.js and non-DOM testing

Base Vitest configuration for testing Node.js code and libraries without DOM dependencies. Includes TypeScript path resolution, Istanbul coverage, and sensible test defaults.

Usage

import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/no-dom';

export default mergeConfig(
  baseConfig,
  defineConfig({
    test: {
      // Your custom test configuration
    },
  }),
);

Reference

export default defineConfig({
  plugins: [tsconfigPaths()],
  test: {
    watch: false,
    coverage: {
      provider: 'istanbul',
      reporter: ['json', 'json-summary', 'lcov', 'text'],
      reportsDirectory: './coverage',
      enabled: true,
      clean: true,
      passWithNoTests: true,
    },
    clearMocks: true,
    mockReset: true,
    restoreMocks: true,
    passWithNoTests: true,
  },
});

Plugins

PluginPurpose
vite-tsconfig-pathsResolves TypeScript path aliases from tsconfig.json

Test Configuration

SettingValueDescription
watchfalseDisables watch mode (run once)
clearMockstrueClears mock calls between tests
mockResettrueResets mock implementations between tests
restoreMockstrueRestores original implementations after tests
passWithNoTeststrueSucceeds when no test files found

Coverage Configuration

SettingValueDescription
provider'istanbul'Uses Istanbul coverage provider
reporter['json', 'json-summary', 'lcov', 'text']Generates multiple coverage formats
reportsDirectory'./coverage'Output directory for coverage reports
enabledtrueCoverage enabled by default
cleantrueClears previous coverage before running
passWithNoTeststrueCoverage passes when no tests exist

Examples

Example: Simple re-export

For projects that don't need custom configuration:

// vitest.config.ts
export { default } from '@accelint/vitest-config/no-dom';

Example: Library testing with custom paths

import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/no-dom';

export default mergeConfig(
  baseConfig,
  defineConfig({
    test: {
      include: ['src/**/*.test.ts'],
      exclude: ['**/node_modules/**', '**/dist/**'],
    },
  }),
);

Example: Adding coverage thresholds

import { defineConfig, mergeConfig } from 'vitest/config';
import baseConfig from '@accelint/vitest-config/no-dom';

export default mergeConfig(
  baseConfig,
  defineConfig({
    test: {
      coverage: {
        thresholds: {
          lines: 80,
          functions: 80,
          branches: 80,
          statements: 80,
        },
        exclude: [
          '**/*.config.*',
          '**/mocks/**',
          '**/*.test.ts',
        ],
      },
    },
  }),
);

Example: TypeScript path resolution

With this tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@utils/*": ["./src/utils/*"]
    }
  }
}

Paths resolve automatically in tests:

import { helper } from '@/utils/helper';
import { format } from '@utils/format';

describe('helper', () => {
  it('works with path aliases', () => {
    expect(helper()).toBeDefined();
  });
});

Example: Running tests

# Run tests once
vitest run

# Run with UI
vitest --ui

# Run with coverage
vitest run --coverage

# Watch mode (overrides config)
vitest

Good to know: The no-dom configuration is the foundation for the dom preset. Use this preset for Node.js libraries, utilities, and backend code. For React components or browser APIs, use the dom preset instead.

On this page