Skip to content

Commit

Permalink
refactor: rewrite testrunner
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 4, 2024
1 parent dfc2efd commit a28abc6
Show file tree
Hide file tree
Showing 46 changed files with 242 additions and 324 deletions.
13 changes: 0 additions & 13 deletions patches/@typescript-eslint+utils+7.4.0.patch

This file was deleted.

12 changes: 6 additions & 6 deletions test/rules/consistent-type-specifier-style.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { TSESTree } from '@typescript-eslint/utils'

import { parsers, test, wrapRun } from '../utils'
import { parsers, test, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/consistent-type-specifier-style'

Expand Down Expand Up @@ -445,28 +445,28 @@ const FLOW_ONLY = {
} as const

describe('TypeScript', () => {
const ruleTester = new TSESLint.RuleTester({
const ruleTester = new RuleTester({
parser: parsers.TS,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
})
wrapRun(ruleTester.run)('consistent-type-specifier-style', rule, {
ruleTester.run$('consistent-type-specifier-style', rule, {
valid: [...COMMON_TESTS.valid, ...TS_ONLY.valid],
invalid: [...COMMON_TESTS.invalid, ...TS_ONLY.invalid],
})
})

describe('Babel/Flow', () => {
const ruleTester = new TSESLint.RuleTester({
const ruleTester = new RuleTester({
parser: parsers.BABEL,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
})
wrapRun(ruleTester.run)('consistent-type-specifier-style', rule, {
ruleTester.run$('consistent-type-specifier-style', rule, {
valid: [...COMMON_TESTS.valid, ...FLOW_ONLY.valid],
invalid: [...COMMON_TESTS.invalid, ...FLOW_ONLY.invalid],
})
Expand Down
12 changes: 5 additions & 7 deletions test/rules/default.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import path from 'node:path'

import { TSESLint } from '@typescript-eslint/utils'

import { test, SYNTAX_CASES, parsers, wrapRun } from '../utils'
import { test, SYNTAX_CASES, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/default'
import { CASE_SENSITIVE_FS } from 'eslint-plugin-import-x/utils'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

wrapRun(ruleTester.run)('default', rule, {
ruleTester.run$('default', rule, {
valid: [
test({ code: 'import "./malformed.js"' }),

Expand Down Expand Up @@ -161,7 +159,7 @@ wrapRun(ruleTester.run)('default', rule, {

// #311: import of mismatched case
if (!CASE_SENSITIVE_FS) {
wrapRun(ruleTester.run)('default (path case-insensitivity)', rule, {
ruleTester.run$('default (path case-insensitivity)', rule, {
valid: [
test({
code: 'import foo from "./jsx/MyUncoolComponent.jsx"',
Expand All @@ -180,7 +178,7 @@ if (!CASE_SENSITIVE_FS) {

describe('TypeScript', () => {
const parser = parsers.TS
wrapRun(ruleTester.run)(`default`, rule, {
ruleTester.run$(`default`, rule, {
valid: [
test({
code: `import foobar from "./typescript-default"`,
Expand Down
10 changes: 5 additions & 5 deletions test/rules/dynamic-import-chunkname.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { TSESTree } from '@typescript-eslint/utils'

import { SYNTAX_CASES, parsers, wrapRun } from '../utils'
import { SYNTAX_CASES, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/dynamic-import-chunkname'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

const pickyCommentFormat = '[a-zA-Z-_/.]+'

Expand Down Expand Up @@ -43,7 +43,7 @@ const pickyChunkNameFormatError = {
},
} as const

wrapRun(ruleTester.run)('dynamic-import-chunkname', rule, {
ruleTester.run$('dynamic-import-chunkname', rule, {
valid: [
{
code: `dynamicImport(
Expand Down Expand Up @@ -971,7 +971,7 @@ describe('TypeScript', () => {
const typescriptParser = parsers.TS
const nodeType = TSESTree.AST_NODE_TYPES.ImportExpression

wrapRun(ruleTester.run)('dynamic-import-chunkname', rule, {
ruleTester.run$('dynamic-import-chunkname', rule, {
valid: [
{
code: `import('test')`,
Expand Down
10 changes: 4 additions & 6 deletions test/rules/export.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { TSESLint } from '@typescript-eslint/utils'

import { test, testFilePath, SYNTAX_CASES, parsers, wrapRun } from '../utils'
import { test, testFilePath, SYNTAX_CASES, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/export'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

wrapRun(ruleTester.run)('export', rule, {
ruleTester.run$('export', rule, {
valid: [
test({ code: 'import "./malformed.js"' }),

Expand Down Expand Up @@ -166,7 +164,7 @@ describe('TypeScript', () => {
},
}

wrapRun(ruleTester.run)('export', rule, {
ruleTester.run$('export', rule, {
valid: [
// type/value name clash
test({
Expand Down
7 changes: 3 additions & 4 deletions test/rules/exports-last.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { TSESLint } from '@typescript-eslint/utils'
import type { TSESTree } from '@typescript-eslint/utils'

import { test, wrapRun } from '../utils'
import { test, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/exports-last'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

const error = (type: `${TSESTree.AST_NODE_TYPES}`) =>
({
messageId: 'end',
type,
}) as const

wrapRun(ruleTester.run)('exports-last', rule, {
ruleTester.run$('exports-last', rule, {
valid: [
// Empty file
test({
Expand Down
10 changes: 4 additions & 6 deletions test/rules/extensions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { TSESLint } from '@typescript-eslint/utils'

import { test, testFilePath, parsers, wrapRun } from '../utils'
import { test, testFilePath, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/extensions'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

wrapRun(ruleTester.run)('extensions', rule, {
ruleTester.run$('extensions', rule, {
valid: [
test({ code: 'import a from "@/a"' }),
test({ code: 'import a from "a"' }),
Expand Down Expand Up @@ -662,7 +660,7 @@ wrapRun(ruleTester.run)('extensions', rule, {
describe('TypeScript', () => {
const parser = parsers.TS

wrapRun(ruleTester.run)(`${parser}: extensions ignore type-only`, rule, {
ruleTester.run$(`${parser}: extensions ignore type-only`, rule, {
valid: [
test({
code: 'import type T from "./typescript-declare";',
Expand Down
10 changes: 4 additions & 6 deletions test/rules/first.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import fs from 'node:fs'

import { TSESLint } from '@typescript-eslint/utils'

import { test, parsers, testFilePath, wrapRun } from '../utils'
import { test, parsers, testFilePath, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/first'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

wrapRun(ruleTester.run)('first', rule, {
ruleTester.run$('first', rule, {
valid: [
test({
code: "import { x } from './foo'; import { y } from './bar';\
Expand Down Expand Up @@ -101,7 +99,7 @@ describe('TypeScript', () => {
},
}

wrapRun(ruleTester.run)('order', rule, {
ruleTester.run$('order', rule, {
valid: [
test({
code: `
Expand Down
8 changes: 3 additions & 5 deletions test/rules/group-exports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TSESLint } from '@typescript-eslint/utils'

import { parsers, test, wrapRun } from '../utils'
import { parsers, test, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/group-exports'

Expand All @@ -11,7 +9,7 @@ const errors = {
'Multiple CommonJS exports; consolidate all exports into a single assignment to `module.exports`',
}

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new RuleTester({
parser: parsers.BABEL,
parserOptions: {
requireConfigFile: false,
Expand All @@ -23,7 +21,7 @@ const ruleTester = new TSESLint.RuleTester({
},
})

wrapRun(ruleTester.run)('group-exports', rule, {
ruleTester.run$('group-exports', rule, {
valid: [
test({ code: 'export const test = true' }),
test({
Expand Down
10 changes: 4 additions & 6 deletions test/rules/max-dependencies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { TSESLint } from '@typescript-eslint/utils'

import { test, parsers, wrapRun } from '../utils'
import { test, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/max-dependencies'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

wrapRun(ruleTester.run)('max-dependencies', rule, {
ruleTester.run$('max-dependencies', rule, {
valid: [
test({ code: 'import "./foo.js"' }),

Expand Down Expand Up @@ -99,7 +97,7 @@ wrapRun(ruleTester.run)('max-dependencies', rule, {
describe('TypeScript', () => {
const parser = parsers.TS

wrapRun(ruleTester.run)('max-dependencies', rule, {
ruleTester.run$('max-dependencies', rule, {
valid: [
test({
code: "import type { x } from './foo'; import { y } from './bar';",
Expand Down
13 changes: 6 additions & 7 deletions test/rules/named.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import path from 'node:path'

import type { TSESTree } from '@typescript-eslint/utils'
import { TSESLint } from '@typescript-eslint/utils'

import { test, SYNTAX_CASES, testFilePath, parsers, wrapRun } from '../utils'
import { test, SYNTAX_CASES, testFilePath, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/named'
import { CASE_SENSITIVE_FS } from 'eslint-plugin-import-x/utils'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

function error(
name: string,
Expand All @@ -18,7 +17,7 @@ function error(
return { message: `${name} not found in '${module}'`, type }
}

wrapRun(ruleTester.run)('named', rule, {
ruleTester.run$('named', rule, {
valid: [
test({ code: 'import "./malformed.js"' }),

Expand Down Expand Up @@ -388,7 +387,7 @@ wrapRun(ruleTester.run)('named', rule, {

// #311: import of mismatched case
if (!CASE_SENSITIVE_FS) {
wrapRun(ruleTester.run)('named (path case-insensitivity)', rule, {
ruleTester.run$('named (path case-insensitivity)', rule, {
valid: [
test({
code: 'import { b } from "./Named-Exports"',
Expand All @@ -404,7 +403,7 @@ if (!CASE_SENSITIVE_FS) {
}

// export-all
wrapRun(ruleTester.run)('named (export *)', rule, {
ruleTester.run$('named (export *)', rule, {
valid: [
test({
code: 'import { foo } from "./export-all"',
Expand Down Expand Up @@ -565,7 +564,7 @@ describe('TypeScript', () => {
)
}

wrapRun(ruleTester.run)(`named [TypeScript]`, rule, {
ruleTester.run$(`named [TypeScript]`, rule, {
valid,
invalid,
})
Expand Down
8 changes: 3 additions & 5 deletions test/rules/namespace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils'

import { test, SYNTAX_CASES, testFilePath, parsers, wrapRun } from '../utils'
import { test, SYNTAX_CASES, testFilePath, parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/namespace'

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new RuleTester({
parserOptions: { env: { es6: true } },
})

Expand Down Expand Up @@ -457,4 +455,4 @@ for (const [folder, parser] of [['deep'], ['deep-es7', parsers.BABEL]]) {
)
}

wrapRun(ruleTester.run)('namespace', rule, { valid, invalid })
ruleTester.run$('namespace', rule, { valid, invalid })
8 changes: 3 additions & 5 deletions test/rules/newline-after-import.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils'

import { parsers, wrapRun } from '../utils'
import { parsers, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/newline-after-import'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

const getImportError = (count: number) => ({
messageId: 'newline' as const,
Expand All @@ -28,7 +26,7 @@ const getRequireError = (count: number) => ({

const REQUIRE_ERROR = getRequireError(1)

wrapRun(ruleTester.run)('newline-after-import', rule, {
ruleTester.run$('newline-after-import', rule, {
valid: [
`var path = require('path');\nvar foo = require('foo');\n`,
`require('foo');`,
Expand Down
8 changes: 3 additions & 5 deletions test/rules/no-absolute-path.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { TSESLint } from '@typescript-eslint/utils'

import { test, wrapRun } from '../utils'
import { test, RuleTester } from '../utils'

import rule from 'eslint-plugin-import-x/rules/no-absolute-path'

const ruleTester = new TSESLint.RuleTester()
const ruleTester = new RuleTester()

const error = {
messageId: 'absolute',
}

wrapRun(ruleTester.run)('no-absolute-path', rule, {
ruleTester.run$('no-absolute-path', rule, {
valid: [
test({ code: 'import _ from "lodash"' }),
test({ code: 'import find from "lodash.find"' }),
Expand Down
Loading

0 comments on commit a28abc6

Please sign in to comment.