Skip to content

Commit

Permalink
fix: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Oct 23, 2024
1 parent 8a39d24 commit e91c3e6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/__tests__/exports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import parser from "@typescript-eslint/parser"
import dedent from "dedent"
import { createRuleTester, createTsRuleTester } from "../test-utils.js"
import { createRuleTester } from "../test-utils.js"

const { default: rule } = await import("../rules/exports.js")

Expand Down Expand Up @@ -365,14 +366,7 @@ createRuleTester().run("exports", rule, {
})

// TypeScript rules
createTsRuleTester({
languageOptions: {
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
},
}).run("exports", rule, {
createRuleTester({ languageOptions: { parser } }).run("exports", rule, {
valid: [
// typeOrder
{
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/imports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dedent from "dedent"
import { createRuleTester, createTsRuleTester } from "../test-utils.js"
import parser from "@typescript-eslint/parser"
import { createRuleTester } from "../test-utils.js"

const { default: rule } = await import("../rules/imports.js")

Expand Down Expand Up @@ -846,7 +847,7 @@ createRuleTester().run("imports - JS", rule, {
})

// TypeScript rules
createTsRuleTester().run("imports - TS", rule, {
createRuleTester({ languageOptions: { parser } }).run("imports - TS", rule, {
valid: [
{
name: "Programs without imports",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/string-enums.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TSESLint } from "@typescript-eslint/utils"
import { RunTests } from "@typescript-eslint/rule-tester"
import rule from "../rules/string-enums.js"
import { createTsRuleTester } from "../test-utils.js"

const ruleTester = createTsRuleTester()

const createValidCodeVariants = (
code: string
): TSESLint.RunTests<
): RunTests<
"unsorted",
[{ caseSensitive?: boolean; natural?: boolean }]
>["valid"] => [
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/string-unions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TSESLint } from "@typescript-eslint/utils"
import { RunTests } from "@typescript-eslint/rule-tester"
import rule from "../rules/string-unions.js"
import { createTsRuleTester } from "../test-utils.js"

const ruleTester = createTsRuleTester()

const createValidCodeVariants = (
code: string
): TSESLint.RunTests<
): RunTests<
"unsorted",
[{ caseSensitive?: boolean; natural?: boolean }]
>["valid"] => [
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/type-properties.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TSESLint } from "@typescript-eslint/utils"
import { RunTests } from "@typescript-eslint/rule-tester"
import rule from "../rules/type-properties.js"
import { createTsRuleTester } from "../test-utils.js"

const ruleTester = createTsRuleTester()

const createValidCodeVariants = (
code: string
): TSESLint.RunTests<
): RunTests<
"unsorted",
[{ caseSensitive?: boolean; natural?: boolean }]
>["valid"] => [
Expand Down
15 changes: 12 additions & 3 deletions src/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import parser from "@typescript-eslint/parser"
import { it, describe } from "vitest"
import { it, describe, afterAll } from "vitest"
import { RuleTester, Linter } from "eslint"
import parser from "@typescript-eslint/parser"
import { RuleTester as TSRuleTester } from "@typescript-eslint/rule-tester"

RuleTester.describe = describe
RuleTester.it = it
RuleTester.itOnly = it.only

TSRuleTester.describe = describe
TSRuleTester.it = it
TSRuleTester.itOnly = it.only
TSRuleTester.afterAll = afterAll

globalThis.resolver = (source) => {
return (
source.startsWith("dependency-") ||
Expand Down Expand Up @@ -39,6 +45,9 @@ export function createRuleTester(config?: Linter.Config) {
}

export function createTsRuleTester(config?: Linter.Config) {
// TSRuleTester is broken
// https://github.com/typescript-eslint/typescript-eslint/issues/9676
// https://github.com/typescript-eslint/typescript-eslint/issues/10191
return new RuleTester({
...config,
languageOptions: {
Expand All @@ -50,5 +59,5 @@ export function createTsRuleTester(config?: Linter.Config) {
...config?.languageOptions?.parserOptions,
},
},
})
}) as unknown as TSRuleTester
}

0 comments on commit e91c3e6

Please sign in to comment.