mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
fix!: remove Node types from the main entry point, use vitest/node instead (#8200)
This commit is contained in:
parent
5261df0b98
commit
1e60c4f440
1
.gitignore
vendored
1
.gitignore
vendored
@ -33,3 +33,4 @@ test/cli/fixtures/browser-multiple/basic-*
|
|||||||
test/browser/html/
|
test/browser/html/
|
||||||
test/core/html/
|
test/core/html/
|
||||||
.vitest-attachments
|
.vitest-attachments
|
||||||
|
explainFiles.txt
|
||||||
@ -27,6 +27,7 @@
|
|||||||
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --sequential --filter '@vitest/test-*' --filter !test-browser run test",
|
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --sequential --filter '@vitest/test-*' --filter !test-browser run test",
|
||||||
"test:examples": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/example-*' run test",
|
"test:examples": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/example-*' run test",
|
||||||
"test:ecosystem-ci": "ECOSYSTEM_CI=true pnpm test:ci",
|
"test:ecosystem-ci": "ECOSYSTEM_CI=true pnpm test:ci",
|
||||||
|
"typebuild": "tsx ./scripts/explain-types.ts",
|
||||||
"typecheck": "tsc -p tsconfig.check.json --noEmit",
|
"typecheck": "tsc -p tsconfig.check.json --noEmit",
|
||||||
"typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt",
|
"typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt",
|
||||||
"ui:build": "vite build packages/ui",
|
"ui:build": "vite build packages/ui",
|
||||||
|
|||||||
@ -64,6 +64,8 @@
|
|||||||
"providers"
|
"providers"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",
|
||||||
|
"typecheck:why": "tsc -p ./src/client/tsconfig.json --noEmit --explainFiles > explainTypes.txt",
|
||||||
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|
||||||
"build:client": "vite build src/client",
|
"build:client": "vite build src/client",
|
||||||
"build:node": "rollup -c",
|
"build:node": "rollup -c",
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import type { ModuleMocker } from '@vitest/mocker/browser'
|
import type { ModuleMocker } from '@vitest/mocker/browser'
|
||||||
import type { CancelReason } from '@vitest/runner'
|
import type { CancelReason } from '@vitest/runner'
|
||||||
import type { BirpcReturn } from 'birpc'
|
import type { BirpcReturn } from 'birpc'
|
||||||
import type { WebSocketBrowserEvents, WebSocketBrowserHandlers } from '../node/types'
|
import type { WebSocketBrowserEvents, WebSocketBrowserHandlers } from '../types'
|
||||||
import type { IframeOrchestrator } from './orchestrator'
|
import type { IframeOrchestrator } from './orchestrator'
|
||||||
import { createBirpc } from 'birpc'
|
import { createBirpc } from 'birpc'
|
||||||
import { parse, stringify } from 'flatted'
|
import { parse, stringify } from 'flatted'
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import type { Options as TestingLibraryOptions, UserEvent as TestingLibraryUserEvent } from '@testing-library/user-event'
|
import type {
|
||||||
import type { RunnerTask } from 'vitest'
|
Options as TestingLibraryOptions,
|
||||||
|
UserEvent as TestingLibraryUserEvent,
|
||||||
|
} from '@testing-library/user-event'
|
||||||
import type {
|
import type {
|
||||||
BrowserLocators,
|
BrowserLocators,
|
||||||
BrowserPage,
|
BrowserPage,
|
||||||
Locator,
|
Locator,
|
||||||
UserEvent,
|
UserEvent,
|
||||||
} from '../../../context'
|
} from '@vitest/browser/context'
|
||||||
|
import type { RunnerTask } from 'vitest'
|
||||||
import type { IframeViewportEvent } from '../client'
|
import type { IframeViewportEvent } from '../client'
|
||||||
import type { BrowserRunnerState } from '../utils'
|
import type { BrowserRunnerState } from '../utils'
|
||||||
import type { Locator as LocatorAPI } from './locators/index'
|
import type { Locator as LocatorAPI } from './locators/index'
|
||||||
@ -289,12 +292,19 @@ export const page: BrowserPage = {
|
|||||||
const name
|
const name
|
||||||
= options.path || `${taskName.replace(/[^a-z0-9]/gi, '-')}-${number}.png`
|
= options.path || `${taskName.replace(/[^a-z0-9]/gi, '-')}-${number}.png`
|
||||||
|
|
||||||
return ensureAwaited(error => triggerCommand('__vitest_screenshot', [name, processTimeoutOptions({
|
return ensureAwaited(error => triggerCommand(
|
||||||
|
'__vitest_screenshot',
|
||||||
|
[
|
||||||
|
name,
|
||||||
|
processTimeoutOptions({
|
||||||
...options,
|
...options,
|
||||||
element: options.element
|
element: options.element
|
||||||
? convertToSelector(options.element)
|
? convertToSelector(options.element)
|
||||||
: undefined,
|
: undefined,
|
||||||
})], error))
|
} as any /** TODO */),
|
||||||
|
],
|
||||||
|
error,
|
||||||
|
))
|
||||||
},
|
},
|
||||||
getByRole() {
|
getByRole() {
|
||||||
throw new Error(`Method "getByRole" is not implemented in the "${provider}" provider.`)
|
throw new Error(`Method "getByRole" is not implemented in the "${provider}" provider.`)
|
||||||
|
|||||||
@ -1,4 +1,12 @@
|
|||||||
import type { UserEventClearOptions, UserEventClickOptions, UserEventDragAndDropOptions, UserEventFillOptions, UserEventHoverOptions, UserEventSelectOptions, UserEventUploadOptions } from '@vitest/browser/context'
|
import type {
|
||||||
|
UserEventClearOptions,
|
||||||
|
UserEventClickOptions,
|
||||||
|
UserEventDragAndDropOptions,
|
||||||
|
UserEventFillOptions,
|
||||||
|
UserEventHoverOptions,
|
||||||
|
UserEventSelectOptions,
|
||||||
|
UserEventUploadOptions,
|
||||||
|
} from '@vitest/browser/context'
|
||||||
import { page, server } from '@vitest/browser/context'
|
import { page, server } from '@vitest/browser/context'
|
||||||
import {
|
import {
|
||||||
getByAltTextSelector,
|
getByAltTextSelector,
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import type { UserEventClickOptions, UserEventDragAndDropOptions, UserEventHoverOptions, UserEventSelectOptions } from '@vitest/browser/context'
|
import type {
|
||||||
|
UserEventClickOptions,
|
||||||
|
UserEventDragAndDropOptions,
|
||||||
|
UserEventHoverOptions,
|
||||||
|
UserEventSelectOptions,
|
||||||
|
} from '@vitest/browser/context'
|
||||||
import { page, server } from '@vitest/browser/context'
|
import { page, server } from '@vitest/browser/context'
|
||||||
import {
|
import {
|
||||||
getByAltTextSelector,
|
getByAltTextSelector,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import type { CancelReason, File, Suite, Task, TaskEventPack, TaskResultPack, Test, TestAnnotation, VitestRunner } from '@vitest/runner'
|
import type { CancelReason, File, Suite, Task, TaskEventPack, TaskResultPack, Test, TestAnnotation, VitestRunner } from '@vitest/runner'
|
||||||
import type { SerializedConfig, TestExecutionMethod, WorkerGlobalState } from 'vitest'
|
import type { SerializedConfig, TestExecutionMethod, WorkerGlobalState } from 'vitest'
|
||||||
import type { VitestExecutor } from 'vitest/execute'
|
|
||||||
import type { VitestBrowserClientMocker } from './mocker'
|
import type { VitestBrowserClientMocker } from './mocker'
|
||||||
import { globalChannel, onCancel } from '@vitest/browser/client'
|
import { globalChannel, onCancel } from '@vitest/browser/client'
|
||||||
import { page, userEvent } from '@vitest/browser/context'
|
import { page, userEvent } from '@vitest/browser/context'
|
||||||
@ -77,7 +76,7 @@ export function createBrowserRunner(
|
|||||||
if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && task.result?.state === 'fail') {
|
if (this.config.browser.screenshotFailures && document.body.clientHeight > 0 && task.result?.state === 'fail') {
|
||||||
const screenshot = await page.screenshot({
|
const screenshot = await page.screenshot({
|
||||||
timeout: this.config.browser.providerOptions?.actionTimeout ?? 5_000,
|
timeout: this.config.browser.providerOptions?.actionTimeout ?? 5_000,
|
||||||
}).catch((err) => {
|
} as any /** TODO */).catch((err) => {
|
||||||
console.error('[vitest] Failed to take a screenshot', err)
|
console.error('[vitest] Failed to take a screenshot', err)
|
||||||
})
|
})
|
||||||
if (screenshot) {
|
if (screenshot) {
|
||||||
@ -239,8 +238,8 @@ export async function initiateRunner(
|
|||||||
})
|
})
|
||||||
|
|
||||||
const [diffOptions] = await Promise.all([
|
const [diffOptions] = await Promise.all([
|
||||||
loadDiffConfig(config, executor as unknown as VitestExecutor),
|
loadDiffConfig(config, executor as any),
|
||||||
loadSnapshotSerializers(config, executor as unknown as VitestExecutor),
|
loadSnapshotSerializers(config, executor as any),
|
||||||
])
|
])
|
||||||
runner.config.diffOptions = diffOptions
|
runner.config.diffOptions = diffOptions
|
||||||
getWorkerState().onFilterStackTrace = (stack: string) => {
|
getWorkerState().onFilterStackTrace = (stack: string) => {
|
||||||
|
|||||||
@ -32,6 +32,7 @@ const state: WorkerGlobalState = {
|
|||||||
},
|
},
|
||||||
onCleanup: fn => getBrowserState().cleanups.push(fn),
|
onCleanup: fn => getBrowserState().cleanups.push(fn),
|
||||||
moduleCache: getBrowserState().moduleCache,
|
moduleCache: getBrowserState().moduleCache,
|
||||||
|
moduleExecutionInfo: new Map(),
|
||||||
rpc: null as any,
|
rpc: null as any,
|
||||||
durations: {
|
durations: {
|
||||||
environment: 0,
|
environment: 0,
|
||||||
|
|||||||
21
packages/browser/src/client/tsconfig.json
Normal file
21
packages/browser/src/client/tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"esnext",
|
||||||
|
"DOM.Iterable"
|
||||||
|
],
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./**/*.ts",
|
||||||
|
"../types.ts",
|
||||||
|
"../../matchers.d.ts",
|
||||||
|
"../../../vitest/src/integrations/chai/chai-subset.d.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"./vite.config.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -65,7 +65,7 @@ export function ensureAwaited<T>(promise: (error?: Error) => Promise<T>): Promis
|
|||||||
export interface BrowserRunnerState {
|
export interface BrowserRunnerState {
|
||||||
files: string[]
|
files: string[]
|
||||||
runningFiles: string[]
|
runningFiles: string[]
|
||||||
moduleCache: WorkerGlobalState['moduleCache']
|
moduleCache: Map<string, any>
|
||||||
config: SerializedConfig
|
config: SerializedConfig
|
||||||
provider: string
|
provider: string
|
||||||
runner: VitestRunner
|
runner: VitestRunner
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { CDPSession } from 'vitest/node'
|
import type { CDPSession } from 'vitest/node'
|
||||||
import type { WebSocketBrowserRPC } from './types'
|
import type { WebSocketBrowserRPC } from '../types'
|
||||||
|
|
||||||
export class BrowserServerCDPHandler {
|
export class BrowserServerCDPHandler {
|
||||||
private listenerIds: Record<string, string[]> = {}
|
private listenerIds: Record<string, string[]> = {}
|
||||||
|
|||||||
@ -3,10 +3,10 @@ import type { Duplex } from 'node:stream'
|
|||||||
import type { TestError } from 'vitest'
|
import type { TestError } from 'vitest'
|
||||||
import type { BrowserCommandContext, ResolveSnapshotPathHandlerContext, TestProject } from 'vitest/node'
|
import type { BrowserCommandContext, ResolveSnapshotPathHandlerContext, TestProject } from 'vitest/node'
|
||||||
import type { WebSocket } from 'ws'
|
import type { WebSocket } from 'ws'
|
||||||
|
import type { WebSocketBrowserEvents, WebSocketBrowserHandlers } from '../types'
|
||||||
import type { ParentBrowserProject } from './projectParent'
|
import type { ParentBrowserProject } from './projectParent'
|
||||||
import type { WebdriverBrowserProvider } from './providers/webdriver'
|
import type { WebdriverBrowserProvider } from './providers/webdriver'
|
||||||
import type { BrowserServerState } from './state'
|
import type { BrowserServerState } from './state'
|
||||||
import type { WebSocketBrowserEvents, WebSocketBrowserHandlers } from './types'
|
|
||||||
import { existsSync, promises as fs } from 'node:fs'
|
import { existsSync, promises as fs } from 'node:fs'
|
||||||
import { AutomockedModule, AutospiedModule, ManualMockedModule, RedirectedModule } from '@vitest/mocker'
|
import { AutomockedModule, AutospiedModule, ManualMockedModule, RedirectedModule } from '@vitest/mocker'
|
||||||
import { ServerMockResolver } from '@vitest/mocker/node'
|
import { ServerMockResolver } from '@vitest/mocker/node'
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { BrowserServerState as IBrowserServerState } from 'vitest/node'
|
import type { BrowserServerState as IBrowserServerState } from 'vitest/node'
|
||||||
import type { WebSocketBrowserRPC } from './types'
|
import type { WebSocketBrowserRPC } from '../types'
|
||||||
|
|
||||||
export class BrowserServerState implements IBrowserServerState {
|
export class BrowserServerState implements IBrowserServerState {
|
||||||
public readonly orchestrators: Map<string, WebSocketBrowserRPC> = new Map()
|
public readonly orchestrators: Map<string, WebSocketBrowserRPC> = new Map()
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import type { MockedModuleSerialized } from '@vitest/mocker'
|
import type { MockedModuleSerialized, ServerIdResolution, ServerMockResolution } from '@vitest/mocker'
|
||||||
import type { ServerIdResolution, ServerMockResolution } from '@vitest/mocker/node'
|
|
||||||
import type { TaskEventPack, TaskResultPack, TestAnnotation } from '@vitest/runner'
|
import type { TaskEventPack, TaskResultPack, TestAnnotation } from '@vitest/runner'
|
||||||
import type { BirpcReturn } from 'birpc'
|
import type { BirpcReturn } from 'birpc'
|
||||||
import type {
|
import type {
|
||||||
AfterSuiteRunMeta,
|
AfterSuiteRunMeta,
|
||||||
BrowserTesterOptions,
|
BrowserTesterOptions,
|
||||||
CancelReason,
|
CancelReason,
|
||||||
Reporter,
|
|
||||||
RunnerTestFile,
|
RunnerTestFile,
|
||||||
|
SerializedTestSpecification,
|
||||||
SnapshotResult,
|
SnapshotResult,
|
||||||
TestExecutionMethod,
|
TestExecutionMethod,
|
||||||
UserConsoleLog,
|
UserConsoleLog,
|
||||||
@ -60,16 +59,19 @@ export interface WebSocketBrowserHandlers {
|
|||||||
trackCdpEvent: (sessionId: string, type: 'on' | 'once' | 'off', event: string, listenerId: string) => void
|
trackCdpEvent: (sessionId: string, type: 'on' | 'once' | 'off', event: string, listenerId: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebSocketEvents
|
export type Awaitable<T> = T | PromiseLike<T>
|
||||||
extends Pick<
|
|
||||||
Reporter,
|
export interface WebSocketEvents {
|
||||||
| 'onCollected'
|
onCollected?: (files: RunnerTestFile[]) => Awaitable<void>
|
||||||
| 'onFinished'
|
onFinished?: (
|
||||||
| 'onTaskUpdate'
|
files: File[],
|
||||||
| 'onUserConsoleLog'
|
errors: unknown[],
|
||||||
| 'onPathsCollected'
|
coverage?: unknown
|
||||||
| 'onSpecsCollected'
|
) => Awaitable<void>
|
||||||
> {
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>
|
||||||
|
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>
|
||||||
|
onPathsCollected?: (paths?: string[]) => Awaitable<void>
|
||||||
|
onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable<void>
|
||||||
onFinishedReportCoverage: () => void
|
onFinishedReportCoverage: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4,5 +4,10 @@
|
|||||||
"types": ["node", "vite/client"],
|
"types": ["node", "vite/client"],
|
||||||
"isolatedDeclarations": true
|
"isolatedDeclarations": true
|
||||||
},
|
},
|
||||||
"exclude": ["dist", "node_modules", "**/vite.config.ts"]
|
"exclude": [
|
||||||
|
"dist",
|
||||||
|
"node_modules",
|
||||||
|
"**/vite.config.ts",
|
||||||
|
"src/client/**/*.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,4 +22,6 @@ export type {
|
|||||||
ModuleMockFactory,
|
ModuleMockFactory,
|
||||||
ModuleMockFactoryWithHelper,
|
ModuleMockFactoryWithHelper,
|
||||||
ModuleMockOptions,
|
ModuleMockOptions,
|
||||||
|
ServerIdResolution,
|
||||||
|
ServerMockResolution,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|||||||
@ -10,8 +10,4 @@ export type { InterceptorPluginOptions } from './interceptorPlugin'
|
|||||||
export { mockerPlugin } from './mockerPlugin'
|
export { mockerPlugin } from './mockerPlugin'
|
||||||
export { findMockRedirect } from './redirect'
|
export { findMockRedirect } from './redirect'
|
||||||
export { ServerMockResolver } from './resolver'
|
export { ServerMockResolver } from './resolver'
|
||||||
export type {
|
export type { ServerResolverOptions } from './resolver'
|
||||||
ServerIdResolution,
|
|
||||||
ServerMockResolution,
|
|
||||||
ServerResolverOptions,
|
|
||||||
} from './resolver'
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { Rollup, ResolvedConfig as ViteConfig, ViteDevServer } from 'vite'
|
import type { Rollup, ResolvedConfig as ViteConfig, ViteDevServer } from 'vite'
|
||||||
|
import type { ServerIdResolution, ServerMockResolution } from '../types'
|
||||||
import { existsSync, readFileSync } from 'node:fs'
|
import { existsSync, readFileSync } from 'node:fs'
|
||||||
import { isAbsolute, join, resolve } from 'pathe'
|
import { isAbsolute, join, resolve } from 'pathe'
|
||||||
import { cleanUrl } from '../utils'
|
import { cleanUrl } from '../utils'
|
||||||
@ -181,17 +182,3 @@ function withTrailingSlash(path: string): string {
|
|||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerMockResolution {
|
|
||||||
mockType: 'manual' | 'redirect' | 'automock' | 'autospy'
|
|
||||||
resolvedId: string
|
|
||||||
resolvedUrl: string
|
|
||||||
needsInterop?: boolean
|
|
||||||
redirectUrl?: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ServerIdResolution {
|
|
||||||
id: string
|
|
||||||
url: string
|
|
||||||
optimized: boolean
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,3 +7,17 @@ export type ModuleMockFactory = () => any
|
|||||||
export interface ModuleMockOptions {
|
export interface ModuleMockOptions {
|
||||||
spy?: boolean
|
spy?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServerMockResolution {
|
||||||
|
mockType: 'manual' | 'redirect' | 'automock' | 'autospy'
|
||||||
|
resolvedId: string
|
||||||
|
resolvedUrl: string
|
||||||
|
needsInterop?: boolean
|
||||||
|
redirectUrl?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServerIdResolution {
|
||||||
|
id: string
|
||||||
|
url: string
|
||||||
|
optimized: boolean
|
||||||
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ export { default as SnapshotState } from './port/state'
|
|||||||
|
|
||||||
export type {
|
export type {
|
||||||
SnapshotData,
|
SnapshotData,
|
||||||
|
SnapshotEnvironment,
|
||||||
SnapshotMatchOptions,
|
SnapshotMatchOptions,
|
||||||
SnapshotResult,
|
SnapshotResult,
|
||||||
SnapshotSerializer,
|
SnapshotSerializer,
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
|
"lib": ["dom", "esnext", "DOM.Iterable"],
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
},
|
},
|
||||||
"include": ["./client/**/*"],
|
"include": ["./client/**/*"],
|
||||||
|
|||||||
@ -47,7 +47,6 @@ export type {
|
|||||||
Constructable,
|
Constructable,
|
||||||
DeepMerge,
|
DeepMerge,
|
||||||
MergeInsertions,
|
MergeInsertions,
|
||||||
MutableArray,
|
|
||||||
Nullable,
|
Nullable,
|
||||||
ParsedStack,
|
ParsedStack,
|
||||||
SerializedError,
|
SerializedError,
|
||||||
|
|||||||
@ -1,13 +1,22 @@
|
|||||||
const SAFE_TIMERS_SYMBOL = Symbol('vitest:SAFE_TIMERS')
|
const SAFE_TIMERS_SYMBOL = Symbol('vitest:SAFE_TIMERS')
|
||||||
|
|
||||||
export interface SafeTimers {
|
export interface SafeTimers {
|
||||||
nextTick: (cb: () => void) => void
|
// node.js timers
|
||||||
|
nextTick?: (cb: () => void) => void
|
||||||
|
setImmediate?: {
|
||||||
|
<TArgs extends any[]>(
|
||||||
|
callback: (...args: TArgs) => void,
|
||||||
|
...args: TArgs
|
||||||
|
): any
|
||||||
|
__promisify__: <T = void>(value?: T, options?: any) => Promise<T>
|
||||||
|
}
|
||||||
|
clearImmediate?: (immediateId: any) => void
|
||||||
|
|
||||||
|
// cross-platform timers
|
||||||
setTimeout: typeof setTimeout
|
setTimeout: typeof setTimeout
|
||||||
setInterval: typeof setInterval
|
setInterval: typeof setInterval
|
||||||
clearInterval: typeof clearInterval
|
clearInterval: typeof clearInterval
|
||||||
clearTimeout: typeof clearTimeout
|
clearTimeout: typeof clearTimeout
|
||||||
setImmediate: typeof setImmediate
|
|
||||||
clearImmediate: typeof clearImmediate
|
|
||||||
queueMicrotask: typeof queueMicrotask
|
queueMicrotask: typeof queueMicrotask
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +32,7 @@ export function getSafeTimers(): SafeTimers {
|
|||||||
} = (globalThis as any)[SAFE_TIMERS_SYMBOL] || globalThis
|
} = (globalThis as any)[SAFE_TIMERS_SYMBOL] || globalThis
|
||||||
|
|
||||||
const { nextTick: safeNextTick } = (globalThis as any)[SAFE_TIMERS_SYMBOL]
|
const { nextTick: safeNextTick } = (globalThis as any)[SAFE_TIMERS_SYMBOL]
|
||||||
|| globalThis.process || { nextTick: (cb: () => void) => cb() }
|
|| globalThis.process || {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nextTick: safeNextTick,
|
nextTick: safeNextTick,
|
||||||
@ -48,9 +57,7 @@ export function setSafeTimers(): void {
|
|||||||
queueMicrotask: safeQueueMicrotask,
|
queueMicrotask: safeQueueMicrotask,
|
||||||
} = globalThis
|
} = globalThis
|
||||||
|
|
||||||
const { nextTick: safeNextTick } = globalThis.process || {
|
const { nextTick: safeNextTick } = globalThis.process || {}
|
||||||
nextTick: cb => cb(),
|
|
||||||
}
|
|
||||||
|
|
||||||
const timers = {
|
const timers = {
|
||||||
nextTick: safeNextTick,
|
nextTick: safeNextTick,
|
||||||
|
|||||||
@ -17,10 +17,6 @@ export type DeepMerge<F, S> = MergeInsertions<{
|
|||||||
: never;
|
: never;
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export type MutableArray<T extends readonly any[]> = {
|
|
||||||
-readonly [k in keyof T]: T[k];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Constructable {
|
export interface Constructable {
|
||||||
new (...args: any[]): any
|
new (...args: any[]): any
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
// CI fails only for this file, but it works locally
|
|
||||||
|
|
||||||
import type { Assertion, ExpectStatic, MatcherState } from '@vitest/expect'
|
import type { Assertion, ExpectStatic, MatcherState } from '@vitest/expect'
|
||||||
import type { TaskPopulated, Test } from '@vitest/runner'
|
import type { TaskPopulated, Test } from '@vitest/runner'
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -724,7 +724,7 @@ function createVitest(): VitestUtils {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resetModules() {
|
resetModules() {
|
||||||
resetModules(workerState.moduleCache)
|
resetModules(workerState.moduleCache as any)
|
||||||
return utils
|
return utils
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import type { AliasOptions, ConfigEnv, DepOptimizationConfig, ServerOptions, Use
|
|||||||
import type { ViteNodeServerOptions } from 'vite-node'
|
import type { ViteNodeServerOptions } from 'vite-node'
|
||||||
import type { ChaiConfig } from '../../integrations/chai/config'
|
import type { ChaiConfig } from '../../integrations/chai/config'
|
||||||
import type { SerializedConfig } from '../../runtime/config'
|
import type { SerializedConfig } from '../../runtime/config'
|
||||||
import type { EnvironmentOptions } from '../../types/environment'
|
|
||||||
import type { Arrayable, LabelColor, ParsedStack, ProvidedContext, TestError } from '../../types/general'
|
import type { Arrayable, LabelColor, ParsedStack, ProvidedContext, TestError } from '../../types/general'
|
||||||
import type { HappyDOMOptions } from '../../types/happy-dom-options'
|
import type { HappyDOMOptions } from '../../types/happy-dom-options'
|
||||||
import type { JSDOMOptions } from '../../types/jsdom-options'
|
import type { JSDOMOptions } from '../../types/jsdom-options'
|
||||||
@ -47,7 +46,16 @@ export type ApiConfig = Pick<
|
|||||||
'port' | 'strictPort' | 'host' | 'middlewareMode'
|
'port' | 'strictPort' | 'host' | 'middlewareMode'
|
||||||
>
|
>
|
||||||
|
|
||||||
export type { EnvironmentOptions, HappyDOMOptions, JSDOMOptions }
|
export interface EnvironmentOptions {
|
||||||
|
/**
|
||||||
|
* jsdom options.
|
||||||
|
*/
|
||||||
|
jsdom?: JSDOMOptions
|
||||||
|
happyDOM?: HappyDOMOptions
|
||||||
|
[x: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { HappyDOMOptions, JSDOMOptions }
|
||||||
|
|
||||||
export type VitestRunMode = 'test' | 'benchmark'
|
export type VitestRunMode = 'test' | 'benchmark'
|
||||||
|
|
||||||
|
|||||||
@ -1,53 +1,5 @@
|
|||||||
import type {
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
Vitest as Vitest_,
|
|
||||||
} from '../node/core'
|
|
||||||
|
|
||||||
import type {
|
|
||||||
BenchmarkUserOptions as BenchmarkUserOptions_,
|
|
||||||
} from '../node/types/benchmark'
|
|
||||||
import type {
|
|
||||||
ApiConfig as ApiConfig_,
|
|
||||||
BrowserConfigOptions as BrowserConfigOptions_,
|
|
||||||
BrowserScript as BrowserScript_,
|
|
||||||
BuiltinEnvironment as BuiltinEnvironment_,
|
|
||||||
CSSModuleScopeStrategy as CSSModuleScopeStrategy_,
|
|
||||||
DepsOptimizationOptions as DepsOptimizationOptions_,
|
|
||||||
EnvironmentOptions as EnvironmentOptions_,
|
|
||||||
HappyDOMOptions as HappyDOMOptions_,
|
|
||||||
InlineConfig as InlineConfig_,
|
|
||||||
JSDOMOptions as JSDOMOptions_,
|
|
||||||
Pool as Pool_,
|
|
||||||
PoolOptions as PoolOptions_,
|
|
||||||
ProjectConfig as ProjectConfig_,
|
|
||||||
ResolvedConfig as ResolvedConfig_,
|
|
||||||
SequenceHooks as SequenceHooks_,
|
|
||||||
SequenceSetupFiles as SequenceSetupFiles_,
|
|
||||||
TransformModePatterns as TransformModePatterns_,
|
|
||||||
TypecheckConfig as TypecheckConfig_,
|
|
||||||
UserConfig as UserConfig_,
|
|
||||||
UserWorkspaceConfig as UserWorkspaceConfig_,
|
|
||||||
VitestEnvironment as VitestEnvironment_,
|
|
||||||
VitestRunMode as VitestRunMode_,
|
|
||||||
} from '../node/types/config'
|
|
||||||
|
|
||||||
import type {
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
Reporter as Reporter_,
|
|
||||||
} from '../node/types/reporter'
|
|
||||||
|
|
||||||
import type {
|
|
||||||
WorkerContext as WorkerContext_,
|
|
||||||
} from '../node/types/worker'
|
|
||||||
|
|
||||||
import type { SerializedTestSpecification } from '../runtime/types/utils'
|
import type { SerializedTestSpecification } from '../runtime/types/utils'
|
||||||
|
|
||||||
import type {
|
|
||||||
WorkerRPC as WorkerRPC_,
|
|
||||||
} from '../types/worker'
|
|
||||||
|
|
||||||
// TODO: deprecate <reference types="vitest" /> in favor of `<reference types="vitest/config" />`
|
|
||||||
import '../node/types/vite'
|
|
||||||
import '../types/global'
|
import '../types/global'
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
@ -85,16 +37,10 @@ export type { AssertType } from '../typecheck/assertType'
|
|||||||
export { expectTypeOf } from '../typecheck/expectTypeOf'
|
export { expectTypeOf } from '../typecheck/expectTypeOf'
|
||||||
export type { ExpectTypeOf } from '../typecheck/expectTypeOf'
|
export type { ExpectTypeOf } from '../typecheck/expectTypeOf'
|
||||||
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type WorkerContext = WorkerContext_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type WorkerRPC = WorkerRPC_
|
|
||||||
|
|
||||||
export type { BrowserTesterOptions } from '../types/browser'
|
export type { BrowserTesterOptions } from '../types/browser'
|
||||||
export type {
|
export type {
|
||||||
AfterSuiteRunMeta,
|
AfterSuiteRunMeta,
|
||||||
LabelColor,
|
LabelColor,
|
||||||
ModuleCache,
|
|
||||||
ModuleGraphData,
|
ModuleGraphData,
|
||||||
ParsedStack,
|
ParsedStack,
|
||||||
ProvidedContext,
|
ProvidedContext,
|
||||||
@ -112,7 +58,6 @@ export type { BrowserUI } from '../types/ui'
|
|||||||
export type {
|
export type {
|
||||||
ContextRPC,
|
ContextRPC,
|
||||||
ContextTestEnvironment,
|
ContextTestEnvironment,
|
||||||
ResolveIdFunction,
|
|
||||||
TestExecutionMethod,
|
TestExecutionMethod,
|
||||||
WorkerGlobalState,
|
WorkerGlobalState,
|
||||||
} from '../types/worker'
|
} from '../types/worker'
|
||||||
@ -168,11 +113,6 @@ export type {
|
|||||||
TestOptions,
|
TestOptions,
|
||||||
} from '@vitest/runner'
|
} from '@vitest/runner'
|
||||||
|
|
||||||
/** @deprecated import from `vitest/reporter` instead */
|
|
||||||
export type Reporter = Reporter_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type Vitest = Vitest_
|
|
||||||
|
|
||||||
export type { CancelReason } from '@vitest/runner'
|
export type { CancelReason } from '@vitest/runner'
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
@ -196,58 +136,6 @@ export type {
|
|||||||
MockInstance,
|
MockInstance,
|
||||||
} from '@vitest/spy'
|
} from '@vitest/spy'
|
||||||
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type BrowserScript = BrowserScript_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type BrowserConfigOptions = BrowserConfigOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type SequenceHooks = SequenceHooks_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type SequenceSetupFiles = SequenceSetupFiles_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type BuiltinEnvironment = BuiltinEnvironment_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type VitestEnvironment = VitestEnvironment_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type Pool = Pool_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type PoolOptions = PoolOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type CSSModuleScopeStrategy = CSSModuleScopeStrategy_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type ApiConfig = ApiConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type JSDOMOptions = JSDOMOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type HappyDOMOptions = HappyDOMOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type EnvironmentOptions = EnvironmentOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type VitestRunMode = VitestRunMode_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type DepsOptimizationOptions = DepsOptimizationOptions_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type TransformModePatterns = TransformModePatterns_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type InlineConfig = InlineConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type TypecheckConfig = TypecheckConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type UserConfig = UserConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type ResolvedConfig = ResolvedConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type ProjectConfig = ProjectConfig_
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type UserWorkspaceConfig = UserWorkspaceConfig_
|
|
||||||
|
|
||||||
export type { SerializedError } from '@vitest/utils'
|
export type { SerializedError } from '@vitest/utils'
|
||||||
|
|
||||||
/** @deprecated use `SerializedTestSpecification` instead */
|
|
||||||
export type SerializableSpec = SerializedTestSpecification
|
|
||||||
export type { SerializedTestSpecification }
|
export type { SerializedTestSpecification }
|
||||||
|
|
||||||
/** @deprecated import from `vitest/node` instead */
|
|
||||||
export type BenchmarkUserOptions = BenchmarkUserOptions_
|
|
||||||
|
|
||||||
export type { DiffOptions } from '@vitest/utils/diff'
|
export type { DiffOptions } from '@vitest/utils/diff'
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import type { ModuleDiagnostic as _FileDiagnostic } from '../node/reporters/reported-tasks'
|
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { Vitest } from '../node/core'
|
import { Vitest } from '../node/core'
|
||||||
import { TestModule as _TestFile } from '../node/reporters/reported-tasks'
|
|
||||||
|
|
||||||
export const version: string = Vitest.version
|
export const version: string = Vitest.version
|
||||||
|
|
||||||
@ -80,8 +78,6 @@ export type {
|
|||||||
ProjectBrowser,
|
ProjectBrowser,
|
||||||
ResolvedBrowserOptions,
|
ResolvedBrowserOptions,
|
||||||
} from '../node/types/browser'
|
} from '../node/types/browser'
|
||||||
/** @deprecated use `createViteServer` instead */
|
|
||||||
export const createServer: typeof vite.createServer = vite.createServer
|
|
||||||
export const createViteServer: typeof vite.createServer = vite.createServer
|
export const createViteServer: typeof vite.createServer = vite.createServer
|
||||||
export type {
|
export type {
|
||||||
ApiConfig,
|
ApiConfig,
|
||||||
@ -89,9 +85,7 @@ export type {
|
|||||||
CSSModuleScopeStrategy,
|
CSSModuleScopeStrategy,
|
||||||
DepsOptimizationOptions,
|
DepsOptimizationOptions,
|
||||||
EnvironmentOptions,
|
EnvironmentOptions,
|
||||||
HappyDOMOptions,
|
|
||||||
InlineConfig,
|
InlineConfig,
|
||||||
JSDOMOptions,
|
|
||||||
Pool,
|
Pool,
|
||||||
PoolOptions,
|
PoolOptions,
|
||||||
ProjectConfig,
|
ProjectConfig,
|
||||||
@ -102,9 +96,9 @@ export type {
|
|||||||
RuntimeConfig,
|
RuntimeConfig,
|
||||||
SequenceHooks,
|
SequenceHooks,
|
||||||
SequenceSetupFiles,
|
SequenceSetupFiles,
|
||||||
|
UserConfig as TestUserConfig,
|
||||||
TransformModePatterns,
|
TransformModePatterns,
|
||||||
TypecheckConfig,
|
TypecheckConfig,
|
||||||
UserConfig,
|
|
||||||
UserWorkspaceConfig,
|
UserWorkspaceConfig,
|
||||||
VitestEnvironment,
|
VitestEnvironment,
|
||||||
VitestRunMode,
|
VitestRunMode,
|
||||||
@ -124,19 +118,10 @@ export type {
|
|||||||
|
|
||||||
export type { VitestPluginContext } from '../node/types/plugin'
|
export type { VitestPluginContext } from '../node/types/plugin'
|
||||||
export type { TestRunResult } from '../node/types/tests'
|
export type { TestRunResult } from '../node/types/tests'
|
||||||
/**
|
|
||||||
* @deprecated Use `TestModule` instead
|
|
||||||
*/
|
|
||||||
export const TestFile: typeof _TestFile = _TestFile
|
|
||||||
export type { WorkerContext } from '../node/types/worker'
|
export type { WorkerContext } from '../node/types/worker'
|
||||||
export { createViteLogger } from '../node/viteLogger'
|
export { createViteLogger } from '../node/viteLogger'
|
||||||
export type { WatcherTriggerPattern } from '../node/watcher'
|
export type { WatcherTriggerPattern } from '../node/watcher'
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use `ModuleDiagnostic` instead
|
|
||||||
*/
|
|
||||||
export type FileDiagnostic = _FileDiagnostic
|
|
||||||
|
|
||||||
export { distDir, rootDir } from '../paths'
|
export { distDir, rootDir } from '../paths'
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import type { FakeTimerInstallOpts } from '@sinonjs/fake-timers'
|
import type { FakeTimerInstallOpts } from '@sinonjs/fake-timers'
|
||||||
import type { PrettyFormatOptions } from '@vitest/pretty-format'
|
import type { PrettyFormatOptions } from '@vitest/pretty-format'
|
||||||
import type { SequenceHooks, SequenceSetupFiles } from '@vitest/runner'
|
import type { SequenceHooks, SequenceSetupFiles } from '@vitest/runner'
|
||||||
import type { SnapshotUpdateState } from '@vitest/snapshot'
|
import type { SnapshotEnvironment, SnapshotUpdateState } from '@vitest/snapshot'
|
||||||
import type { SnapshotEnvironment } from '@vitest/snapshot/environment'
|
|
||||||
import type { SerializedDiffOptions } from '@vitest/utils/diff'
|
import type { SerializedDiffOptions } from '@vitest/utils/diff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -152,7 +152,7 @@ export async function startVitestExecutor(options: ContextExecutorOptions): Prom
|
|||||||
return rpc().resolveId(id, importer, getTransformMode())
|
return rpc().resolveId(id, importer, getTransformMode())
|
||||||
},
|
},
|
||||||
get moduleCache() {
|
get moduleCache() {
|
||||||
return state().moduleCache
|
return state().moduleCache as ModuleCacheMap
|
||||||
},
|
},
|
||||||
get moduleExecutionInfo() {
|
get moduleExecutionInfo() {
|
||||||
return state().moduleExecutionInfo
|
return state().moduleExecutionInfo
|
||||||
|
|||||||
@ -22,10 +22,15 @@ function withSafeTimers(fn: () => void) {
|
|||||||
try {
|
try {
|
||||||
globalThis.setTimeout = setTimeout
|
globalThis.setTimeout = setTimeout
|
||||||
globalThis.clearTimeout = clearTimeout
|
globalThis.clearTimeout = clearTimeout
|
||||||
globalThis.setImmediate = setImmediate
|
|
||||||
globalThis.clearImmediate = clearImmediate
|
|
||||||
|
|
||||||
if (globalThis.process) {
|
if (setImmediate) {
|
||||||
|
globalThis.setImmediate = setImmediate
|
||||||
|
}
|
||||||
|
if (clearImmediate) {
|
||||||
|
globalThis.clearImmediate = clearImmediate
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalThis.process && nextTick) {
|
||||||
globalThis.process.nextTick = nextTick
|
globalThis.process.nextTick = nextTick
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +43,7 @@ function withSafeTimers(fn: () => void) {
|
|||||||
globalThis.setImmediate = currentSetImmediate
|
globalThis.setImmediate = currentSetImmediate
|
||||||
globalThis.clearImmediate = currentClearImmediate
|
globalThis.clearImmediate = currentClearImmediate
|
||||||
|
|
||||||
if (globalThis.process) {
|
if (globalThis.process && nextTick) {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
globalThis.process.nextTick = currentNextTick
|
globalThis.process.nextTick = currentNextTick
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { FileSpecification } from '@vitest/runner'
|
import type { FileSpecification } from '@vitest/runner'
|
||||||
|
import type { ModuleCacheMap } from 'vite-node'
|
||||||
import type { ResolvedTestEnvironment } from '../types/environment'
|
import type { ResolvedTestEnvironment } from '../types/environment'
|
||||||
import type { SerializedConfig } from './config'
|
import type { SerializedConfig } from './config'
|
||||||
import type { VitestExecutor } from './execute'
|
import type { VitestExecutor } from './execute'
|
||||||
@ -56,7 +57,7 @@ export async function run(
|
|||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (isolate) {
|
if (isolate) {
|
||||||
executor.mocker.reset()
|
executor.mocker.reset()
|
||||||
resetModules(workerState.moduleCache, true)
|
resetModules(workerState.moduleCache as ModuleCacheMap, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
workerState.filepath = file.filepath
|
workerState.filepath = file.filepath
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { FileSpecification } from '@vitest/runner'
|
import type { FileSpecification } from '@vitest/runner'
|
||||||
|
import type { ModuleCacheMap } from 'vite-node'
|
||||||
import type { SerializedConfig } from './config'
|
import type { SerializedConfig } from './config'
|
||||||
import type { VitestExecutor } from './execute'
|
import type { VitestExecutor } from './execute'
|
||||||
import { createRequire } from 'node:module'
|
import { createRequire } from 'node:module'
|
||||||
@ -61,7 +62,7 @@ export async function run(
|
|||||||
}
|
}
|
||||||
|
|
||||||
installSourcemapsSupport({
|
installSourcemapsSupport({
|
||||||
getSourceMap: source => workerState.moduleCache.getSourceMap(source),
|
getSourceMap: source => (workerState.moduleCache as ModuleCacheMap).getSourceMap(source),
|
||||||
})
|
})
|
||||||
|
|
||||||
await startCoverageInsideWorker(config.coverage, executor, { isolate: false })
|
await startCoverageInsideWorker(config.coverage, executor, { isolate: false })
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import type {
|
|||||||
VitestRunnerImportSource,
|
VitestRunnerImportSource,
|
||||||
} from '@vitest/runner'
|
} from '@vitest/runner'
|
||||||
import type { SerializedConfig } from '../config'
|
import type { SerializedConfig } from '../config'
|
||||||
import type { VitestExecutor } from '../execute'
|
// import type { VitestExecutor } from '../execute'
|
||||||
import type {
|
import type {
|
||||||
Benchmark,
|
Benchmark,
|
||||||
BenchmarkResult,
|
BenchmarkResult,
|
||||||
@ -150,7 +150,7 @@ async function runBenchmarkSuite(suite: Suite, runner: NodeBenchmarkRunner) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class NodeBenchmarkRunner implements VitestRunner {
|
export class NodeBenchmarkRunner implements VitestRunner {
|
||||||
private __vitest_executor!: VitestExecutor
|
private __vitest_executor!: any
|
||||||
|
|
||||||
constructor(public config: SerializedConfig) {}
|
constructor(public config: SerializedConfig) {}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import type {
|
|||||||
VitestRunnerImportSource,
|
VitestRunnerImportSource,
|
||||||
} from '@vitest/runner'
|
} from '@vitest/runner'
|
||||||
import type { SerializedConfig } from '../config'
|
import type { SerializedConfig } from '../config'
|
||||||
import type { VitestExecutor } from '../execute'
|
// import type { VitestExecutor } from '../execute'
|
||||||
import { getState, GLOBAL_EXPECT, setState } from '@vitest/expect'
|
import { getState, GLOBAL_EXPECT, setState } from '@vitest/expect'
|
||||||
import { getNames, getTestName, getTests } from '@vitest/runner/utils'
|
import { getNames, getTestName, getTests } from '@vitest/runner/utils'
|
||||||
import { normalize } from 'pathe'
|
import { normalize } from 'pathe'
|
||||||
@ -28,7 +28,7 @@ const workerContext = Object.create(null)
|
|||||||
export class VitestTestRunner implements VitestRunner {
|
export class VitestTestRunner implements VitestRunner {
|
||||||
private snapshotClient = getSnapshotClient()
|
private snapshotClient = getSnapshotClient()
|
||||||
private workerState = getWorkerState()
|
private workerState = getWorkerState()
|
||||||
private __vitest_executor!: VitestExecutor
|
private __vitest_executor!: any
|
||||||
private cancelRun = false
|
private cancelRun = false
|
||||||
|
|
||||||
private assertionsErrors = new WeakMap<Readonly<Task>, Error>()
|
private assertionsErrors = new WeakMap<Readonly<Task>, Error>()
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import type { ModuleCacheMap } from 'vite-node'
|
||||||
import type { ResolvedTestEnvironment } from '../types/environment'
|
import type { ResolvedTestEnvironment } from '../types/environment'
|
||||||
import type { SerializedConfig } from './config'
|
import type { SerializedConfig } from './config'
|
||||||
import type { VitestExecutor } from './execute'
|
import type { VitestExecutor } from './execute'
|
||||||
@ -66,7 +67,7 @@ export async function setupGlobalEnv(
|
|||||||
}
|
}
|
||||||
|
|
||||||
installSourcemapsSupport({
|
installSourcemapsSupport({
|
||||||
getSourceMap: source => state.moduleCache.getSourceMap(source),
|
getSourceMap: source => (state.moduleCache as ModuleCacheMap).getSourceMap(source),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!config.disableConsoleIntercept) {
|
if (!config.disableConsoleIntercept) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { Context } from 'node:vm'
|
import type { Context } from 'node:vm'
|
||||||
|
import type { ModuleCacheMap } from 'vite-node'
|
||||||
import type { WorkerGlobalState } from '../../types/worker'
|
import type { WorkerGlobalState } from '../../types/worker'
|
||||||
import { pathToFileURL } from 'node:url'
|
import { pathToFileURL } from 'node:url'
|
||||||
import { isContext } from 'node:vm'
|
import { isContext } from 'node:vm'
|
||||||
@ -76,7 +77,7 @@ export async function runVmTests(method: 'run' | 'collect', state: WorkerGlobalS
|
|||||||
|
|
||||||
const executor = await startVitestExecutor({
|
const executor = await startVitestExecutor({
|
||||||
context,
|
context,
|
||||||
moduleCache: state.moduleCache,
|
moduleCache: state.moduleCache as ModuleCacheMap,
|
||||||
state,
|
state,
|
||||||
externalModulesExecutor,
|
externalModulesExecutor,
|
||||||
requestStubs: stubs,
|
requestStubs: stubs,
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import type { Awaitable } from './general'
|
import type { Awaitable } from './general'
|
||||||
import type { HappyDOMOptions } from './happy-dom-options'
|
|
||||||
import type { JSDOMOptions } from './jsdom-options'
|
|
||||||
|
|
||||||
export interface EnvironmentReturn {
|
export interface EnvironmentReturn {
|
||||||
teardown: (global: any) => Awaitable<void>
|
teardown: (global: any) => Awaitable<void>
|
||||||
@ -21,15 +19,6 @@ export interface Environment {
|
|||||||
) => Awaitable<EnvironmentReturn>
|
) => Awaitable<EnvironmentReturn>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EnvironmentOptions {
|
|
||||||
/**
|
|
||||||
* jsdom options.
|
|
||||||
*/
|
|
||||||
jsdom?: JSDOMOptions
|
|
||||||
happyDOM?: HappyDOMOptions
|
|
||||||
[x: string]: unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ResolvedTestEnvironment {
|
export interface ResolvedTestEnvironment {
|
||||||
environment: Environment
|
environment: Environment
|
||||||
options: Record<string, any> | null
|
options: Record<string, any> | null
|
||||||
|
|||||||
@ -5,23 +5,8 @@ export type Nullable<T> = T | null | undefined
|
|||||||
export type Arrayable<T> = T | Array<T>
|
export type Arrayable<T> = T | Array<T>
|
||||||
export type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never
|
export type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never
|
||||||
|
|
||||||
export type MutableArray<T extends readonly any[]> = {
|
|
||||||
-readonly [k in keyof T]: T[k];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Constructable {
|
|
||||||
new (...args: any[]): any
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TransformMode = 'web' | 'ssr'
|
export type TransformMode = 'web' | 'ssr'
|
||||||
|
|
||||||
/** @deprecated not used */
|
|
||||||
export interface ModuleCache {
|
|
||||||
promise?: Promise<any>
|
|
||||||
exports?: any
|
|
||||||
code?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AfterSuiteRunMeta {
|
export interface AfterSuiteRunMeta {
|
||||||
coverage?: unknown
|
coverage?: unknown
|
||||||
testFiles: string[]
|
testFiles: string[]
|
||||||
|
|||||||
@ -1,17 +1,10 @@
|
|||||||
import type { CancelReason, FileSpecification, Task } from '@vitest/runner'
|
import type { CancelReason, FileSpecification, Task } from '@vitest/runner'
|
||||||
import type { BirpcReturn } from 'birpc'
|
import type { BirpcReturn } from 'birpc'
|
||||||
import type { ModuleCacheMap, ModuleExecutionInfo, ViteNodeResolveId } from 'vite-node'
|
|
||||||
import type { SerializedConfig } from '../runtime/config'
|
import type { SerializedConfig } from '../runtime/config'
|
||||||
import type { Environment } from './environment'
|
import type { Environment } from './environment'
|
||||||
import type { TransformMode } from './general'
|
import type { TransformMode } from './general'
|
||||||
import type { RunnerRPC, RuntimeRPC } from './rpc'
|
import type { RunnerRPC, RuntimeRPC } from './rpc'
|
||||||
|
|
||||||
/** @deprecated unused */
|
|
||||||
export type ResolveIdFunction = (
|
|
||||||
id: string,
|
|
||||||
importer?: string
|
|
||||||
) => Promise<ViteNodeResolveId | null>
|
|
||||||
|
|
||||||
export type WorkerRPC = BirpcReturn<RuntimeRPC, RunnerRPC>
|
export type WorkerRPC = BirpcReturn<RuntimeRPC, RunnerRPC>
|
||||||
|
|
||||||
export interface ContextTestEnvironment {
|
export interface ContextTestEnvironment {
|
||||||
@ -43,8 +36,8 @@ export interface WorkerGlobalState {
|
|||||||
environment: Environment
|
environment: Environment
|
||||||
environmentTeardownRun?: boolean
|
environmentTeardownRun?: boolean
|
||||||
onCancel: Promise<CancelReason>
|
onCancel: Promise<CancelReason>
|
||||||
moduleCache: ModuleCacheMap
|
moduleCache: Map<string, any>
|
||||||
moduleExecutionInfo?: ModuleExecutionInfo
|
moduleExecutionInfo: Map<string, any>
|
||||||
onCleanup: (listener: () => unknown) => void
|
onCleanup: (listener: () => unknown) => void
|
||||||
providedContext: Record<string, any>
|
providedContext: Record<string, any>
|
||||||
durations: {
|
durations: {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["ESNext", "WebWorker"],
|
"lib": ["ESNext", "WebWorker", "DOM"],
|
||||||
"isolatedDeclarations": true
|
"isolatedDeclarations": true
|
||||||
},
|
},
|
||||||
"exclude": ["./dist"]
|
"exclude": ["./dist"]
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"lib": ["DOM"],
|
||||||
"isolatedDeclarations": true
|
"isolatedDeclarations": true
|
||||||
},
|
},
|
||||||
"exclude": ["./dist"]
|
"exclude": ["./dist"]
|
||||||
|
|||||||
49
scripts/explain-types.ts
Normal file
49
scripts/explain-types.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
|
||||||
|
// { dep: ['dep2'], dep2: [] }
|
||||||
|
const dependencies: Record<string, string[]> = {}
|
||||||
|
const content = readFileSync(process.argv[2], 'utf-8').split('\n')
|
||||||
|
|
||||||
|
let lastKey = content[0]
|
||||||
|
for (let i = 1; i < content.length; i++) {
|
||||||
|
const line = content[i]
|
||||||
|
if (line.startsWith(' ')) {
|
||||||
|
const line = content[i].trim()
|
||||||
|
if (!line.startsWith('Imported via')) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const [_, __, from] = (line.includes('with')
|
||||||
|
? /Imported via '(.*)' from file '(.*)' with/.exec(line)
|
||||||
|
: /Imported via '(.*)' from file '(.*)'/.exec(line)) ?? []
|
||||||
|
|
||||||
|
dependencies[from] ??= []
|
||||||
|
if (!dependencies[from].includes(lastKey)) {
|
||||||
|
dependencies[from].push(lastKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lastKey = content[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function printTree(start: string, deps: string[], depth = 1, seen = new Set()) {
|
||||||
|
for (const dep of deps) {
|
||||||
|
if (seen.has(dep)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen.add(dep)
|
||||||
|
console.error(' '.repeat(depth) + dep)
|
||||||
|
const deps = dependencies[dep]
|
||||||
|
if (deps && !dep.includes('node_modules')) {
|
||||||
|
printTree(start, deps, depth + 1, seen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in dependencies) {
|
||||||
|
if (key.startsWith('src/client')) {
|
||||||
|
console.error(key)
|
||||||
|
printTree(key, dependencies[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import type { UserConfig } from 'vitest'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { resolve } from 'node:path'
|
import { resolve } from 'node:path'
|
||||||
import { describe, expect, test } from 'vitest'
|
import { describe, expect, test } from 'vitest'
|
||||||
import { getCurrentTest } from 'vitest/suite'
|
import { getCurrentTest } from 'vitest/suite'
|
||||||
import { runVitest } from '../../test-utils'
|
import { runVitest } from '../../test-utils'
|
||||||
|
|
||||||
describe('expect.soft', () => {
|
describe('expect.soft', () => {
|
||||||
const run = (config?: UserConfig) => runVitest({
|
const run = (config?: TestUserConfig) => runVitest({
|
||||||
root: resolve('./fixtures/expect-soft'),
|
root: resolve('./fixtures/expect-soft'),
|
||||||
include: ['expects/soft.test.ts'],
|
include: ['expects/soft.test.ts'],
|
||||||
setupFiles: [],
|
setupFiles: [],
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { RunnerTaskResultPack, RunnerTestFile } from 'vitest'
|
import type { RunnerTaskResultPack, RunnerTestFile } from 'vitest'
|
||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { expect, it } from 'vitest'
|
import { expect, it } from 'vitest'
|
||||||
import { rolldownVersion } from 'vitest/node'
|
import { rolldownVersion } from 'vitest/node'
|
||||||
@ -14,7 +14,7 @@ it.each([
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] as UserConfig[])('passes down metadata when $name', { timeout: 60_000, retry: 1 }, async (config) => {
|
] as TestUserConfig[])('passes down metadata when $name', { timeout: 60_000, retry: 1 }, async (config) => {
|
||||||
const taskUpdate: RunnerTaskResultPack[] = []
|
const taskUpdate: RunnerTaskResultPack[] = []
|
||||||
const finishedFiles: RunnerTestFile[] = []
|
const finishedFiles: RunnerTestFile[] = []
|
||||||
const collectedFiles: RunnerTestFile[] = []
|
const collectedFiles: RunnerTestFile[] = []
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import type { TestAPI } from 'vitest'
|
import type { TestAPI } from 'vitest'
|
||||||
import type { ViteUserConfig } from 'vitest/config'
|
import type { ViteUserConfig } from 'vitest/config'
|
||||||
import type { TestSpecification, UserConfig } from 'vitest/node'
|
import type { TestSpecification, TestUserConfig } from 'vitest/node'
|
||||||
import type { TestFsStructure } from '../../test-utils'
|
import type { TestFsStructure } from '../../test-utils'
|
||||||
import { runInlineTests } from '../../test-utils'
|
import { runInlineTests } from '../../test-utils'
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ describe('browser tests', () => {
|
|||||||
async function runFixtureTests<T>(
|
async function runFixtureTests<T>(
|
||||||
extendedTest: ({ log }: { log: typeof console.log }) => TestAPI<T>,
|
extendedTest: ({ log }: { log: typeof console.log }) => TestAPI<T>,
|
||||||
fs: Record<string, ((context: { extendedTest: TestAPI<T> }) => unknown) | ViteUserConfig>,
|
fs: Record<string, ((context: { extendedTest: TestAPI<T> }) => unknown) | ViteUserConfig>,
|
||||||
config?: UserConfig,
|
config?: TestUserConfig,
|
||||||
) {
|
) {
|
||||||
if (typeof fs['vitest.config.js'] === 'object') {
|
if (typeof fs['vitest.config.js'] === 'object') {
|
||||||
fs['vitest.config.js'].test!.globals = true
|
fs['vitest.config.js'].test!.globals = true
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
|
|
||||||
import { expect, test } from 'vitest'
|
import { expect, test } from 'vitest'
|
||||||
import { runVitest } from '../../test-utils'
|
import { runVitest } from '../../test-utils'
|
||||||
|
|
||||||
const configs: UserConfig[] = []
|
const configs: TestUserConfig[] = []
|
||||||
const pools: UserConfig[] = [
|
const pools: TestUserConfig[] = [
|
||||||
{ pool: 'threads' },
|
{ pool: 'threads' },
|
||||||
{ pool: 'forks' },
|
{ pool: 'forks' },
|
||||||
{ pool: 'threads', poolOptions: { threads: { singleThread: true } } },
|
{ pool: 'threads', poolOptions: { threads: { singleThread: true } } },
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { ViteUserConfig } from 'vitest/config'
|
import type { ViteUserConfig } from 'vitest/config'
|
||||||
import type { UserConfig, VitestOptions } from 'vitest/node'
|
import type { TestUserConfig, VitestOptions } from 'vitest/node'
|
||||||
import type { TestFsStructure } from '../../test-utils'
|
import type { TestFsStructure } from '../../test-utils'
|
||||||
import crypto from 'node:crypto'
|
import crypto from 'node:crypto'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
@ -7,7 +7,7 @@ import { describe, expect, onTestFinished, test } from 'vitest'
|
|||||||
import { createVitest } from 'vitest/node'
|
import { createVitest } from 'vitest/node'
|
||||||
import { runVitestCli, useFS } from '../../test-utils'
|
import { runVitestCli, useFS } from '../../test-utils'
|
||||||
|
|
||||||
async function vitest(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
async function vitest(cliOptions: TestUserConfig, configValue: TestUserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
||||||
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
||||||
onTestFinished(() => vitest.close())
|
onTestFinished(() => vitest.close())
|
||||||
return vitest
|
return vitest
|
||||||
@ -308,7 +308,7 @@ test('can enable browser-cli options for multi-project workspace', async () => {
|
|||||||
expect(projects[1].config.browser.headless).toBe(true)
|
expect(projects[1].config.browser.headless).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
function getCliConfig(options: UserConfig, cli: string[], fs: TestFsStructure = {}) {
|
function getCliConfig(options: TestUserConfig, cli: string[], fs: TestFsStructure = {}) {
|
||||||
const root = resolve(process.cwd(), `vitest-test-${crypto.randomUUID()}`)
|
const root = resolve(process.cwd(), `vitest-test-${crypto.randomUUID()}`)
|
||||||
useFS(root, {
|
useFS(root, {
|
||||||
...fs,
|
...fs,
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import type { ViteUserConfig } from 'vitest/config'
|
import type { ViteUserConfig } from 'vitest/config'
|
||||||
import type { TestProject, UserConfig, VitestOptions } from 'vitest/node'
|
import type { TestProject, TestUserConfig, VitestOptions } from 'vitest/node'
|
||||||
import { expect, onTestFinished, test } from 'vitest'
|
import { expect, onTestFinished, test } from 'vitest'
|
||||||
import { createVitest } from 'vitest/node'
|
import { createVitest } from 'vitest/node'
|
||||||
|
|
||||||
async function vitest(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
async function vitest(cliOptions: TestUserConfig, configValue: TestUserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
||||||
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
||||||
onTestFinished(() => vitest.close())
|
onTestFinished(() => vitest.close())
|
||||||
return vitest
|
return vitest
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { UserConfig as ViteUserConfig } from 'vite'
|
import type { UserConfig as ViteUserConfig } from 'vite'
|
||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import type { VitestRunnerCLIOptions } from '../../test-utils'
|
import type { VitestRunnerCLIOptions } from '../../test-utils'
|
||||||
import { cpus } from 'node:os'
|
import { cpus } from 'node:os'
|
||||||
import { normalize, resolve } from 'pathe'
|
import { normalize, resolve } from 'pathe'
|
||||||
@ -11,7 +11,7 @@ const providers = ['playwright', 'webdriverio', 'preview'] as const
|
|||||||
const names = ['edge', 'chromium', 'webkit', 'chrome', 'firefox', 'safari'] as const
|
const names = ['edge', 'chromium', 'webkit', 'chrome', 'firefox', 'safari'] as const
|
||||||
const browsers = providers.map(provider => names.map(name => ({ name, provider }))).flat()
|
const browsers = providers.map(provider => names.map(name => ({ name, provider }))).flat()
|
||||||
|
|
||||||
function runVitest(config: NonNullable<UserConfig> & { shard?: any }, viteOverrides: ViteUserConfig = {}, runnerOptions?: VitestRunnerCLIOptions) {
|
function runVitest(config: NonNullable<TestUserConfig> & { shard?: any }, viteOverrides: ViteUserConfig = {}, runnerOptions?: VitestRunnerCLIOptions) {
|
||||||
return testUtils.runVitest({ root: './fixtures/test', include: ['example.test.ts'], ...config }, [], undefined, viteOverrides, runnerOptions)
|
return testUtils.runVitest({ root: './fixtures/test', include: ['example.test.ts'], ...config }, [], undefined, viteOverrides, runnerOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { expect, test } from 'vitest'
|
import { expect, test } from 'vitest'
|
||||||
import { runVitest } from '../../test-utils'
|
import { runVitest } from '../../test-utils'
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ test.for([
|
|||||||
{ isolate: false, minWorkers: 1, maxWorkers: 1 },
|
{ isolate: false, minWorkers: 1, maxWorkers: 1 },
|
||||||
{ isolate: false, fileParallelism: false },
|
{ isolate: false, fileParallelism: false },
|
||||||
{ isolate: false, poolOptions: { forks: { singleFork: true } } },
|
{ isolate: false, poolOptions: { forks: { singleFork: true } } },
|
||||||
] satisfies UserConfig[])(`getState().testPath during collection %s`, async (config) => {
|
] satisfies TestUserConfig[])(`getState().testPath during collection %s`, async (config) => {
|
||||||
const result = await runVitest({
|
const result = await runVitest({
|
||||||
root: './fixtures/get-state',
|
root: './fixtures/get-state',
|
||||||
...config,
|
...config,
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { expect, test } from 'vitest'
|
import { expect, test } from 'vitest'
|
||||||
|
|
||||||
import { runVitest } from '../../test-utils'
|
import { runVitest } from '../../test-utils'
|
||||||
|
|
||||||
const configs: UserConfig[] = [
|
const configs: TestUserConfig[] = [
|
||||||
{ pool: 'threads', poolOptions: { threads: { isolate: false, singleThread: true } } },
|
{ pool: 'threads', poolOptions: { threads: { isolate: false, singleThread: true } } },
|
||||||
{ pool: 'threads', poolOptions: { threads: { isolate: false, singleThread: false } } },
|
{ pool: 'threads', poolOptions: { threads: { isolate: false, singleThread: false } } },
|
||||||
{ pool: 'threads', poolOptions: { threads: { isolate: false, minThreads: 1, maxThreads: 1 } } },
|
{ pool: 'threads', poolOptions: { threads: { isolate: false, minThreads: 1, maxThreads: 1 } } },
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
import type { UserConfig as ViteUserConfig } from 'vite'
|
import type { UserConfig as ViteUserConfig } from 'vite'
|
||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { describe, expect, it, onTestFinished } from 'vitest'
|
import { describe, expect, it, onTestFinished } from 'vitest'
|
||||||
import { extraInlineDeps } from 'vitest/config'
|
import { extraInlineDeps } from 'vitest/config'
|
||||||
import { createVitest, parseCLI } from 'vitest/node'
|
import { createVitest, parseCLI } from 'vitest/node'
|
||||||
|
|
||||||
type VitestOptions = Parameters<typeof createVitest>[3]
|
type VitestOptions = Parameters<typeof createVitest>[3]
|
||||||
|
|
||||||
async function vitest(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
async function vitest(cliOptions: TestUserConfig, configValue: TestUserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
||||||
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }, vitestOptions)
|
||||||
onTestFinished(() => vitest.close())
|
onTestFinished(() => vitest.close())
|
||||||
return vitest
|
return vitest
|
||||||
}
|
}
|
||||||
|
|
||||||
async function config(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
async function config(cliOptions: TestUserConfig, configValue: TestUserConfig = {}, viteConfig: ViteUserConfig = {}, vitestOptions: VitestOptions = {}) {
|
||||||
const v = await vitest(cliOptions, configValue, viteConfig, vitestOptions)
|
const v = await vitest(cliOptions, configValue, viteConfig, vitestOptions)
|
||||||
return v.config
|
return v.config
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { basename } from 'pathe'
|
import { basename } from 'pathe'
|
||||||
|
|
||||||
import { expect, test } from 'vitest'
|
import { expect, test } from 'vitest'
|
||||||
import * as testUtils from '../../test-utils'
|
import * as testUtils from '../../test-utils'
|
||||||
|
|
||||||
function runVitest(config: UserConfig) {
|
function runVitest(config: TestUserConfig) {
|
||||||
return testUtils.runVitest({ ...config, root: './fixtures/shard' })
|
return testUtils.runVitest({ ...config, root: './fixtures/shard' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { describe, expect, test, vi } from 'vitest'
|
import { describe, expect, test, vi } from 'vitest'
|
||||||
|
|
||||||
import { getWorkersCountByPercentage } from 'vitest/src/utils/workers.js'
|
import { getWorkersCountByPercentage } from 'vitest/src/utils/workers.js'
|
||||||
@ -26,7 +26,7 @@ describe('workers util', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function runVitest(config: UserConfig) {
|
function runVitest(config: TestUserConfig) {
|
||||||
return testUtils.runVitest({ ...config, root: './fixtures/workers-option' })
|
return testUtils.runVitest({ ...config, root: './fixtures/workers-option' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,13 +88,11 @@ it('exports snapshot', async ({ skip, task }) => {
|
|||||||
"./node": {
|
"./node": {
|
||||||
"BaseSequencer": "function",
|
"BaseSequencer": "function",
|
||||||
"GitNotFoundError": "function",
|
"GitNotFoundError": "function",
|
||||||
"TestFile": "function",
|
|
||||||
"TestsNotFoundError": "function",
|
"TestsNotFoundError": "function",
|
||||||
"VitestPackageInstaller": "function",
|
"VitestPackageInstaller": "function",
|
||||||
"VitestPlugin": "function",
|
"VitestPlugin": "function",
|
||||||
"createDebugger": "function",
|
"createDebugger": "function",
|
||||||
"createMethodsRPC": "function",
|
"createMethodsRPC": "function",
|
||||||
"createServer": "function",
|
|
||||||
"createViteLogger": "function",
|
"createViteLogger": "function",
|
||||||
"createViteServer": "function",
|
"createViteServer": "function",
|
||||||
"createVitest": "function",
|
"createVitest": "function",
|
||||||
@ -243,13 +241,11 @@ it('exports snapshot', async ({ skip, task }) => {
|
|||||||
"./node": {
|
"./node": {
|
||||||
"BaseSequencer": "function",
|
"BaseSequencer": "function",
|
||||||
"GitNotFoundError": "function",
|
"GitNotFoundError": "function",
|
||||||
"TestFile": "function",
|
|
||||||
"TestsNotFoundError": "function",
|
"TestsNotFoundError": "function",
|
||||||
"VitestPackageInstaller": "function",
|
"VitestPackageInstaller": "function",
|
||||||
"VitestPlugin": "function",
|
"VitestPlugin": "function",
|
||||||
"createDebugger": "function",
|
"createDebugger": "function",
|
||||||
"createMethodsRPC": "function",
|
"createMethodsRPC": "function",
|
||||||
"createServer": "function",
|
|
||||||
"createViteLogger": "function",
|
"createViteLogger": "function",
|
||||||
"createViteServer": "function",
|
"createViteServer": "function",
|
||||||
"createVitest": "function",
|
"createVitest": "function",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { CoverageSummary, FileCoverageData } from 'istanbul-lib-coverage'
|
import type { CoverageSummary, FileCoverageData } from 'istanbul-lib-coverage'
|
||||||
import type { TestFunction } from 'vitest'
|
import type { TestFunction } from 'vitest'
|
||||||
import type { UserConfig } from 'vitest/node'
|
import type { TestUserConfig } from 'vitest/node'
|
||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import { resolve } from 'node:path'
|
import { resolve } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
@ -28,7 +28,7 @@ export function coverageTest(name: string, fn: TestFunction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runVitest(config: UserConfig, options = { throwOnError: true }) {
|
export async function runVitest(config: TestUserConfig, options = { throwOnError: true }) {
|
||||||
const provider = process.env.COVERAGE_PROVIDER as any
|
const provider = process.env.COVERAGE_PROVIDER as any
|
||||||
|
|
||||||
const result = await testUtils.runVitest({
|
const result = await testUtils.runVitest({
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { Reporter, Vitest } from 'vitest'
|
import type { Reporter, Vitest } from 'vitest/node'
|
||||||
|
|
||||||
export default class TestReporter implements Reporter {
|
export default class TestReporter implements Reporter {
|
||||||
ctx!: Vitest
|
ctx!: Vitest
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import type {
|
|||||||
TestRunEndReason,
|
TestRunEndReason,
|
||||||
TestSpecification,
|
TestSpecification,
|
||||||
TestSuite,
|
TestSuite,
|
||||||
UserConfig,
|
TestUserConfig,
|
||||||
Vitest,
|
Vitest,
|
||||||
} from 'vitest/node'
|
} from 'vitest/node'
|
||||||
import { rmSync } from 'node:fs'
|
import { rmSync } from 'node:fs'
|
||||||
@ -1110,12 +1110,12 @@ interface ReporterOptions {
|
|||||||
|
|
||||||
async function run(
|
async function run(
|
||||||
structure: Parameters<typeof runInlineTests>[0],
|
structure: Parameters<typeof runInlineTests>[0],
|
||||||
customConfig?: UserConfig,
|
customConfig?: TestUserConfig,
|
||||||
reporterOptions?: ReporterOptions,
|
reporterOptions?: ReporterOptions,
|
||||||
) {
|
) {
|
||||||
const reporter = new CustomReporter(reporterOptions)
|
const reporter = new CustomReporter(reporterOptions)
|
||||||
|
|
||||||
const config: UserConfig = {
|
const config: TestUserConfig = {
|
||||||
config: false,
|
config: false,
|
||||||
fileParallelism: false,
|
fileParallelism: false,
|
||||||
globals: true,
|
globals: true,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { ViteNodeRunner } from 'vite-node/client'
|
import type { ViteNodeRunner } from 'vite-node/client'
|
||||||
import type { Vitest } from 'vitest'
|
import type { Vitest } from 'vitest/node'
|
||||||
/**
|
/**
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { Options } from 'tinyexec'
|
|||||||
import type { UserConfig as ViteUserConfig } from 'vite'
|
import type { UserConfig as ViteUserConfig } from 'vite'
|
||||||
import type { WorkerGlobalState } from 'vitest'
|
import type { WorkerGlobalState } from 'vitest'
|
||||||
import type { TestProjectConfiguration } from 'vitest/config'
|
import type { TestProjectConfiguration } from 'vitest/config'
|
||||||
import type { TestModule, UserConfig, Vitest, VitestRunMode } from 'vitest/node'
|
import type { TestModule, TestUserConfig, Vitest, VitestRunMode } from 'vitest/node'
|
||||||
import { webcrypto as crypto } from 'node:crypto'
|
import { webcrypto as crypto } from 'node:crypto'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { Readable, Writable } from 'node:stream'
|
import { Readable, Writable } from 'node:stream'
|
||||||
@ -29,7 +29,7 @@ export interface VitestRunnerCLIOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runVitest(
|
export async function runVitest(
|
||||||
cliOptions: UserConfig,
|
cliOptions: TestUserConfig,
|
||||||
cliFilters: string[] = [],
|
cliFilters: string[] = [],
|
||||||
mode: VitestRunMode = 'test',
|
mode: VitestRunMode = 'test',
|
||||||
viteOverrides: ViteUserConfig = {},
|
viteOverrides: ViteUserConfig = {},
|
||||||
@ -342,7 +342,7 @@ export function useFS<T extends TestFsStructure>(root: string, structure: T) {
|
|||||||
|
|
||||||
export async function runInlineTests(
|
export async function runInlineTests(
|
||||||
structure: TestFsStructure,
|
structure: TestFsStructure,
|
||||||
config?: UserConfig,
|
config?: TestUserConfig,
|
||||||
options?: VitestRunnerCLIOptions,
|
options?: VitestRunnerCLIOptions,
|
||||||
viteOverrides: ViteUserConfig = {},
|
viteOverrides: ViteUserConfig = {},
|
||||||
) {
|
) {
|
||||||
|
|||||||
5
test/typescript/failing/node-types.test-d.ts
Normal file
5
test/typescript/failing/node-types.test-d.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { test } from 'vitest'
|
||||||
|
|
||||||
|
test('buffer is not available', () => {
|
||||||
|
Buffer.from([])
|
||||||
|
})
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
exports[`should fail > typecheck files 1`] = `
|
exports[`should fail > typecheck files 1`] = `
|
||||||
"TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
|
"TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
|
||||||
|
TypeCheckError: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try \`npm i --save-dev @types/node\` and then add 'node' to the types field in your tsconfig.
|
||||||
TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has no call signatures.
|
TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has no call signatures.
|
||||||
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
|
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
|
||||||
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
|
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
|
||||||
@ -77,6 +78,17 @@ TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`should fail > typecheck files 8`] = `
|
exports[`should fail > typecheck files 8`] = `
|
||||||
|
" FAIL node-types.test-d.ts > buffer is not available
|
||||||
|
TypeCheckError: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try \`npm i --save-dev @types/node\` and then add 'node' to the types field in your tsconfig.
|
||||||
|
❯ node-types.test-d.ts:4:3
|
||||||
|
2|
|
||||||
|
3| test('buffer is not available', () => {
|
||||||
|
4| Buffer.from([])
|
||||||
|
| ^
|
||||||
|
5| })"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`should fail > typecheck files 9`] = `
|
||||||
" FAIL only.test-d.ts > failing test
|
" FAIL only.test-d.ts > failing test
|
||||||
TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
|
TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
|
||||||
❯ only.test-d.ts:4:33
|
❯ only.test-d.ts:4:33
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.build.json",
|
"extends": "../../tsconfig.build.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./failing/*"
|
"./failing/*"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -24,17 +24,9 @@
|
|||||||
"~/*": ["./packages/ui/client/*"],
|
"~/*": ["./packages/ui/client/*"],
|
||||||
"vitest": ["./packages/vitest/src/public/index.ts"],
|
"vitest": ["./packages/vitest/src/public/index.ts"],
|
||||||
"vitest/globals": ["./packages/vitest/globals.d.ts"],
|
"vitest/globals": ["./packages/vitest/globals.d.ts"],
|
||||||
"vitest/node": ["./packages/vitest/src/public/node.ts"],
|
"vitest/*": ["./packages/vitest/src/public/*"],
|
||||||
"vitest/reporters": ["./packages/vitest/src/public/reporters.ts"],
|
|
||||||
"vitest/execute": ["./packages/vitest/src/public/execute.ts"],
|
|
||||||
"vitest/config": ["./packages/vitest/src/public/config.ts"],
|
|
||||||
"vitest/coverage": ["./packages/vitest/src/public/coverage.ts"],
|
|
||||||
"vitest/internal/browser": ["./packages/vitest/src/public/browser.ts"],
|
|
||||||
"vitest/runners": ["./packages/vitest/src/public/runners.ts"],
|
|
||||||
"vite-node": ["./packages/vite-node/src/index.ts"],
|
"vite-node": ["./packages/vite-node/src/index.ts"],
|
||||||
"vite-node/client": ["./packages/vite-node/src/client.ts"],
|
"vite-node/*": ["./packages/vite-node/src/*"]
|
||||||
"vite-node/server": ["./packages/vite-node/src/server.ts"],
|
|
||||||
"vite-node/utils": ["./packages/vite-node/src/utils.ts"]
|
|
||||||
},
|
},
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
"extends": "./tsconfig.base.json",
|
"extends": "./tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"paths": {
|
"paths": {
|
||||||
"vitest": ["./packages/vitest/dist/index.d.ts"]
|
"vitest": ["./packages/vitest/dist/index.d.ts"],
|
||||||
|
"vitest/*": ["./packages/vitest/dist/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user