eslint-vitest-rule-tester
ESLint rule tester with Vitest.
This module requires ESLint v9.0+.
Install
npm i -D eslint-vitest-rule-tester
Usage
Classical Usage
Simliar style to ESLint's TestRunner
(test cases with implicit test suites)
import { run } from 'eslint-vitest-rule-tester'
run('rule-name', rule, {
valid: [
],
invalid: [
],
}, {
configs: {
languageOptions: {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
}
})
Explicit Test Suites
import { createRuleTester } from 'eslint-vitest-rule-tester'
import { describe, expect, it } from 'vitest'
describe('rule-name', () => {
const { valid, invalid } = createRuleTester({
name: 'rule-name',
rule,
configs: {
languageOptions: {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
}
})
it('valid case 1', () => {
valid('const foo = 1')
})
it('invalid case 1 with snapshot', () => {
const result = invalid({
input: 'const foo = 1',
errors: ['error-message-id'],
})
expect(result.output).toMatchSnapshot()
})
})
License
MIT License © 2024-PRESENT Anthony Fu