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 3 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
179 changes: 92 additions & 87 deletions tests/rules/avoid-combining-selectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,148 +1,153 @@
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: [
`
const valid = [
`
import { Store } from '@ngrx/store'

class Ok {
readonly test$ = somethingOutside();
readonly test$ = somethingOutside();
timdeschryver marked this conversation as resolved.
Show resolved Hide resolved
}`,
`
`
import { Store } from '@ngrx/store'

class Ok1 {
readonly vm$: Observable<unknown>
readonly vm$: Observable<unknown>

constructor(store: Store) {
this.vm$ = store.select(selectItems)
}
constructor(store: Store) {
this.vm$ = store.select(selectItems)
}
}`,
`
`
import { Store, select } from '@ngrx/store'

class Ok2 {
vm$ = this.store.pipe(select(selectItems))
vm$ = this.store.pipe(select(selectItems))

constructor(private store: Store) {}
constructor(private store: Store) {}
}`,
`
`
import { Store } from '@ngrx/store'

class Ok3 {
vm$ = combineLatest(this.store$.select(selectItems), this.somethingElse())
vm$ = combineLatest(this.store$.select(selectItems), this.somethingElse())

constructor(private store$: Store) {}
constructor(private store$: Store) {}
}`,
`
`
import { Store } from '@ngrx/store'

@Pipe()
class Ok4 {
vm$ = combineLatest(this.somethingElse(), this.store.select(selectItems))
vm$ = combineLatest(this.somethingElse(), this.store.select(selectItems))

constructor(private readonly store: Store) {}
constructor(private readonly store: Store) {}
}`,
],
invalid: [
fromFixture(
`
]

const invalid = [
fromFixture(
`
import { Store } from '@ngrx/store'

class NotOk {
readonly vm$: Observable<unknown>

constructor(store: Store, private store2: Store) {
this.vm$ = combineLatest(
store.select(selectItems),
store.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.store2.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)
}
readonly vm$: Observable<unknown>

constructor(store: Store, private store2: Store) {
this.vm$ = combineLatest(
store.select(selectItems),
store.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.store2.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)
}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'

class NotOk1 {
vm$ = combineLatest(
this.store.pipe(select(selectItems)),
this.store.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)
vm$ = combineLatest(
this.store.pipe(select(selectItems)),
this.store.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)

constructor(private store: Store) {}
constructor(private store: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'

class NotOk2 {
vm$ = combineLatest(
this.customName.select(selectItems),
this.customName.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.somethingElse(),
)

constructor(private customName: Store) {}
vm$ = combineLatest(
this.customName.select(selectItems),
this.customName.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.somethingElse(),
)

constructor(private customName: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'

@Pipe()
class NotOk3 {
vm$ = combineLatest(
this.customName.select(selectItems),
this.customName.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.somethingElse(),
)

constructor(private readonly customName: Store) {}
vm$ = combineLatest(
this.customName.select(selectItems),
this.customName.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.somethingElse(),
)

constructor(private readonly customName: Store) {}
}`,
),
fromFixture(
`
),
fromFixture(
`
import { Store } from '@ngrx/store'

class NotOk4 {
vm$ = combineLatest(
this.store.pipe(select(selectItems)),
this.store.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)
vm$ = combineLatest(
this.store.pipe(select(selectItems)),
this.store.select(selectOtherItems),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)

constructor(private store: Store) {}
constructor(private store: Store) {}
}`,
),
),

fromFixture(
`
fromFixture(
`
import { Store } from '@ngrx/store'

class NotOk5 {
vm$ = combineLatest(
this.store.select(selectItems),
this.store.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.store2.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)

constructor(private store: Store, private store2: Store) {}
vm$ = combineLatest(
this.store.select(selectItems),
this.store.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
this.store2.pipe(select(selectOtherItems)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
)

constructor(private store: Store, private store2: Store) {}
}`,
),
],
),
]

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