How describe, test and the rest become available
| Mode | Form | Notes |
|---|---|---|
| Named import | import { test, describe, it, expect, beforeEach } from 'vitest' |
The common case. Resolved with normal import-binding semantics (oxc_semantic symbol resolution), including renamed imports (import { test as t } from 'vitest'). |
| Namespace import | import * as vitest from 'vitest'; vitest.test(...) |
Member access off a namespace-imported binding from the 'vitest' specifier must be recognized, not just bare identifiers. |
| Globals | globals: true in config |
No import at all. See Globals. |
Registration re-exports
Section titled “Registration re-exports”The analyzer follows direct and renamed registration re-exports through project barrels.
Multiple export * paths preserve a registration when they prove the same terminal API module
and export name. An explicit known value re-export takes precedence over stars in either source
order. A matching registration category alone does not prove binding identity; conflicting or
opaque star sources retain their conservative refusal. Module-load registrations remain visible
independently of which export supplies the imported function.
Globals
Section titled “Globals”With globals: true, test, describe, it, suite, expect, the hooks and the rest are
ambient globals, syntactically indistinguishable from any other free identifier of the same name.
- Recognizing them requires resolving the effective Vitest config for the file’s project.
- Only when
globals: trueresolves for that file are the bare identifiers treated as Vitest globals. - A bare identifier that merely looks like a test declarator is not one until the config says so.
globals config specifics
Section titled “globals config specifics”From /config/globals:
- Default:
false. - Enable with
test: { globals: true }in the resolved Vite/Vitest config, or the--globalsCLI flag. - For TypeScript ambient types, projects also add
"types": ["vitest/globals"]totsconfig.json. That is a type-checking concern only, not a runtime-behavior signal, so the extractor does not use it as an alternative detection source: a repo could have the types entry withoutglobals: true, or vice versa via the CLI flag. It MAY be used as a corroborating hint when the config file itself is not resolvable.
Where globals: true can be set
Section titled “Where globals: true can be set”Any of:
- Root
vitest.config.{ts,mts,cts,js,mjs,cjs}, looked up first. - Root
vite.config.{ts,mts,cts,js,mjs,cjs}, looked up second, if novitest.configis found. Thetestfield is nested under Vite’s own config object, optionally gated byprocess.env.VITESTor Vite’smodeto avoid polluting the plain Vite build config type. - Per project, inside a
test.projectsentry: either an inline object ({ test: { globals: true, ... } }) or a referenced project config file matchingvitest.config*,vite.config*,vitest.<name>.config.*orvite.<name>.config.*(<name>= letters, digits,_or-). - Legacy
vitest.workspace.{ts,js}files, deprecated since 3.2 in favor oftest.projectsbut still functionally supported per the projects guide. Each entry can carry its ownglobalsthe same way aprojectsarray entry can.
Per-project settings matter because projects can set extends: false to ignore the root config, so
globals is not guaranteed uniform across a workspace. The extractor must resolve it per
project, not once globally for the whole scan.
[UNVERIFIED] Whether globals is on the explicit “root config only” restricted-options list. The
config overview page mentions such a list exists, but the fetched excerpt did not confirm this
option’s membership. Treat it as settable per project unless direct testing shows otherwise.
Config file lookup does not consider JSON files for the root config: vitest.config.json is not
in the documented lookup list. UNVERIFIED for legacy vitest.workspace.json.
Back to the Vitest surface index.