From 0f0d75631c3b9d6f335d822a24e25b46b2219eda Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 10 May 2023 17:07:37 +0200 Subject: [PATCH] docs: synchronize startVitest API with docs (#3343) Co-authored-by: Anjorin Damilare --- docs/advanced/api.md | 8 +++++++- packages/vitest/src/node/cli-api.ts | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/advanced/api.md b/docs/advanced/api.md index c58aee76961a..68e8720b2dc4 100644 --- a/docs/advanced/api.md +++ b/docs/advanced/api.md @@ -11,7 +11,7 @@ You can start running Vitest tests using its Node API: ```js import { startVitest } from 'vitest/node' -const vitest = await startVitest('test', ['tests/run-only.test.ts']) +const vitest = await startVitest('test') await vitest?.close() ``` @@ -28,6 +28,12 @@ If watch mode is not enabled, Vitest will call `close` method. If watch mode is enabled and the terminal supports TTY, Vitest will register console shortcuts. +You can pass down a list of filters as a second argument. Vitest will run only tests that contain at least one of the passed-down strings in their file path. + +Additionally, you can use the third argument to pass in CLI arguments, which will override any test config options. + +Alternatively, you can pass in the complete Vite config as the fourth argument, which will take precedence over any other user-defined options. + ## 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. diff --git a/packages/vitest/src/node/cli-api.ts b/packages/vitest/src/node/cli-api.ts index b22932804ed9..1cb2bc2dc5d1 100644 --- a/packages/vitest/src/node/cli-api.ts +++ b/packages/vitest/src/node/cli-api.ts @@ -22,8 +22,8 @@ export interface CliOptions extends UserConfig { */ export async function startVitest( mode: VitestRunMode, - cliFilters: string[], - options: CliOptions, + cliFilters: string[] = [], + options: CliOptions = {}, viteOverrides?: ViteUserConfig, ): Promise { process.env.TEST = 'true'