Imported runners
A runner is a first-party function that registers tests when called. When VitestDedup can prove what a call registers, it expands the call into those tests, as if they were written at the call site, so a wrapper helper does not hide duplicates. When it cannot, the call is counted and the tests around it are left out of comparison rather than guessed at.
What an expansion keeps
Section titled “What an expansion keeps”- Source locations come from the runner; the registering file, governing globals and configuration come from the caller.
- Each call registers its own tests, titled from its own arguments. Every test a call registers is a separate runtime case for that call, keyed by its declaration, the caller file and the chain of call positions (a nested call is its own execution). So the tests that repeated calls with equal arguments register can be reported as duplicates of each other (under an equivalent context, with the rule enabled); such a finding names the runner’s declaration for both.
- An expanded test is compared with every other test, including the caller’s own.
- Reads of
import.metaretain the runner’s source module identity. A matching spelling in a different module does not establish equal metadata, even when both assertions happen to pass. - Type-only imports, interfaces and type aliases are erased and add no effects.
When a call is expanded
Section titled “When a call is expanded”The calling file qualifies when it parses cleanly and its top level holds only imports, inert
declarations (functions, types, literal constants), plain test(title, callback) calls with a
static title (a string of any length, or a template up to 65,536 bytes) and an inline callback,
statement-level calls of imported runners or same-file helpers, and plain
describe blocks (a title that renders from literals or constants, no each, no skip, no third
argument, and a synchronous
callback that takes no parameters) whose bodies close the same way. A call
may sit inside such a describe: Vitest runs describe callbacks after the module body, so what the
call registers joins that suite, and the tests take its suite path. A hook written anywhere in the
calling file, a call inside a describe whose runner registers a hook (it would govern every test
in that suite), any other suite in the file (a table or skipped one, one with options, callback
parameters or a title that does not render; Vitest still runs its callback), a label the sequence
cannot close around, a module load the file does not import by name, or a registration function
read as a value refuses the whole file’s expansion. Every value it imports from a project module must be
a runner the proof read.
A runner qualifies when:
- it is a named or default export, reached directly or through re-export hops, whose binding is never reassigned;
- it is a synchronous, non-generator function with a body that does not read
thisorarguments, with plain, immutable positional parameters and no directeval; - importing its module, and every project module that loads with it, runs nothing that is not inert;
- its body is a sequence of
test(title, callback)calls with an inline callback, hook registrations, and calls of other runners, local or imported, that qualify in turn. Adescribeinside a runner is not expanded yet. Statements after an unconditionalreturndo not run. The sequence may also hold:- a
constholding one of those registrations (const registered = test(...)); - a
trywithoutcatchwhosefinallydeclares nothing, reads only literals and constants and ends normally, which leaves the block’s registrations as they are.
- a
A function declared with overload signatures runs its implementation. A registration function
built inside a runner (const each = test.each([1])) refuses, even when it is never used:
building one changes state Vitest’s later registrations read. So does the in-source binding
import.meta.vitest, which an imported module may not receive.
A title may read the call’s arguments when they are literals or constants the proof can evaluate.
Same-file helpers
Section titled “Same-file helpers”A function in the calling file is expanded the same way when:
- it is a top-level
functiondeclaration, or a top-levelconstbound to a function or arrow, never reassigned; - every use of it is a call: a statement-level call at the top level, or a call from another helper that qualifies;
- a
consthelper, and every top-level binding a helper reads, is declared before the first top-level call, since a hoisted function called above the declaration would reach it uninitialized. A top-level call can reach any helper through another, so the check covers every helper; a file whose calls all sit inside adescribehas nothing to precede, since describe callbacks run after the whole module body; - its body meets the runner rules above.
A test written inside such a helper is registered once per call, titled from that call’s arguments, and is not counted again on its own. A helper that fails any rule leaves the file’s tests excluded, as before.
Hooks-only helpers
Section titled “Hooks-only helpers”A call of a helper whose body registers only hooks is a hook-wrapper site: it registers no test,
and its hooks join the context of the tests in its scope. A body counts as hooks-only only when it is
closed: plain parameters, and statements that are hook registrations, calls of other hooks-only
helpers, declarations of plain names, return, blocks and if over values that run nothing. Proven
lexical beforeEach setup an imported helper installs takes part in redundant-hook; see
Hook scheduling.
Setup calls and packages
Section titled “Setup calls and packages”A call that registers nothing, of a first-party function or of an installed package, is setup: it joins the context of every test in its scope, so files that call it pair only with files that make the same call. Installed-package code is not read. A package that registers tests when called is not seen: its tests are missing from the count.
What a refusal does
Section titled “What a refusal does”Each call that may register tests and is not expanded counts as one test excluded as
registered-elsewhere, and the scope around it (its suite, or the file) is excluded as
helper-effects-unproved. The run is marked incomplete, and the json and jsonl reports list the
file with its reason; see Excluded files.
Nuxt projects
Section titled “Nuxt projects”The nearest applicable tsconfig.json, including its extends and project references, takes
precedence. When no user tsconfig exists on the importer’s route to its Nuxt project root,
vitest-dedup automatically uses the generated configuration in .nuxt. It recognizes a
nuxt.config.ts, .js, .mjs, .mts or .cjs file, or a nuxt dependency in package.json.
Discovery stops at the analysis root or a separate package boundary.
Legacy projects use .nuxt/tsconfig.json. Projects with generated app, shared or node configs
use Nuxt’s app/server/shared/node project references: each file gets the aliases of the context
that includes it. Files outside those contexts do not inherit app aliases. Existing user configs
are never replaced, including configs that exclude the importing file.
Run nuxt prepare when the missing-prerequisite notice
names generated configuration. vitest-dedup does not execute Nuxt or write a root tsconfig.
For a custom build directory, link the generated config from your own root tsconfig. Historical
analysis reads only committed configuration; it cannot borrow your working .nuxt directory.
The generated
auto-import tables (.nuxt/imports.d.ts) are not read: an auto-imported call is setup like any
other call that registers nothing.
Budgets
Section titled “Budgets”- Expansion follows runner calls to a depth of 8 and at most 2,000 calls per file, each with at most 2,000 arguments.
- The helper sources one file’s expansion reads share 8 MiB, and its proof work is bounded at 8 MiB. When building an ordinary imported runner template, each source read spends work before parsing. Completed templates can be reused in the same caller, with a separate 8 MiB estimate for retained template data. Templates that exceed the remaining retention budget can still serve the current invocation. Every invocation checks dependency and export depth limits.
- Helper files share the source limits: 8 MiB, 36,864 raw syntax units and lexical nesting depth 256.
- Each module inventory also bounds uncached import analysis at depth 32, 64 module-analysis attempts per pass, three cache-progress passes (192 attempts total), and 8 MiB of source shared by all passes. A limit makes the inventory incomplete and prevents runner expansion from using its partial results; completed cached proofs remain reusable. Its diagnostic names the exhausted bound, final refused root-relative module and the aggregate work already spent.
A file past a budget is refused as a whole, with the outcome above.
Baselines
Section titled “Baselines”--baseline-from-ref resolves project imports against committed source and resolver
configuration, with the same import-classification boundaries as a working-tree run. It never substitutes current helpers for historical dependencies.
Historical symlinks and actual source/configuration access failures refuse the baseline. A
missing package-based tsconfig extension or unresolved linkage to a committed project package makes
the historical pass incomplete with no allowance. Private #-mapped tsconfig extensions remain
errors; see
revision baselines.
Back to the documentation index.