Skip to content

Commit

Permalink
test: use uvu to run rule tests for better reports
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Oct 5, 2021
1 parent e13381f commit cbe5f6a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,62 @@ import rule, {
} from '../../src/rules/store/avoid-combining-selectors'
import { ruleTester } from '../utils'

ruleTester().run(path.parse(__filename).name, rule, {
valid: [
`
export const test = () =>
ruleTester().run(path.parse(__filename).name, rule, {
valid: [
`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
readonly test$ = somethingOutside();
}`,
`
`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
vm$ = this.store.select(selectItems)
constructor(private store: Store){}
}
`,
`
`
import { Store, select } from '@ngrx/store'
@Component()
export class FixtureComponent {
vm$ = this.store.pipe(select(selectItems))
constructor(private store: Store){}
}
`,
`
`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
vm$ = combineLatest(this.store.select(selectItems), this.somethingElse())
constructor(private store: Store){}
}
`,
`
`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
vm$ = combineLatest(this.somethingElse(), this.store.select(selectItems))
constructor(private store: Store){}
}
`,
],
invalid: [
fromFixture(
stripIndent`
],
invalid: [
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
vm$ = combineLatest(this.store.select(selectItems), this.store.select(selectOtherItems))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
constructor(private store: Store){}
}
`,
),
fromFixture(
stripIndent`
),
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
Expand All @@ -69,9 +70,9 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private store: Store){}
}
`,
),
fromFixture(
stripIndent`
),
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
Expand All @@ -80,9 +81,9 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private customName: Store){}
}
`,
),
fromFixture(
stripIndent`
),
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
Expand All @@ -91,9 +92,9 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private customName: Store){}
}
`,
),
fromFixture(
stripIndent`
),
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
Expand All @@ -102,10 +103,10 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private store: Store){}
}
`,
),
),

fromFixture(
stripIndent`
fromFixture(
stripIndent`
import { Store } from '@ngrx/store'
@Component()
export class FixtureComponent {
Expand All @@ -114,6 +115,6 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private store: Store){}
}
`,
),
],
})
),
],
})
15 changes: 15 additions & 0 deletions tests/rules.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path from 'path'
import { test } from 'uvu'
import { traverseFolder } from '../src/utils'

for (const rule of traverseFolder(path.join(__dirname, 'fixtures'))) {
test(rule.file, () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const result = require(rule.path)
if (result?.test) {
result.test()
}
})
}

test.run()

0 comments on commit cbe5f6a

Please sign in to comment.