Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ export default [
]
```

### Custom Fixtures

If you're using custom fixtures in a separate file and importing them in your tests, you can let the plugin know about them by adding them to the `vitestImports` setting. The property accepts an array of strings or regular expressions that match the module names where your custom fixtures are defined.

```js
import vitest from '@vitest/eslint-plugin'

export default [
{
files: ['tests/**'], // or any other pattern
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
},
settings: {
vitest: {
vitestImports: ['@/tests/fixtures', /test-extend$/],
},
},
},
]
```

### Shareable configurations

#### Recommended
Expand Down
10 changes: 9 additions & 1 deletion src/utils/parse-vitest-fn-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ const resolveVitestFn = (
}

if (maybeImport) {
if (maybeImport.source === 'vitest') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const vitestImports = context.settings.vitest?.vitestImports ?? []
const isVitestImport = maybeImport.source === 'vitest' ||
vitestImports.some((importName: unknown) => importName instanceof RegExp
? importName.test(maybeImport.source)
: maybeImport.source === importName)

if (isVitestImport) {
return {
original: maybeImport.imported,
local: maybeImport.local,
Expand Down
57 changes: 57 additions & 0 deletions tests/valid-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,63 @@ ruleTester.run(RULE_NAME, rule, {
},
],
},
{
code: `import { test } from './test-extend'
test('the correct way to properly handle all things', () => {})
`,
settings: {
vitest: {
vitestImports: ['./test-extend']
}
},
options: [{ disallowedWords: ['correct'] }],
errors: [
{
messageId: 'disallowedWord',
data: { word: 'correct' },
column: 12,
line: 2,
},
],
},
{
code: `import { test } from '@/tests/fixtures'
test('the correct way to properly handle all things', () => {})
`,
settings: {
vitest: {
vitestImports: ['@/tests/fixtures']
}
},
options: [{ disallowedWords: ['correct'] }],
errors: [
{
messageId: 'disallowedWord',
data: { word: 'correct' },
column: 12,
line: 2,
},
],
},
{
code: `import { test } from '@/tests/fixtures'
test('the correct way to properly handle all things', () => {})
`,
settings: {
vitest: {
vitestImports: [/\/fixtures$/]
}
},
options: [{ disallowedWords: ['correct'] }],
errors: [
{
messageId: 'disallowedWord',
data: { word: 'correct' },
column: 12,
line: 2,
},
],
},
],
})

Expand Down
Loading