Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
eslint-vitest-rule-tester
Advanced tools
ESLint rule tester with Vitest.
This module requires ESLint v9.0+.
npm i -D eslint-vitest-rule-tester
Simliar style to ESLint's TestRunner
(test cases with implicit test suites)
import { run } from 'eslint-vitest-rule-tester'
run('rule-name', rule, {
valid: [
// test cases
],
invalid: [
// test cases
],
}, {
// the default flat configs
configs: {
languageOptions: {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
}
})
output
output
field can be a function to do custom assertion. This would also be compatible with snapshot testing.
import { run } from 'eslint-vitest-rule-tester'
import { expect } from 'vitest'
run('rule-name', rule, {
invalid: [
{
input: 'let foo = 1',
output(output) {
expect(output)
.toMatchInlineSnapshot(`"const foo = 1;"`)
},
},
],
})
errors
errors
field can be a function to do custom assertion, same as output
.
import { run } from 'eslint-vitest-rule-tester'
import { expect } from 'vitest'
run('rule-name', rule, {
invalid: [
{
input: 'let foo = 1',
errors(errors) {
expect(errors.map(e => e.messageId))
.toMatchInlineSnapshot(`["error-message-id"]`)
},
},
],
})
onResult
hookonResult
field can be an function to do custom assertion with the entire result object.
import { run } from 'eslint-vitest-rule-tester'
import { expect } from 'vitest'
run('rule-name', rule, {
invalid: [
'let foo = 1',
],
onResult(testCase, result) {
if (testCase.type === 'invalid')
expect(result).toMatchSnapshot()
// here you can't use `toMatchInlineSnapshot` because it's not in the test case
},
})
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: {
// flat config options
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()
})
})
MIT License © 2024-PRESENT Anthony Fu
FAQs
ESLint rule tester with Vitest
The npm package eslint-vitest-rule-tester receives a total of 19,908 weekly downloads. As such, eslint-vitest-rule-tester popularity was classified as popular.
We found that eslint-vitest-rule-tester demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.