Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(runner): deprecate custom type in favour of "test" #6866

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ export interface Test<ExtraContext = object> extends TaskPopulated {
context: TaskContext<Test> & ExtraContext & TestContext
}

/**
* @deprecated Use `Test` instead. `type: 'custom'` will be removed in Vitest 3.0
*/
export interface Custom<ExtraContext = object> extends TaskPopulated {
/**
* @deprecated use `test` instead. `custom` will be removed in Vitest 3.0
*/
type: 'custom'
/**
* Task context that will be passed to the test function.
Expand All @@ -228,6 +234,9 @@ export interface Custom<ExtraContext = object> extends TaskPopulated {

export type Task = Test | Suite | Custom | File

/**
* @deprecated Vitest doesn't provide `done()` anymore
*/
export type DoneCallback = (error?: any) => void
export type TestFunction<ExtraContext = object> = (
context: ExtendedContext<Test> & ExtraContext
Expand Down
15 changes: 11 additions & 4 deletions packages/runner/src/utils/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import type { Custom, Suite, Task, Test } from '../types/tasks'
import { type Arrayable, toArray } from '@vitest/utils'

/**
* @deprecated use `isTestCase` instead
*/
export function isAtomTest(s: Task): s is Test | Custom {
return isTestCase(s)
}

export function isTestCase(s: Task): s is Test | Custom {
return s.type === 'test' || s.type === 'custom'
}

export function getTests(suite: Arrayable<Task>): (Test | Custom)[] {
const tests: (Test | Custom)[] = []
const arraySuites = toArray(suite)
for (const s of arraySuites) {
if (isAtomTest(s)) {
if (isTestCase(s)) {
tests.push(s)
}
else {
for (const task of s.tasks) {
if (isAtomTest(task)) {
if (isTestCase(task)) {
tests.push(task)
}
else {
Expand All @@ -31,7 +38,7 @@ export function getTests(suite: Arrayable<Task>): (Test | Custom)[] {

export function getTasks(tasks: Arrayable<Task> = []): Task[] {
return toArray(tasks).flatMap(s =>
isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)],
isTestCase(s) ? [s] : [s, ...getTasks(s.tasks)],
)
}

Expand All @@ -43,7 +50,7 @@ export function getSuites(suite: Arrayable<Task>): Suite[] {

export function hasTests(suite: Arrayable<Suite>): boolean {
return toArray(suite).some(s =>
s.tasks.some(c => isAtomTest(c) || hasTests(c)),
s.tasks.some(c => isTestCase(c) || hasTests(c)),
)
}

Expand Down
Loading