Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): correct project.provide type #5959

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading