Skip to content

Latest commit

 

History

History
90 lines (77 loc) · 22.2 KB

vitest.md

File metadata and controls

90 lines (77 loc) · 22.2 KB

vitest config

Config for projects using Vitest for testing.

🏗️ Setup

  1. If you haven't already, make sure to install @code-pushup/eslint-config and its required peer dependencies.

  2. Since this plugin requires additional peer dependencies, you have to install them as well:

    npm install -D eslint-plugin-{jest-formatting,vitest}
  3. Add to your eslint.config.js file:

    import vitest from '@code-pushup/eslint-config/vitest.js';
    import tseslint from 'typescript-eslint';
    
    export default tseslint.config(
      ...vitest,
      {
        // customize rules if needed:
        rules: {
          // e.g. to customize file naming convention (default pattern is '.*\\.spec\\.[tj]sx?$'):
          'vitest/consistent-test-filename': [
            'warn',
            { 'pattern': '.*\\.(unit|integration|e2e)\\.test\\.ts$' }
          ],
          // e.g. to customize `test` or `it` usage (default is `it` in `describe` and `test` at top-level):
          'vitest/consistent-test-it': ['warn', { fn: 'test', withinDescribe: 'test' }]
        }
      }
    );

📏 Rules (41)

🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.

🚨 Errors (8)

Plugin Rule Options Autofix Overrides
vitest expect-expect
enforce having expectation in test body
vitest no-commented-out-tests
disallow commented out tests
vitest no-identical-title
disallow identical titles
🔧
vitest no-import-node-test
disallow importing node:test
🔧
vitest require-local-test-context-for-concurrent-snapshots
require local Test Context for concurrent snapshot tests
vitest valid-describe-callback
enforce valid describe callback
vitest valid-expect
enforce valid expect() usage
vitest valid-title
enforce valid titles
🔧

⚠️ Warnings (33)

Plugin Rule Options Autofix Overrides
jest-formatting padding-around-after-all-blocks
🔧
jest-formatting padding-around-after-each-blocks
🔧
jest-formatting padding-around-before-all-blocks
🔧
jest-formatting padding-around-before-each-blocks
🔧
jest-formatting padding-around-describe-blocks
🔧
jest-formatting padding-around-test-blocks
🔧
vitest consistent-test-filename
require .spec test file pattern
pattern: .*\.spec\.[tj]sx?$
{
  "pattern": ".*\\.spec\\.[tj]sx?$"
}
vitest consistent-test-it
enforce using test or it but not both
🔧
vitest max-nested-describe
require describe block to be less than set max value or default value
max: 2
{
  "max": 2
}
vitest no-alias-methods
disallow alias methods
🔧
vitest no-conditional-expect
disallow conditional expects
vitest no-conditional-tests
disallow conditional tests
vitest no-disabled-tests
disallow disabled tests
vitest no-done-callback
disallow using a callback in asynchronous tests and hooks
💡
vitest no-duplicate-hooks
disallow duplicate hooks and teardown hooks
vitest no-focused-tests
disallow focused tests
🔧
vitest no-mocks-import
disallow importing from mocks directory
vitest no-standalone-expect
disallow using expect outside of it or test blocks
vitest no-test-return-statement
disallow return statements in tests
vitest prefer-comparison-matcher
enforce using the built-in comparison matchers
🔧
vitest prefer-each
enforce using each rather than manual loops
vitest prefer-equality-matcher
enforce using the built-in quality matchers
💡
vitest prefer-expect-resolves
enforce using expect().resolves over expect(await ...) syntax
🔧
vitest prefer-hooks-on-top
enforce having hooks before any test cases
vitest prefer-mock-promise-shorthand
enforce mock resolved/rejected shorthands for promises
🔧
vitest prefer-spy-on
enforce using vi.spyOn
🔧
vitest prefer-to-be
enforce using toBe()
🔧
vitest prefer-to-contain
enforce using toContain()
🔧
vitest prefer-to-have-length
enforce using toHaveLength()
🔧
vitest prefer-todo
enforce using test.todo
🔧
vitest require-hook
require setup and teardown to be within a hook
vitest require-to-throw-message
require toThrow() to be called with an error message
vitest require-top-level-describe
enforce that all tests are in a top-level describe