Skip to content

Commit 95c367f

Browse files
authored
fix(browser): allow importing BrowserCommand if no browser package is installed (#8666)
1 parent 9edf904 commit 95c367f

File tree

7 files changed

+27
-27
lines changed

7 files changed

+27
-27
lines changed

packages/browser/context.d.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SerializedConfig } from 'vitest'
2-
import { StringifyOptions } from 'vitest/internal/browser'
2+
import { StringifyOptions, BrowserCommands } from 'vitest/internal/browser'
33
import { ARIARole } from './aria-role.js'
44
import {} from './matchers.js'
55

@@ -17,11 +17,6 @@ export type BufferEncoding =
1717
| 'binary'
1818
| 'hex'
1919

20-
export interface FsOptions {
21-
encoding?: BufferEncoding
22-
flag?: string | number
23-
}
24-
2520
export interface CDPSession {
2621
// methods are defined by the provider type augmentation
2722
}
@@ -168,19 +163,6 @@ export interface ScreenshotMatcherOptions<
168163
timeout?: number
169164
}
170165

171-
export interface BrowserCommands {
172-
readFile: (
173-
path: string,
174-
options?: BufferEncoding | FsOptions
175-
) => Promise<string>
176-
writeFile: (
177-
path: string,
178-
content: string,
179-
options?: BufferEncoding | (FsOptions & { mode?: number | string })
180-
) => Promise<void>
181-
removeFile: (path: string) => Promise<void>
182-
}
183-
184166
export interface UserEvent {
185167
/**
186168
* Creates a new user event instance. This is useful if you need to keep the
@@ -421,7 +403,7 @@ export interface LocatorByRoleOptions extends LocatorOptions {
421403

422404
interface LocatorScreenshotOptions extends Omit<ScreenshotOptions, 'element'> {}
423405

424-
interface LocatorSelectors {
406+
export interface LocatorSelectors {
425407
/**
426408
* Creates a way to locate an element by its [ARIA role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles), [ARIA attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes) and [accessible name](https://developer.mozilla.org/en-US/docs/Glossary/Accessible_name).
427409
* @see {@link https://vitest.dev/guide/browser/locators#getbyrole}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type { BrowserCommands } from 'vitest/browser'
12
import type { BrowserCommand, TestProject } from 'vitest/node'
2-
import type { BrowserCommands } from '../../../context'
33
import fs, { promises as fsp } from 'node:fs'
44
import { basename, dirname, resolve } from 'node:path'
55
import mime from 'mime/lite'

packages/browser/src/node/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { StackTraceParserOptions } from '@vitest/utils/source-map'
22
import type { ViteDevServer } from 'vite'
33
import type { ParsedStack, SerializedConfig, TestError } from 'vitest'
4+
import type { BrowserCommands } from 'vitest/browser'
45
import type {
56
BrowserCommand,
67
BrowserCommandContext,
@@ -10,7 +11,6 @@ import type {
1011
TestProject,
1112
Vitest,
1213
} from 'vitest/node'
13-
import type { BrowserCommands } from '../../context'
1414
import type { ParentBrowserProject } from './projectParent'
1515
import { existsSync } from 'node:fs'
1616
import { readFile } from 'node:fs/promises'

packages/vitest/browser/context.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from '@vitest/browser-playwright/context'
44
export * from '@vitest/browser-webdriverio/context'
55
// @ts-ignore -- @vitest/browser-preview might not be installed
66
export * from '@vitest/browser-preview/context'
7+
export { BrowserCommands, FsOptions } from 'vitest/internal/browser'

packages/vitest/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
"tinyglobby": "catalog:",
189189
"tinypool": "^2.0.0",
190190
"tinyrainbow": "catalog:",
191-
"vite": "^6.0.0 || ^7.0.0-0",
191+
"vite": "^6.0.0 || ^7.0.0",
192192
"why-is-node-running": "^2.3.0"
193193
},
194194
"devDependencies": {
@@ -205,7 +205,6 @@
205205
"@types/picomatch": "^4.0.2",
206206
"@types/prompts": "^2.4.9",
207207
"@types/sinonjs__fake-timers": "^8.1.5",
208-
"@vitest/browser-playwright": "workspace:*",
209208
"acorn-walk": "catalog:",
210209
"birpc": "catalog:",
211210
"cac": "catalog:",

packages/vitest/src/public/browser.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ export {
2323
getOriginalPosition,
2424
} from '@vitest/utils/source-map'
2525
export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers'
26+
27+
export interface FsOptions {
28+
encoding?: BufferEncoding
29+
flag?: string | number
30+
}
31+
32+
export interface BrowserCommands {
33+
readFile: (
34+
path: string,
35+
options?: BufferEncoding | FsOptions
36+
) => Promise<string>
37+
writeFile: (
38+
path: string,
39+
content: string,
40+
options?: BufferEncoding | (FsOptions & { mode?: number | string })
41+
) => Promise<void>
42+
removeFile: (path: string) => Promise<void>
43+
}
2644
/**
2745
* @internal
2846
*/

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)