···10031003globalThis.resetBeforeEachTest = true
10041004```
1005100510061006+### provide <Version>2.1.0</Version> {#provide}
10071007+10081008+- **Type:** `Partial<ProvidedContext>`
10091009+10101010+Define values that can be accessed inside your tests using `inject` method.
10111011+10121012+:::code-group
10131013+```ts [vitest.config.js]
10141014+import { defineConfig } from 'vitest/config'
10151015+10161016+export default defineConfig({
10171017+ test: {
10181018+ provide: {
10191019+ API_KEY: '123',
10201020+ },
10211021+ },
10221022+})
10231023+```
10241024+```ts [my.test.js]
10251025+import { expect, inject, test } from 'vitest'
10261026+10271027+test('api key is defined', () => {
10281028+ expect(inject('API_KEY')).toBe('123')
10291029+})
10301030+```
10311031+:::
10321032+10331033+::: warning
10341034+Properties have to be strings and values need to be [serializable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types) because this object will be transferred between different processes.
10351035+:::
10361036+10371037+::: tip
10381038+If you are using TypeScript, you will need to augment `ProvidedContext` type for type safe access:
10391039+10401040+```ts
10411041+// vitest.shims.d.ts
10421042+10431043+declare module 'vitest' {
10441044+ export interface ProvidedContext {
10451045+ API_KEY: string
10461046+ }
10471047+}
10481048+10491049+// mark this file as a module so augmentation works correctly
10501050+export {}
10511051+```
10521052+:::
10531053+10061054### globalSetup
1007105510081056- **Type:** `string | string[]`
···10181066::: warning
10191067Global setup runs only if there is at least one running test. This means that global setup might start running during watch mode after test file is changed (the test file will wait for global setup to finish before running).
1020106810211021-Beware that the global setup is running in a different global scope, so your tests don't have access to variables defined here. However, you can pass down serializable data to tests via `provide` method:
10691069+Beware that the global setup is running in a different global scope, so your tests don't have access to variables defined here. However, you can pass down serializable data to tests via [`provide`](#provide) method:
1022107010231071:::code-group
10241072```js [globalSetup.js]
···10331081 provide('wsPort', 3000)
10341082}
1035108310361036-// You can also extend `ProvidedContext` type
10371037-// to have type safe access to `provide/inject` methods:
10381084declare module 'vitest' {
10391085 export interface ProvidedContext {
10401086 wsPort: number
···364364 project.server = ctx.server
365365 project.runner = ctx.runner
366366 project.config = ctx.config
367367+ for (const _providedKey in ctx.config.provide) {
368368+ const providedKey = _providedKey as keyof ProvidedContext
369369+ // type is very strict here, so we cast it to any
370370+ (project.provide as (key: string, value: unknown) => void)(
371371+ providedKey,
372372+ ctx.config.provide[providedKey],
373373+ )
374374+ }
367375 project.testProject = new TestProject(project)
368376 return project
369377 }
···384392 server.config,
385393 this.ctx.logger,
386394 )
395395+ for (const _providedKey in this.config.provide) {
396396+ const providedKey = _providedKey as keyof ProvidedContext
397397+ // type is very strict here, so we cast it to any
398398+ (this.provide as (key: string, value: unknown) => void)(
399399+ providedKey,
400400+ this.config.provide[providedKey],
401401+ )
402402+ }
403403+387404 this.testProject = new TestProject(this)
388405389406 this.server = server