From 214ec2677dbd463b9b9f8f90894e54a018c23d8e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 1 Oct 2024 16:59:38 +0200 Subject: [PATCH] docs: mention `state.getFiles` API (#6607) --- docs/advanced/api.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/advanced/api.md b/docs/advanced/api.md index 5429a84f0..4d1fcecaa 100644 --- a/docs/advanced/api.md +++ b/docs/advanced/api.md @@ -34,6 +34,23 @@ Additionally, you can use the third argument to pass in CLI arguments, which wil Alternatively, you can pass in the complete Vite config as the fourth argument, which will take precedence over any other user-defined options. +After running the tests, you can get the results from the `state.getFiles` API: + +```ts +const vitest = await startVitest('test') + +console.log(vitest.state.getFiles()) // [{ type: 'file', ... }] +``` + +Since Vitest 2.1, it is recommended to use the ["Reported Tasks" API](/advanced/reporters#reported-tasks) together with the `state.getFiles`. In the future, Vitest will return those objects directly: + +```ts +const vitest = await startVitest('test') + +const [fileTask] = vitest.state.getFiles() +const testFile = vitest.state.getReportedEntity(fileTask) +``` + ## createVitest You can create Vitest instance yourself using `createVitest` function. It returns the same `Vitest` instance as `startVitest`, but it doesn't start tests and doesn't validate installed packages. -- 2.51.2