Skip to content

Commit 510e64a

Browse files
committed
refactor: rename onWatcherRerun to onTestsRerun
1 parent a34b4f5 commit 510e64a

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

docs/config/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,8 @@ Since Vitest 2.2.0, you can define a custom callback function to be called when
10941094
```ts
10951095
import type { GlobalSetupContext } from 'vitest/node'
10961096

1097-
export default function setup({ onWatcherRerun }: GlobalSetupContext) {
1098-
onWatcherRerun(async () => {
1097+
export default function setup({ onTestsRerun }: GlobalSetupContext) {
1098+
onTestsRerun(async () => {
10991099
await restartDb()
11001100
})
11011101
}

packages/vitest/src/node/core.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Writable } from 'node:stream'
33
import type { ViteDevServer } from 'vite'
44
import type { defineWorkspace } from 'vitest/config'
55
import type { SerializedCoverageConfig } from '../runtime/config'
6-
import type { ArgumentsType, OnServerRestartHandler, OnWatcherRerunHandler, ProvidedContext, UserConsoleLog } from '../types/general'
6+
import type { ArgumentsType, OnServerRestartHandler, OnTestsRerunHandler, ProvidedContext, UserConsoleLog } from '../types/general'
77
import type { ProcessPool, WorkspaceSpec } from './pool'
88
import type { TestSpecification } from './spec'
99
import type { ResolvedConfig, UserConfig, VitestRunMode } from './types/config'
@@ -102,7 +102,7 @@ export class Vitest {
102102
private _onClose: (() => Awaited<unknown>)[] = []
103103
private _onSetServer: OnServerRestartHandler[] = []
104104
private _onCancelListeners: ((reason: CancelReason) => Promise<void> | void)[] = []
105-
private _onUserWatcherRerun: OnWatcherRerunHandler[] = []
105+
private _onUserTestsRerun: OnTestsRerunHandler[] = []
106106

107107
async setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig) {
108108
this.unregisterWatcher?.()
@@ -114,7 +114,7 @@ export class Vitest {
114114
this.coverageProvider = undefined
115115
this.runningPromise = undefined
116116
this._cachedSpecs.clear()
117-
this._onUserWatcherRerun = []
117+
this._onUserTestsRerun = []
118118

119119
const resolved = resolveConfig(this.mode, options, server.config, this.logger)
120120

@@ -695,7 +695,7 @@ export class Vitest {
695695

696696
await Promise.all([
697697
this.report('onWatcherRerun', files, trigger),
698-
...this._onUserWatcherRerun.map(fn => fn(files)),
698+
...this._onUserTestsRerun.map(fn => fn(files)),
699699
])
700700
await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)), allTestsRun)
701701

@@ -820,7 +820,7 @@ export class Vitest {
820820
const triggerLabel = Array.from(triggerIds).join(', ')
821821
await Promise.all([
822822
this.report('onWatcherRerun', files, triggerLabel),
823-
...this._onUserWatcherRerun.map(fn => fn(files)),
823+
...this._onUserTestsRerun.map(fn => fn(files)),
824824
])
825825

826826
await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)), false)
@@ -1159,7 +1159,7 @@ export class Vitest {
11591159
this._onClose.push(fn)
11601160
}
11611161

1162-
onWatcherRerun(fn: OnWatcherRerunHandler): void {
1163-
this._onUserWatcherRerun.push(fn)
1162+
onTestsRerun(fn: OnTestsRerunHandler): void {
1163+
this._onUserTestsRerun.push(fn)
11641164
}
11651165
}

packages/vitest/src/node/globalSetup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ViteNodeRunner } from 'vite-node/client'
2-
import type { OnWatcherRerunHandler, ProvidedContext } from '../types/general'
2+
import type { OnTestsRerunHandler, ProvidedContext } from '../types/general'
33
import type { ResolvedConfig } from './types/config'
44
import { toArray } from '@vitest/utils'
55

@@ -9,7 +9,7 @@ export interface GlobalSetupContext {
99
key: T,
1010
value: ProvidedContext[T]
1111
) => void
12-
onWatcherRerun: (cb: OnWatcherRerunHandler) => void
12+
onTestsRerun: (cb: OnTestsRerunHandler) => void
1313
}
1414

1515
export interface GlobalSetupFile {

packages/vitest/src/node/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class WorkspaceProject {
170170
const teardown = await globalSetupFile.setup?.({
171171
provide: (key, value) => this.provide(key, value),
172172
config: this.config,
173-
onWatcherRerun: cb => this.ctx.onWatcherRerun(cb),
173+
onTestsRerun: cb => this.ctx.onTestsRerun(cb),
174174
})
175175
if (teardown == null || !!globalSetupFile.teardown) {
176176
continue

packages/vitest/src/public/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export type {
128128

129129
export type {
130130
OnServerRestartHandler,
131-
OnWatcherRerunHandler,
131+
OnTestsRerunHandler,
132132
} from '../types/general'
133133

134134
export { createDebugger } from '../utils/debugger'

packages/vitest/src/types/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ export interface ModuleGraphData {
4646
}
4747

4848
export type OnServerRestartHandler = (reason?: string) => Promise<void> | void
49-
export type OnWatcherRerunHandler = (testFiles: string[]) => Promise<void> | void
49+
export type OnTestsRerunHandler = (testFiles: string[]) => Promise<void> | void
5050
export interface ProvidedContext {}

test/watch/fixtures/global-setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const calls: string[] = [];
44

55
(globalThis as any).__CALLS = calls
66

7-
export default ({ onWatcherRerun }: GlobalSetupContext) => {
7+
export default ({ onTestsRerun }: GlobalSetupContext) => {
88
calls.push('start')
9-
onWatcherRerun(() => {
9+
onTestsRerun(() => {
1010
calls.push('rerun')
1111
})
1212
return () => {

0 commit comments

Comments
 (0)