Skip to content

Commit db19f6e

Browse files
committedDec 5, 2024··
Revert "fix: don't use Custom internally"
This reverts commit 46fc534.
1 parent 46fc534 commit db19f6e

File tree

16 files changed

+56
-44
lines changed

16 files changed

+56
-44
lines changed
 

‎packages/runner/src/collect.ts

+1-1
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 === 'suite') {
63+
if (c.type === 'test' || c.type === 'custom' || c.type === 'suite') {
6464
file.tasks.push(c)
6565
}
6666
else if (c.type === 'collector') {

‎packages/runner/src/run.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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,
56
File,
67
HookCleanupCallback,
78
HookListener,
@@ -176,7 +177,7 @@ async function callCleanupHooks(cleanups: HookCleanupCallback[]) {
176177
)
177178
}
178179

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

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

472473
async function runSuiteChild(c: Task, runner: VitestRunner) {
473-
if (c.type === 'test') {
474+
if (c.type === 'test' || c.type === 'custom') {
474475
return limitMaxConcurrency(() => runTest(c, runner))
475476
}
476477
else if (c.type === 'suite') {

‎packages/runner/src/suite.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { FixtureItem } from './fixture'
22
import type { VitestRunner } from './types/runner'
33
import type {
4+
Custom,
45
CustomAPI,
56
File,
67
Fixtures,
@@ -293,7 +294,7 @@ function createSuiteCollector(
293294
each?: boolean,
294295
suiteOptions?: TestOptions,
295296
) {
296-
const tasks: (Test | Suite | SuiteCollector)[] = []
297+
const tasks: (Test | Custom | Suite | SuiteCollector)[] = []
297298
const factoryQueue: (Test | Suite | SuiteCollector)[] = []
298299

299300
let suite: Suite

‎packages/runner/src/test-state.ts

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

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

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

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

‎packages/runner/src/types/runner.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DiffOptions } from '@vitest/utils/diff'
22
import type {
3+
Custom,
34
ExtendedContext,
45
File,
56
SequenceHooks,
@@ -90,7 +91,7 @@ export interface VitestRunner {
9091
/**
9192
* When the task has finished running, but before cleanup hooks are called
9293
*/
93-
onTaskFinished?: (test: Test) => unknown
94+
onTaskFinished?: (test: Test | Custom) => unknown
9495
/**
9596
* Called after result and state are set.
9697
*/

‎packages/runner/src/types/tasks.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export interface Custom<ExtraContext = object> extends TaskPopulated {
234234
context: TaskContext<Test> & ExtraContext & TestContext
235235
}
236236

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

239239
/**
240240
* @deprecated Vitest doesn't provide `done()` anymore
@@ -578,6 +578,8 @@ export interface SuiteCollector<ExtraContext = object> {
578578
test: TestAPI<ExtraContext>
579579
tasks: (
580580
| Suite
581+
// TODO: remove in Vitest 3
582+
| Custom<ExtraContext>
581583
| Test<ExtraContext>
582584
| SuiteCollector<ExtraContext>
583585
)[]

‎packages/runner/src/utils/tasks.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import type { Suite, Task, Test } from '../types/tasks'
1+
import type { Custom, 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 {
7+
export function isAtomTest(s: Task): s is Test | Custom {
88
return isTestCase(s)
99
}
1010

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

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

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

+1-1
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') {
22+
if (task.type === 'test' || task.type === 'custom') {
2323
return [{ ...task, level }]
2424
}
2525
else {

‎packages/ui/client/composables/explorer/collector.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { File, Task, TaskResultPack, Test } from '@vitest/runner'
1+
import type { Custom, File, Task, TaskResultPack, Test } from '@vitest/runner'
22
import type { Arrayable } from '@vitest/utils'
33
import type { CollectFilteredTests, CollectorInfo, Filter, FilteredTests } from '~/composables/explorer/types'
4-
import { isTestCase } from '@vitest/runner/utils/tasks'
4+
import { isAtomTest } from '@vitest/runner/utils'
55
import { toArray } from '@vitest/utils'
66
import { hasFailedSnapshot } from '@vitest/ws-client'
77
import { client, findById } from '~/composables/client'
@@ -460,12 +460,12 @@ export function collectTestsTotalData(
460460
return filesSummary
461461
}
462462

463-
function* testsCollector(suite: Arrayable<Task>): Generator<Test> {
463+
function* testsCollector(suite: Arrayable<Task>): Generator<Test | Custom> {
464464
const arraySuites = toArray(suite)
465465
let s: Task
466466
for (let i = 0; i < arraySuites.length; i++) {
467467
s = arraySuites[i]
468-
if (isTestCase(s)) {
468+
if (isAtomTest(s)) {
469469
yield s
470470
}
471471
else {

‎packages/ui/client/composables/explorer/types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface RootTreeNode extends TaskTreeNode {
2525
tasks: FileTreeNode[]
2626
}
2727

28-
export type TaskTreeNodeType = 'file' | 'suite' | 'test'
28+
export type TaskTreeNodeType = 'file' | 'suite' | 'test' | 'custom'
2929

3030
export interface UITaskTreeNode extends TaskTreeNode {
3131
type: TaskTreeNodeType
@@ -42,6 +42,11 @@ export interface TestTreeNode extends UITaskTreeNode {
4242
type: 'test'
4343
}
4444

45+
export interface CustomTestTreeNode extends UITaskTreeNode {
46+
fileId: string
47+
type: 'custom'
48+
}
49+
4550
export interface ParentTreeNode extends UITaskTreeNode {
4651
children: Set<string>
4752
tasks: UITaskTreeNode[]

‎packages/ui/client/composables/explorer/utils.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { File, Task } from '@vitest/runner'
22
import type {
3+
CustomTestTreeNode,
34
FileTreeNode,
45
ParentTreeNode,
56
SuiteTreeNode,
@@ -12,12 +13,12 @@ import { explorerTree } from '~/composables/explorer/index'
1213
import { openedTreeItemsSet } from '~/composables/explorer/state'
1314
import { getProjectNameColor, isSuite as isTaskSuite } from '~/utils/task'
1415

15-
export function isTestNode(node: UITaskTreeNode): node is TestTreeNode {
16-
return node.type === 'test'
16+
export function isTestNode(node: UITaskTreeNode): node is TestTreeNode | CustomTestTreeNode {
17+
return node.type === 'test' || node.type === 'custom'
1718
}
1819

19-
export function isRunningTestNode(node: UITaskTreeNode): node is TestTreeNode {
20-
return node.mode === 'run' && (node.type === 'test')
20+
export function isRunningTestNode(node: UITaskTreeNode): node is TestTreeNode | CustomTestTreeNode {
21+
return node.mode === 'run' && (node.type === 'test' || node.type === 'custom')
2122
}
2223

2324
export function isFileNode(node: UITaskTreeNode): node is FileTreeNode {
@@ -160,7 +161,7 @@ export function createOrUpdateNode(
160161
indent: node.indent + 1,
161162
duration,
162163
state: task.result?.state,
163-
} as TestTreeNode
164+
} as TestTreeNode | CustomTestTreeNode
164165
}
165166
else {
166167
taskNode = {

‎packages/vitest/src/node/reporters/dot.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { File, TaskResultPack, TaskState, Test } from '@vitest/runner'
1+
import type { Custom, File, TaskResultPack, TaskState, Test } from '@vitest/runner'
22
import type { Vitest } from '../core'
33
import { getTests } from '@vitest/runner/utils'
44
import c from 'tinyrainbow'
@@ -78,15 +78,15 @@ class DotSummary extends TaskParser {
7878
}
7979
}
8080

81-
onTestStart(test: Test) {
81+
onTestStart(test: Test | Custom) {
8282
if (this.finishedTests.has(test.id)) {
8383
return
8484
}
8585

8686
this.tests.set(test.id, test.mode || 'run')
8787
}
8888

89-
onTestFinished(test: Test) {
89+
onTestFinished(test: Test | Custom) {
9090
if (this.finishedTests.has(test.id)) {
9191
return
9292
}

‎packages/vitest/src/node/reporters/reported-tasks.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
Custom as RunnerCustomCase,
23
Task as RunnerTask,
34
Test as RunnerTestCase,
45
File as RunnerTestFile,
@@ -55,7 +56,7 @@ class ReportedTaskImplementation {
5556
export class TestCase extends ReportedTaskImplementation {
5657
#fullName: string | undefined
5758

58-
declare public readonly task: RunnerTestCase
59+
declare public readonly task: RunnerTestCase | RunnerCustomCase
5960
public readonly type = 'test'
6061

6162
/**
@@ -78,7 +79,7 @@ export class TestCase extends ReportedTaskImplementation {
7879
*/
7980
public readonly parent: TestSuite | TestModule
8081

81-
protected constructor(task: RunnerTestCase, project: TestProject) {
82+
protected constructor(task: RunnerTestCase | RunnerCustomCase, project: TestProject) {
8283
super(task, project)
8384

8485
this.name = task.name
@@ -404,7 +405,7 @@ export interface TaskOptions {
404405
}
405406

406407
function buildOptions(
407-
task: RunnerTestCase | RunnerTestFile | RunnerTestSuite,
408+
task: RunnerTestCase | RunnerCustomCase | RunnerTestFile | RunnerTestSuite,
408409
): TaskOptions {
409410
return {
410411
each: task.each,

‎packages/vitest/src/node/reporters/summary.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { File, Test } from '@vitest/runner'
1+
import type { Custom, File, Test } from '@vitest/runner'
22
import type { Vitest } from '../core'
33
import type { Reporter } from '../types/reporter'
44
import type { HookOptions } from './task-parser'
@@ -169,7 +169,7 @@ export class SummaryReporter extends TaskParser implements Reporter {
169169
stats.hook.visible = false
170170
}
171171

172-
onTestStart(test: Test) {
172+
onTestStart(test: Test | Custom) {
173173
// Track slow running tests only on verbose mode
174174
if (!this.options.verbose) {
175175
return
@@ -200,7 +200,7 @@ export class SummaryReporter extends TaskParser implements Reporter {
200200
stats.tests.set(test.id, slowTest)
201201
}
202202

203-
onTestFinished(test: Test) {
203+
onTestFinished(test: Test | Custom) {
204204
const stats = this.getTestStats(test)
205205

206206
if (!stats) {
@@ -262,7 +262,7 @@ export class SummaryReporter extends TaskParser implements Reporter {
262262
}
263263
}
264264

265-
private getTestStats(test: Test) {
265+
private getTestStats(test: Test | Custom) {
266266
const file = test.file
267267
let stats = this.runningTests.get(file.id)
268268

‎packages/vitest/src/node/reporters/task-parser.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { File, Task, TaskResultPack, Test } from '@vitest/runner'
1+
import type { Custom, File, Task, TaskResultPack, Test } from '@vitest/runner'
22
import type { Vitest } from '../core'
33
import { getTests } from '@vitest/runner/utils'
44

@@ -19,8 +19,8 @@ export class TaskParser {
1919
onHookStart(_options: HookOptions) {}
2020
onHookEnd(_options: HookOptions) {}
2121

22-
onTestStart(_test: Test) {}
23-
onTestFinished(_test: Test) {}
22+
onTestStart(_test: Test | Custom) {}
23+
onTestFinished(_test: Test | Custom) {}
2424

2525
onTestFilePrepare(_file: File) {}
2626
onTestFileFinished(_file: File) {}
@@ -29,8 +29,8 @@ export class TaskParser {
2929
const startingTestFiles: File[] = []
3030
const finishedTestFiles: File[] = []
3131

32-
const startingTests: Test[] = []
33-
const finishedTests: Test[] = []
32+
const startingTests: (Test | Custom)[] = []
33+
const finishedTests: (Test | Custom)[] = []
3434

3535
const startingHooks: HookOptions[] = []
3636
const endingHooks: HookOptions[] = []
@@ -54,7 +54,7 @@ export class TaskParser {
5454
}
5555
}
5656

57-
if (task?.type === 'test') {
57+
if (task?.type === 'test' || task?.type === 'custom') {
5858
if (task.result?.state === 'run') {
5959
startingTests.push(task)
6060
}

‎packages/vitest/src/public/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export type Suite = Suite_
161161
export type File = File_
162162
/** @deprecated use `RunnerTestCase` instead */
163163
export type Test = Test_
164-
/** @deprecated do not use `Custom`, use `RunnerTestCase` instead */
164+
/** @deprecated use `RunnerCustomCase` instead */
165165
export type Custom = Custom_
166166
/** @deprecated use `RunnerTask` instead */
167167
export type Task = Task_

0 commit comments

Comments
 (0)
Please sign in to comment.