npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-vitest-globals

v1.6.1

Published

ESLint plugin for Vitest globals

Readme

eslint-plugin-vitest-globals

ESLint plugin for Vitest globals

NPM version Codacy Badge Known Vulnerabilities npm download License

Sonar

Change Log

Installation

# pnpm
pnpm add -D eslint-plugin-vitest-globals

# npm
npm install -D eslint-plugin-vitest-globals

# yarn
yarn add -D eslint-plugin-vitest-globals

Usage

Classic Config (ESLint 8 and below)

Option 1: Apply to all files

{
  "extends": ["plugin:vitest-globals/recommended"]
}

Option 2: Apply only to test files (Recommended)

{
  "overrides": [
    {
      "files": ["**/__tests__/**/*.[jt]s?(x)", "**/*.test.[jt]s?(x)", "**/*.spec.[jt]s?(x)"],
      "extends": ["plugin:vitest-globals/recommended"]
    }
  ]
}

Option 3: Using environment only

If you only need the globals without the base config:

{
  "plugins": ["vitest-globals"],
  "env": {
    "vitest-globals/env": true
  }
}

Option 4: With overrides and environment

{
  "overrides": [
    {
      "files": ["**/*.test.js", "**/*.spec.js"],
      "plugins": ["vitest-globals"],
      "env": {
        "vitest-globals/env": true
      }
    }
  ]
}

Flat Config (ESLint 9+)

Option 1: Using the recommended config

// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  {
    files: ['**/*.test.js', '**/*.spec.js'],
    ...vitestGlobals.configs['flat/recommended']
  }
]

Option 2: Using the base config

// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  {
    files: ['**/*.test.js', '**/*.spec.js'],
    ...vitestGlobals.configs['flat/base']
  }
]

Option 3: With TypeScript files

// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  {
    files: ['**/*.test.ts', '**/*.spec.ts'],
    ...vitestGlobals.configs['flat/recommended']
  }
]

Option 4: With JavaScript and TypeScript

// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  {
    files: ['**/*.test.{js,ts}', '**/*.spec.{js,ts}', '**/__tests__/**/*.{js,ts}'],
    ...vitestGlobals.configs['flat/recommended']
  }
]

Option 5: Custom configuration

// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  {
    files: ['tests/**/*.js'],
    plugins: {
      'vitest-globals': vitestGlobals
    },
    languageOptions: {
      globals: {
        ...vitestGlobals.environments.env.globals
      }
    }
  }
]

Supported Globals

The plugin provides the following Vitest globals:

Test Functions

| Global | Description | | ----------- | --------------------------- | | suite | Define a test suite | | test | Define a test | | describe | Define a test suite (alias) | | it | Define a test (alias) | | xtest | Skip a test | | xit | Skip a test (alias) | | xdescribe | Skip a suite | | bench | Define a benchmark | | benchmark | Define a benchmark (alias) |

Assertions

| Global | Description | | -------- | ---------------------- | | expect | Assertion function | | assert | Assert function | | chai | Chai assertion library |

Type Checking

| Global | Description | | -------------- | --------------------- | | expectTypeOf | Runtime type checking | | assertType | Type assertion |

Utilities

| Global | Description | | -------- | ------------------- | | vi | Vitest mock utility | | vitest | Vitest instance |

Hooks

| Global | Description | | ---------------- | --------------------------- | | beforeAll | Run before all tests | | afterAll | Run after all tests | | beforeEach | Run before each test | | afterEach | Run after each test | | onTestFinished | Callback when test finishes | | onTestFailed | Callback when test fails |

Compatibility

| ESLint Version | Config Type | Supported | | -------------- | -------------- | --------- | | ESLint 8.x | Classic Config | ✅ | | ESLint 8.x | Flat Config | ✅ | | ESLint 9.x | Flat Config | ✅ |

| Prettier Version | Compatible | | ---------------- | ---------- | | Prettier 2.x | ✅ | | Prettier 3.x | ✅ |

TypeScript Support

This plugin includes TypeScript type definitions. No additional @types package is needed.

// example.test.ts
// No imports needed - globals are automatically available

describe('TypeScript test', () => {
  it('should work with types', () => {
    expect(1 + 1).toBe(2)
  })
})

Vitest Configuration

To enable Vitest globals, add globals: true to your Vitest config:

// vitest.config.js
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    globals: true
  }
})

Example with Prettier

This plugin works seamlessly with Prettier:

{
  "extends": ["plugin:vitest-globals/recommended", "prettier"]
}

Support & Issues

Please open an issue here.

License

MIT