Skip to content

Commit

Permalink
fix(api): correct project.provide type (#5959)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jun 24, 2024
1 parent fca8b92 commit 0eda99d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { getWorkerState } from '../utils/global'
* Gives access to injected context provided from the main thread.
* This usually returns a value provided by `globalSetup` or an external library.
*/
export function inject<T extends keyof ProvidedContext>(
export function inject<T extends keyof ProvidedContext & string>(
key: T,
): ProvidedContext[T] {
const workerState = getWorkerState()
return workerState.providedContext[key]
return workerState.providedContext[key] as ProvidedContext[T]
}
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class Vitest {
}
}

public provide<T extends keyof ProvidedContext>(key: T, value: ProvidedContext[T]) {
public provide<T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) {
this.getCoreWorkspaceProject().provide(key, value)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ResolvedConfig } from '../types/config'

export interface GlobalSetupContext {
config: ResolvedConfig
provide: <T extends keyof ProvidedContext>(
provide: <T extends keyof ProvidedContext & string>(
key: T,
value: ProvidedContext[T]
) => void
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export class WorkspaceProject {
return this.ctx.getCoreWorkspaceProject() === this
}

provide = <T extends keyof ProvidedContext>(
provide<T extends keyof ProvidedContext & string>(
key: T,
value: ProvidedContext[T],
) => {
) {
try {
structuredClone(value)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ export class WorkspaceProject {

for (const globalSetupFile of this._globalSetups) {
const teardown = await globalSetupFile.setup?.({
provide: this.provide,
provide: (key, value) => this.provide(key, value),
config: this.config,
})
if (teardown == null || !!globalSetupFile.teardown) {
Expand Down

0 comments on commit 0eda99d

Please sign in to comment.