MCPcopy
hub / github.com/vitest-dev/vitest / startVitest

Function startVitest

packages/vitest/src/node/cli/cli-api.ts:56–151  ·  view source on GitHub ↗
(
  mode: VitestRunMode,
  cliFilters: string[] = [],
  options: CliOptions = {},
  viteOverrides?: ViteUserConfig,
  vitestOptions?: VitestOptions,
)

Source from the content-addressed store, hash-verified

54 * Returns a Vitest instance if initialized successfully.
55 */
56export async function startVitest(
57 mode: VitestRunMode,
58 cliFilters: string[] = [],
59 options: CliOptions = {},
60 viteOverrides?: ViteUserConfig,
61 vitestOptions?: VitestOptions,
62): Promise<Vitest> {
63 const root = resolve(options.root || process.cwd())
64
65 const ctx = await prepareVitest(
66 mode,
67 options,
68 viteOverrides,
69 vitestOptions,
70 cliFilters,
71 )
72
73 if (mode === 'test' && ctx._coverageOptions.enabled) {
74 const provider = ctx._coverageOptions.provider || 'v8'
75 const requiredPackages = CoverageProviderMap[provider]
76
77 if (requiredPackages) {
78 if (
79 !(await ctx.packageInstaller.ensureInstalled(requiredPackages, root, ctx.version))
80 ) {
81 process.exitCode = 1
82 return ctx
83 }
84 }
85 }
86
87 const stdin = vitestOptions?.stdin || process.stdin
88 const stdout = vitestOptions?.stdout || process.stdout
89 let stdinCleanup
90 if (stdin.isTTY && ctx.config.watch) {
91 stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout)
92 }
93
94 ctx.onAfterSetServer(() => {
95 if (ctx.config.standalone) {
96 ctx.standalone()
97 }
98 else {
99 ctx.start(cliFilters)
100 }
101 })
102
103 try {
104 if (ctx.config.listTags) {
105 await ctx.listTags()
106 }
107 else if (ctx.config.clearCache) {
108 await ctx.experimental_clearCache()
109 }
110 else if (ctx.config.mergeReports) {
111 await ctx.mergeReports()
112 }
113 else if (ctx.config.standalone) {

Callers 6

cli.test.jsFile · 0.90
runVitestFunction · 0.90
ui.spec.tsFile · 0.90
startFunction · 0.70

Calls 14

registerConsoleShortcutsFunction · 0.90
prepareVitestFunction · 0.85
ensureInstalledMethod · 0.80
onAfterSetServerMethod · 0.80
standaloneMethod · 0.80
listTagsMethod · 0.80
errorMethod · 0.80
printErrorMethod · 0.80
shouldKeepServerMethod · 0.80
resolveFunction · 0.50
startMethod · 0.45

Tested by

no test coverage detected