Skip to content

Commit

Permalink
fix(vitest): deprecate old task types and node-reliant types (#6632)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 3, 2024
1 parent 937cca8 commit 000459a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,14 @@ export interface RuntimeContext {
currentSuite: SuiteCollector | null
}

/**
* User's custom test context.
*/
export interface TestContext {}

/**
* Context that's always available in the test function.
*/
export interface TaskContext<Task extends Custom | Test = Custom | Test> {
/**
* Metadata of the current test
Expand Down
47 changes: 36 additions & 11 deletions packages/vitest/src/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import '../types/global'

import type {
Custom as Custom_,
DoneCallback as DoneCallback_,
File as File_,
RuntimeContext as RuntimeContext_,
SuiteHooks as SuiteHooks_,
Suite as Suite_,
TaskBase as TaskBase_,
TaskResultPack as TaskResultPack_,
TaskResult as TaskResult_,
Task as Task_,
Test as Test_,
} from '@vitest/runner'
Expand All @@ -18,6 +24,10 @@ import type {
TscErrorInfo as TscErrorInfo_,
} from '../typecheck/types'

import type {
WorkerRPC as WorkerRPC_,
} from '../types/worker'

import type {
ArgumentsType as ArgumentsType_,
Arrayable as Arrayable_,
Expand Down Expand Up @@ -86,6 +96,9 @@ import type {
} from '../node/types/benchmark'

import type { SerializedTestSpecification } from '../runtime/types/utils'
import type {
WorkerContext as WorkerContext_,
} from '../node/types/worker'

export {
suite,
Expand Down Expand Up @@ -137,34 +150,46 @@ export type Test = Test_
export type Custom = Custom_
/** @deprecated use `RunnerTask` instead */
export type Task = Task_
/** @deprecated use `RunnerTaskBase` instead */
export type TaskBase = TaskBase_
/** @deprecated use `RunnerTaskResult` instead */
export type TaskResult = TaskResult_
/** @deprecated use `RunnerTaskResultPack` instead */
export type TaskResultPack = TaskResultPack_

/** @deprecated don't use `DoneCallback` since it's not supported */
export type DoneCallback = DoneCallback_

/** @deprecated internal type, don't use it */
export type RuntimeContext = RuntimeContext_
/** @deprecated internal type, don't use it */
export type SuiteHooks = SuiteHooks_

export type {
RunMode,
TaskState,
TaskBase,
TaskResult,
TaskResultPack,
TaskBase as RunnerTaskBase,
TaskResult as RunnerTaskResult,
TaskResultPack as RunnerTaskResultPack,
Suite as RunnerTestSuite,
File as RunnerTestFile,
Test as RunnerTestCase,
Task as RunnerTask,
Custom as RunnerCustomCase,
DoneCallback,
TestFunction,
TestOptions,
TestAPI,
SuiteAPI,
HookListener,
HookCleanupCallback,
SuiteHooks,
SuiteCollector,
SuiteFactory,
RuntimeContext,
TestContext,
TaskContext,
ExtendedContext,
TaskCustomOptions,
OnTestFailedHandler,
OnTestFinishedHandler,
TaskMeta,
} from '@vitest/runner'
export type {
Expand All @@ -182,17 +207,17 @@ export type {
SnapshotSerializer,
} from '@vitest/snapshot'

/** @deprecated import from `vitest/node` instead */
export type WorkerContext = WorkerContext_
/** @deprecated import from `vitest/node` instead */
export type WorkerRPC = WorkerRPC_

export type {
ResolveIdFunction,
WorkerRPC,
WorkerGlobalState,
ContextTestEnvironment,
ContextRPC,
} from '../types/worker'
export type {
/** @deprecated import from `vitest/node` instead */
WorkerContext,
} from '../node/types/worker'

/** @deprecated do not use, internal helper */
export type Awaitable<T> = Awaitable_<T>
Expand Down
21 changes: 17 additions & 4 deletions packages/vitest/src/types/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { FetchResult, RawSourceMap, ViteNodeResolveId } from 'vite-node'
import type { CancelReason, File, TaskResultPack } from '@vitest/runner'
import type { SnapshotResult } from '@vitest/snapshot'
import type { AfterSuiteRunMeta, TransformMode, UserConsoleLog } from './general'
Expand All @@ -11,16 +10,30 @@ export interface RuntimeRPC {
externalize?: string
id?: string
}>
transform: (id: string, transformMode: TransformMode) => Promise<FetchResult>
transform: (id: string, transformMode: TransformMode) => Promise<{
code?: string
}>
resolveId: (
id: string,
importer: string | undefined,
transformMode: TransformMode
) => Promise<ViteNodeResolveId | null>
) => Promise<{
external?: boolean | 'absolute' | 'relative'
id: string
/** @deprecated */
meta?: Record<string, any> | null
/** @deprecated */
moduleSideEffects?: boolean | 'no-treeshake' | null
/** @deprecated */
syntheticNamedExports?: boolean | string | null
} | null>
/**
* @deprecated unused
*/
getSourceMap: (
id: string,
force?: boolean
) => Promise<RawSourceMap | undefined>
) => Promise<any>

onFinished: (files: File[], errors?: unknown[]) => void
onPathsCollected: (paths: string[]) => void
Expand Down

0 comments on commit 000459a

Please sign in to comment.