[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Vladimir and committed by
GitHub
(Jun 24, 2024, 10:56 AM +0200) 0eda99de fca8b922

+7 -7
+2 -2
packages/vitest/src/integrations/inject.ts
··· 5 5 * Gives access to injected context provided from the main thread. 6 6 * This usually returns a value provided by `globalSetup` or an external library. 7 7 */ 8 - export function inject<T extends keyof ProvidedContext>( 8 + export function inject<T extends keyof ProvidedContext & string>( 9 9 key: T, 10 10 ): ProvidedContext[T] { 11 11 const workerState = getWorkerState() 12 - return workerState.providedContext[key] 12 + return workerState.providedContext[key] as ProvidedContext[T] 13 13 }
+1 -1
packages/vitest/src/node/core.ts
··· 183 183 } 184 184 } 185 185 186 - public provide<T extends keyof ProvidedContext>(key: T, value: ProvidedContext[T]) { 186 + public provide<T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) { 187 187 this.getCoreWorkspaceProject().provide(key, value) 188 188 } 189 189
+1 -1
packages/vitest/src/node/globalSetup.ts
··· 5 5 6 6 export interface GlobalSetupContext { 7 7 config: ResolvedConfig 8 - provide: <T extends keyof ProvidedContext>( 8 + provide: <T extends keyof ProvidedContext & string>( 9 9 key: T, 10 10 value: ProvidedContext[T] 11 11 ) => void
+3 -3
packages/vitest/src/node/workspace.ts
··· 115 115 return this.ctx.getCoreWorkspaceProject() === this 116 116 } 117 117 118 - provide = <T extends keyof ProvidedContext>( 118 + provide<T extends keyof ProvidedContext & string>( 119 119 key: T, 120 120 value: ProvidedContext[T], 121 - ) => { 121 + ) { 122 122 try { 123 123 structuredClone(value) 124 124 } ··· 157 157 158 158 for (const globalSetupFile of this._globalSetups) { 159 159 const teardown = await globalSetupFile.setup?.({ 160 - provide: this.provide, 160 + provide: (key, value) => this.provide(key, value), 161 161 config: this.config, 162 162 }) 163 163 if (teardown == null || !!globalSetupFile.teardown) {