Skip to content

Commit 7957f91

Browse files
authored
fix: don't use Custom type internally (#7032)
1 parent db19f6e commit 7957f91

File tree

18 files changed

+50
-69
lines changed

18 files changed

+50
-69
lines changed

packages/runner/src/collect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function collectTests(
6060
mergeHooks(fileHooks, getHooks(defaultTasks))
6161

6262
for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
63-
if (c.type === 'test' || c.type === 'custom' || c.type === 'suite') {
63+
if (c.type === 'test' || c.type === 'suite') {
6464
file.tasks.push(c)
6565
}
6666
else if (c.type === 'collector') {

packages/runner/src/run.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Awaitable } from '@vitest/utils'
22
import type { DiffOptions } from '@vitest/utils/diff'
33
import type { FileSpec, VitestRunner } from './types/runner'
44
import type {
5-
Custom,
65
File,
76
HookCleanupCallback,
87
HookListener,
@@ -177,7 +176,7 @@ async function callCleanupHooks(cleanups: HookCleanupCallback[]) {
177176
)
178177
}
179178

180-
export async function runTest(test: Test | Custom, runner: VitestRunner): Promise<void> {
179+
export async function runTest(test: Test, runner: VitestRunner): Promise<void> {
181180
await runner.onBeforeRunTask?.(test)
182181

183182
if (test.mode !== 'run') {
@@ -471,7 +470,7 @@ export async function runSuite(suite: Suite, runner: VitestRunner): Promise<void
471470
let limitMaxConcurrency: ReturnType<typeof limitConcurrency>
472471

473472
async function runSuiteChild(c: Task, runner: VitestRunner) {
474-
if (c.type === 'test' || c.type === 'custom') {
473+
if (c.type === 'test') {
475474
return limitMaxConcurrency(() => runTest(c, runner))
476475
}
477476
else if (c.type === 'suite') {

packages/runner/src/suite.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { FixtureItem } from './fixture'
22
import type { VitestRunner } from './types/runner'
33
import type {
4-
Custom,
5-
CustomAPI,
64
File,
75
Fixtures,
86
RunMode,
@@ -294,7 +292,7 @@ function createSuiteCollector(
294292
each?: boolean,
295293
suiteOptions?: TestOptions,
296294
) {
297-
const tasks: (Test | Custom | Suite | SuiteCollector)[] = []
295+
const tasks: (Test | Suite | SuiteCollector)[] = []
298296
const factoryQueue: (Test | Suite | SuiteCollector)[] = []
299297

300298
let suite: Suite
@@ -609,7 +607,7 @@ function createSuite() {
609607
export function createTaskCollector(
610608
fn: (...args: any[]) => any,
611609
context?: Record<string, unknown>,
612-
): CustomAPI {
610+
): TestAPI {
613611
const taskFn = fn as any
614612

615613
taskFn.each = function <T>(
@@ -730,7 +728,7 @@ export function createTaskCollector(
730728
const _test = createChainable(
731729
['concurrent', 'sequential', 'skip', 'only', 'todo', 'fails'],
732730
taskFn,
733-
) as CustomAPI
731+
) as TestAPI
734732

735733
if (context) {
736734
(_test as any).mergeContext(context)

packages/runner/src/test-state.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { Custom, Test } from './types/tasks.ts'
1+
import type { Test } from './types/tasks.ts'
22

3-
let _test: Test | Custom | undefined
3+
let _test: Test | undefined
44

5-
export function setCurrentTest<T extends Test | Custom>(test: T | undefined): void {
5+
export function setCurrentTest<T extends Test>(test: T | undefined): void {
66
_test = test
77
}
88

9-
export function getCurrentTest<T extends Test | Custom | undefined>(): T {
9+
export function getCurrentTest<T extends Test | undefined>(): T {
1010
return _test as T
1111
}

packages/runner/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type {
1212
BeforeAllListener,
1313
BeforeEachListener,
1414
Custom,
15+
/** @deprecated use `TestAPI` instead */
1516
CustomAPI,
1617
DoneCallback,
1718
ExtendedContext,

packages/runner/src/types/runner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DiffOptions } from '@vitest/utils/diff'
22
import type {
3-
Custom,
43
ExtendedContext,
54
File,
65
SequenceHooks,
@@ -91,7 +90,7 @@ export interface VitestRunner {
9190
/**
9291
* When the task has finished running, but before cleanup hooks are called
9392
*/
94-
onTaskFinished?: (test: Test | Custom) => unknown
93+
onTaskFinished?: (test: Test) => unknown
9594
/**
9695
* Called after result and state are set.
9796
*/

packages/runner/src/types/tasks.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,9 @@ export interface Test<ExtraContext = object> extends TaskPopulated {
223223
/**
224224
* @deprecated Use `Test` instead. `type: 'custom'` is not used since 2.2
225225
*/
226-
export interface Custom<ExtraContext = object> extends TaskPopulated {
227-
/**
228-
* @deprecated use `test` instead. `custom` is not used since 2.2
229-
*/
230-
type: 'custom'
231-
/**
232-
* Task context that will be passed to the test function.
233-
*/
234-
context: TaskContext<Test> & ExtraContext & TestContext
235-
}
226+
export type Custom<ExtraContext = object> = Test<ExtraContext>
236227

237-
export type Task = Test | Suite | Custom | File
228+
export type Task = Test | Suite | File
238229

239230
/**
240231
* @deprecated Vitest doesn't provide `done()` anymore
@@ -441,6 +432,7 @@ export type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> &
441432
}>
442433
}
443434

435+
/** @deprecated use `TestAPI` instead */
444436
export type { TestAPI as CustomAPI }
445437

446438
export interface FixtureOptions {
@@ -578,8 +570,6 @@ export interface SuiteCollector<ExtraContext = object> {
578570
test: TestAPI<ExtraContext>
579571
tasks: (
580572
| Suite
581-
// TODO: remove in Vitest 3
582-
| Custom<ExtraContext>
583573
| Test<ExtraContext>
584574
| SuiteCollector<ExtraContext>
585575
)[]

packages/runner/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export {
1818
hasFailed,
1919
hasTests,
2020
isAtomTest,
21+
isTestCase,
2122
} from './tasks'

packages/runner/src/utils/tasks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import type { Custom, Suite, Task, Test } from '../types/tasks'
1+
import type { Suite, Task, Test } from '../types/tasks'
22
import { type Arrayable, toArray } from '@vitest/utils'
33

44
/**
55
* @deprecated use `isTestCase` instead
66
*/
7-
export function isAtomTest(s: Task): s is Test | Custom {
7+
export function isAtomTest(s: Task): s is Test {
88
return isTestCase(s)
99
}
1010

11-
export function isTestCase(s: Task): s is Test | Custom {
12-
return s.type === 'test' || s.type === 'custom'
11+
export function isTestCase(s: Task): s is Test {
12+
return s.type === 'test'
1313
}
1414

15-
export function getTests(suite: Arrayable<Task>): (Test | Custom)[] {
16-
const tests: (Test | Custom)[] = []
15+
export function getTests(suite: Arrayable<Task>): Test[] {
16+
const tests: Test[] = []
1717
const arraySuites = toArray(suite)
1818
for (const s of arraySuites) {
1919
if (isTestCase(s)) {

packages/ui/client/components/views/ViewReport.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function collectFailed(task: Task, level: number): LeveledTask[] {
1919
return []
2020
}
2121
22-
if (task.type === 'test' || task.type === 'custom') {
22+
if (task.type === 'test') {
2323
return [{ ...task, level }]
2424
}
2525
else {

0 commit comments

Comments
 (0)