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 12, 2021
1 parent c392618 commit 5b764b4
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions tests/rules/avoid-cyclic-effects.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { stripIndent } from 'common-tags'
import { fromFixture } from 'eslint-etc'
import path from 'path'
import { test } from 'uvu'
import rule, { messageId } from '../../src/rules/effects/avoid-cyclic-effects'
import { ruleTester } from '../utils'

const setup = `
test(__filename, () => {
const setup = `
import type { OnRunEffects } from '@ngrx/effects'
import { EffectConfig } from '@ngrx/effects'
import { Actions, createEffect, ofType } from '@ngrx/effects'
Expand All @@ -19,16 +21,16 @@ const setup = `
bar
}
`.concat(
[
"const subject = 'SUBJECT'",
'const genericFoo = createAction(`${subject} FOO`);',
'const genericBar = createAction(`${subject} BAR`);',
].join('\n'),
)
[
"const subject = 'SUBJECT'",
'const genericFoo = createAction(`${subject} FOO`);',
'const genericBar = createAction(`${subject} BAR`);',
].join('\n'),
)

ruleTester().run(path.parse(__filename).name, rule, {
valid: [
`
ruleTester().run(path.parse(__filename).name, rule, {
valid: [
`
${setup}
class Effect {
foo$ = createEffect(() =>
Expand All @@ -43,7 +45,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`,
`
`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -58,7 +60,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`,
`
`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -73,7 +75,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`,
`
`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -88,7 +90,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`,
`
`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -104,7 +106,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`,
`
`
${setup}
class Effect {
foo$: CreateEffectMetadata
Expand All @@ -121,8 +123,8 @@ ruleTester().run(path.parse(__filename).name, rule, {
}
}
`,
// https://github.com/timdeschryver/eslint-plugin-ngrx/issues/223
`
// https://github.com/timdeschryver/eslint-plugin-ngrx/issues/223
`
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
Expand Down Expand Up @@ -154,14 +156,14 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private readonly actions$: Actions) {}
}
`,
],
invalid: [
fromFixture(stripIndent`
],
invalid: [
fromFixture(stripIndent`
${setup}
class Effect {
foo$ = createEffect(() =>
this.actions$.pipe(
~~~~~~~~~~~~~~~~~~ [${messageId}]
~~~~~~~~~~~~~~~~~~~ [${messageId}]
ofType(foo),
tap(() => alert('hi'))
),
Expand All @@ -172,7 +174,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`),
fromFixture(stripIndent`
fromFixture(stripIndent`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -188,7 +190,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`),
fromFixture(stripIndent`
fromFixture(stripIndent`
${setup}
class Effect {
foo$ = createEffect(() => {
Expand All @@ -204,7 +206,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
) {}
}
`),
fromFixture(stripIndent`
fromFixture(stripIndent`
${setup}
class Effect {
foo$ = createEffect(
Expand All @@ -222,7 +224,7 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private actions$: Actions) {}
}
`),
fromFixture(stripIndent`
fromFixture(stripIndent`
${setup}
class Effect {
foo$: CreateEffectMetadata
Expand All @@ -239,8 +241,8 @@ ruleTester().run(path.parse(__filename).name, rule, {
}
}
`),
// https://github.com/timdeschryver/eslint-plugin-ngrx/issues/223
fromFixture(stripIndent`
// https://github.com/timdeschryver/eslint-plugin-ngrx/issues/223
fromFixture(stripIndent`
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
Expand Down Expand Up @@ -273,5 +275,8 @@ ruleTester().run(path.parse(__filename).name, rule, {
constructor(private readonly actions$: Actions) {}
}
`),
],
],
})
})

test.run()

0 comments on commit 5b764b4

Please sign in to comment.