Skip to content

Commit

Permalink
test: use uvu to run rule tests for better reports (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Oct 20, 2021
1 parent c392618 commit 44e0829
Show file tree
Hide file tree
Showing 30 changed files with 2,063 additions and 1,680 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
// TODO: Use `@typescript-eslint/no-restricted-imports` once https://github.com/typescript-eslint/typescript-eslint/pull/3996 is available.
'no-restricted-imports': [
'error',
{
patterns: ['@typescript-eslint/experimental-utils/dist/*'],
},
],
curly: 'error',
},
}
69 changes: 41 additions & 28 deletions tests/rules/avoid-combining-selectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import type {
ESLintUtils,
TSESLint,
} from '@typescript-eslint/experimental-utils'
import { fromFixture } from 'eslint-etc'
import path from 'path'
import { test } from 'uvu'
import rule, {
messageId,
} from '../../src/rules/store/avoid-combining-selectors'
import { ruleTester } from '../utils'

ruleTester().run(path.parse(__filename).name, rule, {
valid: [
`
type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule>
type Options = ESLintUtils.InferOptionsTypeFromRule<typeof rule>
type RunTests = TSESLint.RunTests<MessageIds, Options>

const valid: RunTests['valid'] = [
`
import { Store } from '@ngrx/store'
class Ok {
readonly test$ = somethingOutside();
}`,
`
`
import { Store } from '@ngrx/store'
class Ok1 {
Expand All @@ -23,23 +31,23 @@ class Ok1 {
this.vm$ = store.select(selectItems)
}
}`,
`
`
import { Store, select } from '@ngrx/store'
class Ok2 {
vm$ = this.store.pipe(select(selectItems))
constructor(private store: Store) {}
}`,
`
`
import { Store } from '@ngrx/store'
class Ok3 {
vm$ = combineLatest(this.store$.select(selectItems), this.somethingElse())
constructor(private store$: Store) {}
}`,
`
`
import { Store } from '@ngrx/store'
@Pipe()
Expand All @@ -48,10 +56,11 @@ class Ok4 {
constructor(private readonly store: Store) {}
}`,
],
invalid: [
fromFixture(
`
]

const invalid: RunTests['invalid'] = [
fromFixture(
`
import { Store } from '@ngrx/store'
class NotOk {
Expand All @@ -67,9 +76,9 @@ class NotOk {
)
}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'
class NotOk1 {
Expand All @@ -81,9 +90,9 @@ class NotOk1 {
constructor(private store: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'
class NotOk2 {
Expand All @@ -96,9 +105,9 @@ class NotOk2 {
constructor(private customName: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'
@Pipe()
Expand All @@ -112,9 +121,9 @@ class NotOk3 {
constructor(private readonly customName: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'
class NotOk4 {
Expand All @@ -126,10 +135,10 @@ class NotOk4 {
constructor(private store: Store) {}
}`,
),
),

fromFixture(
`
fromFixture(
`
import { Store } from '@ngrx/store'
class NotOk5 {
Expand All @@ -143,6 +152,10 @@ class NotOk5 {
constructor(private store: Store, private store2: Store) {}
}`,
),
],
),
]

test(__filename, () => {
ruleTester().run(path.parse(__filename).name, rule, { valid, invalid })
})
test.run()

0 comments on commit 44e0829

Please sign in to comment.