Skip to content

Commit accd2ed

Browse files
authored
refactor: enable isolatedDeclarations (#7473)
1 parent 01b91b5 commit accd2ed

File tree

168 files changed

+788
-640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+788
-640
lines changed

packages/browser/src/client/channel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export type IframeChannelEvent =
4040
| IframeChannelIncomingEvent
4141
| IframeChannelOutgoingEvent
4242

43-
export const channel = new BroadcastChannel(
43+
export const channel: BroadcastChannel = new BroadcastChannel(
4444
`vitest:${getBrowserState().sessionId}`,
4545
)
46-
export const globalChannel = new BroadcastChannel('vitest:global')
46+
export const globalChannel: BroadcastChannel = new BroadcastChannel('vitest:global')
4747

48-
export function waitForChannel(event: IframeChannelOutgoingEvent['type']) {
48+
export function waitForChannel(event: IframeChannelOutgoingEvent['type']): Promise<void> {
4949
return new Promise<void>((resolve) => {
5050
channel.addEventListener(
5151
'message',

packages/browser/src/client/client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { getBrowserState } from './utils'
66

77
const PAGE_TYPE = getBrowserState().type
88

9-
export const PORT = location.port
10-
export const HOST = [location.hostname, PORT].filter(Boolean).join(':')
11-
export const RPC_ID
9+
export const PORT: string = location.port
10+
export const HOST: string = [location.hostname, PORT].filter(Boolean).join(':')
11+
export const RPC_ID: string
1212
= PAGE_TYPE === 'orchestrator'
1313
? getBrowserState().sessionId
1414
: getBrowserState().testerId
1515
const METHOD = getBrowserState().method
16-
export const ENTRY_URL = `${
16+
export const ENTRY_URL: string = `${
1717
location.protocol === 'https:' ? 'wss:' : 'ws:'
1818
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ''}&method=${METHOD}&token=${(window as any).VITEST_API_TOKEN}`
1919

2020
let setCancel = (_: CancelReason) => {}
21-
export const onCancel = new Promise<CancelReason>((resolve) => {
21+
export const onCancel: Promise<CancelReason> = new Promise((resolve) => {
2222
setCancel = resolve
2323
})
2424

@@ -135,6 +135,6 @@ function createClient() {
135135
return ctx
136136
}
137137

138-
export const client = createClient()
138+
export const client: VitestBrowserClient = createClient()
139139

140140
export * from './channel'

packages/browser/src/client/tester/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
UserEventTabOptions,
1212
UserEventTypeOptions,
1313
} from '../../../context'
14+
import type { BrowserRunnerState } from '../utils'
1415
import { convertElementToCssSelector, ensureAwaited, getBrowserState, getWorkerState } from '../utils'
1516

1617
// this file should not import anything directly, only types and utils
@@ -238,7 +239,7 @@ function createPreviewUserEvent(userEventBase: TestingLibraryUserEvent, options:
238239
return vitestUserEvent
239240
}
240241

241-
export function cdp() {
242+
export function cdp(): BrowserRunnerState['cdp'] {
242243
return getBrowserState().cdp!
243244
}
244245

packages/browser/src/client/tester/dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ expect(${name}).toHaveBeenCalledWith(${formattedParams})
1818
}
1919
}
2020

21-
export function setupDialogsSpy() {
21+
export function setupDialogsSpy(): void {
2222
globalThis.alert = showPopupWarning('alert', undefined)
2323
globalThis.confirm = showPopupWarning('confirm', false, true)
2424
globalThis.prompt = showPopupWarning('prompt', null, 'your value')

packages/browser/src/client/tester/expect-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ExpectPollOptions } from 'vitest'
33
import * as matchers from '@testing-library/jest-dom/matchers'
44
import { chai, expect } from 'vitest'
55

6-
export async function setupExpectDom() {
6+
export async function setupExpectDom(): Promise<void> {
77
expect.extend(matchers)
88
expect.element = <T extends Element | Locator>(elementOrLocator: T, options?: ExpectPollOptions) => {
99
if (!(elementOrLocator instanceof Element) && !('element' in elementOrLocator)) {

packages/browser/src/client/tester/locators/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { ensureAwaited, getBrowserState, getWorkerState } from '../../utils'
2626
import { getElementError } from '../public-utils'
2727

2828
// we prefer using playwright locators because they are more powerful and support Shadow DOM
29-
export const selectorEngine = Ivya.create({
29+
export const selectorEngine: Ivya = Ivya.create({
3030
browser: ((name: string) => {
3131
switch (name) {
3232
case 'edge':
@@ -217,7 +217,7 @@ export abstract class Locator {
217217
return this.worker.rpc as any as BrowserRPC
218218
}
219219

220-
protected triggerCommand<T>(command: string, ...args: any[]) {
220+
protected triggerCommand<T>(command: string, ...args: any[]): Promise<T> {
221221
const filepath = this.worker.filepath
222222
|| this.worker.current?.file?.filepath
223223
|| undefined

packages/browser/src/client/tester/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { rpc } from './rpc'
44

55
const { Date, console, performance } = globalThis
66

7-
export function setupConsoleLogSpy() {
7+
export function setupConsoleLogSpy(): void {
88
const {
99
log,
1010
info,

packages/browser/src/client/tester/msw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ModuleMockerMSWInterceptor } from '@vitest/mocker/browser'
22
import { getConfig } from '../utils'
33

4-
export function createModuleMockerInterceptor() {
4+
export function createModuleMockerInterceptor(): ModuleMockerMSWInterceptor {
55
const debug = getConfig().env.VITEST_BROWSER_DEBUG
66
return new ModuleMockerMSWInterceptor({
77
globalThisAccessor: '"__vitest_mocker__"',

packages/browser/src/client/tester/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) {
3131

3232
const promises = new Set<Promise<unknown>>()
3333

34-
export async function rpcDone() {
34+
export async function rpcDone(): Promise<unknown[] | undefined> {
3535
if (!promises.size) {
3636
return
3737
}

packages/browser/src/client/tester/runner.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ interface BrowserRunnerOptions {
1616
config: SerializedConfig
1717
}
1818

19-
export const browserHashMap = new Map<
20-
string,
21-
string
22-
>()
19+
export const browserHashMap: Map<string, string> = new Map()
2320

2421
interface CoverageHandler {
2522
takeCoverage: () => Promise<unknown>
@@ -157,7 +154,7 @@ export async function initiateRunner(
157154
state: WorkerGlobalState,
158155
mocker: VitestBrowserClientMocker,
159156
config: SerializedConfig,
160-
) {
157+
): Promise<VitestRunner> {
161158
if (cachedRunner) {
162159
return cachedRunner
163160
}

packages/browser/src/client/tester/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class VitestBrowserSnapshotEnvironment implements SnapshotEnvironment {
66
private sourceMaps = new Map<string, any>()
77
private traceMaps = new Map<string, TraceMap>()
88

9-
public addSourceMap(filepath: string, map: any) {
9+
public addSourceMap(filepath: string, map: any): void {
1010
this.sourceMaps.set(filepath, map)
1111
}
1212

packages/browser/src/client/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import type { SerializedConfig, WorkerGlobalState } from 'vitest'
22

3-
export async function importId(id: string) {
3+
export async function importId(id: string): Promise<any> {
44
const name = `/@id/${id}`.replace(/\\/g, '/')
55
return getBrowserState().wrapModule(() => import(/* @vite-ignore */ name))
66
}
77

8-
export async function importFs(id: string) {
8+
export async function importFs(id: string): Promise<any> {
99
const name = `/@fs/${id}`.replace(/\\/g, '/')
1010
return getBrowserState().wrapModule(() => import(/* @vite-ignore */ name))
1111
}
1212

1313
export const executor = {
1414
isBrowser: true,
1515

16-
executeId: (id: string) => {
16+
executeId: (id: string): Promise<any> => {
1717
if (id[0] === '/' || id[1] === ':') {
1818
return importFs(id)
1919
}
@@ -103,7 +103,7 @@ export function getWorkerState(): WorkerGlobalState {
103103
}
104104

105105
/* @__NO_SIDE_EFFECTS__ */
106-
export function convertElementToCssSelector(element: Element) {
106+
export function convertElementToCssSelector(element: Element): string {
107107
if (!element || !(element instanceof Element)) {
108108
throw new Error(
109109
`Expected DOM element to be an instance of Element, received ${typeof element}`,

packages/browser/src/node/cdp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export class BrowserServerCDPHandler {
1111
private tester: WebSocketBrowserRPC,
1212
) {}
1313

14-
send(method: string, params?: Record<string, unknown>) {
14+
send(method: string, params?: Record<string, unknown>): Promise<unknown> {
1515
return this.session.send(method, params)
1616
}
1717

18-
on(event: string, id: string, once = false) {
18+
on(event: string, id: string, once = false): void {
1919
if (!this.listenerIds[event]) {
2020
this.listenerIds[event] = []
2121
}
@@ -36,7 +36,7 @@ export class BrowserServerCDPHandler {
3636
}
3737
}
3838

39-
off(event: string, id: string) {
39+
off(event: string, id: string): void {
4040
if (!this.listenerIds[event]) {
4141
this.listenerIds[event] = []
4242
}
@@ -48,7 +48,7 @@ export class BrowserServerCDPHandler {
4848
}
4949
}
5050

51-
once(event: string, listener: string) {
51+
once(event: string, listener: string): void {
5252
this.on(event, listener, true)
5353
}
5454
}

packages/browser/src/node/commands/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ import { type } from './type'
1717
import { upload } from './upload'
1818

1919
export default {
20-
readFile,
21-
removeFile,
22-
writeFile,
23-
__vitest_fileInfo: _fileInfo,
24-
__vitest_upload: upload,
25-
__vitest_click: click,
26-
__vitest_dblClick: dblClick,
27-
__vitest_tripleClick: tripleClick,
28-
__vitest_screenshot: screenshot,
29-
__vitest_type: type,
30-
__vitest_clear: clear,
31-
__vitest_fill: fill,
32-
__vitest_tab: tab,
33-
__vitest_keyboard: keyboard,
34-
__vitest_selectOptions: selectOptions,
35-
__vitest_dragAndDrop: dragAndDrop,
36-
__vitest_hover: hover,
37-
__vitest_cleanup: keyboardCleanup,
20+
readFile: readFile as typeof readFile,
21+
removeFile: removeFile as typeof removeFile,
22+
writeFile: writeFile as typeof writeFile,
23+
__vitest_fileInfo: _fileInfo as typeof _fileInfo,
24+
__vitest_upload: upload as typeof upload,
25+
__vitest_click: click as typeof click,
26+
__vitest_dblClick: dblClick as typeof dblClick,
27+
__vitest_tripleClick: tripleClick as typeof tripleClick,
28+
__vitest_screenshot: screenshot as typeof screenshot,
29+
__vitest_type: type as typeof type,
30+
__vitest_clear: clear as typeof clear,
31+
__vitest_fill: fill as typeof fill,
32+
__vitest_tab: tab as typeof tab,
33+
__vitest_keyboard: keyboard as typeof keyboard,
34+
__vitest_selectOptions: selectOptions as typeof selectOptions,
35+
__vitest_dragAndDrop: dragAndDrop as typeof dragAndDrop,
36+
__vitest_hover: hover as typeof hover,
37+
__vitest_cleanup: keyboardCleanup as typeof keyboardCleanup,
3838
}

packages/browser/src/node/commands/keyboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export async function keyboardImplementation(
8383
text: string,
8484
selectAll: () => Promise<void>,
8585
skipRelease: boolean,
86-
) {
86+
): Promise<{ pressed: Set<string> }> {
8787
if (provider instanceof PlaywrightBrowserProvider) {
8888
const page = provider.getPage(sessionId)
8989
const actions = parseKeyDef(defaultKeyMap, text)

packages/browser/src/node/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { fileURLToPath } from 'node:url'
22
import { resolve } from 'pathe'
33

44
const pkgRoot = resolve(fileURLToPath(import.meta.url), '../..')
5-
export const distRoot = resolve(pkgRoot, 'dist')
5+
export const distRoot: string = resolve(pkgRoot, 'dist')

packages/browser/src/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function createBrowserServer(
1717
configFile: string | undefined,
1818
prePlugins: Plugin[] = [],
1919
postPlugins: Plugin[] = [],
20-
) {
20+
): Promise<ParentBrowserProject> {
2121
if (project.vitest.version !== version) {
2222
project.vitest.logger.warn(
2323
c.yellow(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { ServerResponse } from 'node:http'
22

3-
export function disableCache(res: ServerResponse) {
3+
export function disableCache(res: ServerResponse): void {
44
res.setHeader(
55
'Cache-Control',
66
'no-cache, max-age=0, must-revalidate',
77
)
88
res.setHeader('Content-Type', 'text/html; charset=utf-8')
99
}
1010

11-
export function allowIframes(res: ServerResponse) {
11+
export function allowIframes(res: ServerResponse): void {
1212
// remove custom iframe related headers to allow the iframe to load
1313
res.removeHeader('X-Frame-Options')
1414
}

packages/browser/src/node/project.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { StackTraceParserOptions } from '@vitest/utils/source-map'
2-
import type { ErrorWithDiff, SerializedConfig } from 'vitest'
2+
import type { ViteDevServer } from 'vite'
3+
import type { ErrorWithDiff, ParsedStack, SerializedConfig } from 'vitest'
34
import type {
45
BrowserProvider,
56
ProjectBrowser as IProjectBrowser,
@@ -23,11 +24,11 @@ export class ProjectBrowser implements IProjectBrowser {
2324
public provider!: BrowserProvider
2425
public vitest: Vitest
2526
public config: ResolvedConfig
26-
public children = new Set<ProjectBrowser>()
27+
public children: Set<ProjectBrowser> = new Set<ProjectBrowser>()
2728

2829
public parent!: ParentBrowserProject
2930

30-
public state = new BrowserServerState()
31+
public state: BrowserServerState = new BrowserServerState()
3132

3233
constructor(
3334
public project: TestProject,
@@ -53,18 +54,18 @@ export class ProjectBrowser implements IProjectBrowser {
5354
).then(html => (this.testerHtml = html))
5455
}
5556

56-
get vite() {
57+
get vite(): ViteDevServer {
5758
return this.parent.vite
5859
}
5960

60-
wrapSerializedConfig() {
61+
wrapSerializedConfig(): SerializedConfig {
6162
const config = wrapConfig(this.project.serializedConfig)
6263
config.env ??= {}
6364
config.env.VITEST_BROWSER_DEBUG = process.env.VITEST_BROWSER_DEBUG || ''
6465
return config
6566
}
6667

67-
async initBrowserProvider(project: TestProject) {
68+
async initBrowserProvider(project: TestProject): Promise<void> {
6869
if (this.provider) {
6970
return
7071
}
@@ -95,18 +96,18 @@ export class ProjectBrowser implements IProjectBrowser {
9596
public parseErrorStacktrace(
9697
e: ErrorWithDiff,
9798
options: StackTraceParserOptions = {},
98-
) {
99+
): ParsedStack[] {
99100
return this.parent.parseErrorStacktrace(e, options)
100101
}
101102

102103
public parseStacktrace(
103104
trace: string,
104105
options: StackTraceParserOptions = {},
105-
) {
106+
): ParsedStack[] {
106107
return this.parent.parseStacktrace(trace, options)
107108
}
108109

109-
async close() {
110+
async close(): Promise<void> {
110111
await this.parent.vite.close()
111112
}
112113
}

0 commit comments

Comments
 (0)