Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use uvu to run rule tests for better reports #257

Merged
merged 6 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()