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

Function runVitest

test/test-utils/index.ts:59–268  ·  view source on GitHub ↗
(
  config: RunVitestConfig,
  cliFilters: string[] = config.$cliFilters || [],
  runnerOptions: VitestRunnerCLIOptions = {},
)

Source from the content-addressed store, hash-verified

57 * except for the ones provided in `$cliOptions`.
58 */
59export async function runVitest(
60 config: RunVitestConfig,
61 cliFilters: string[] = config.$cliFilters || [],
62 runnerOptions: VitestRunnerCLIOptions = {},
63) {
64 // Reset possible previous runs
65 process.exitCode = 0
66 let exitCode = process.exitCode
67
68 if (runnerOptions.printExitCode) {
69 globalThis.process = new Proxy(process_, {
70 set(target, p, newValue, receiver) {
71 if (p === 'exitCode') {
72 // eslint-disable-next-line no-console
73 console.trace('exitCode was set to', newValue)
74 }
75 return Reflect.set(target, p, newValue, receiver)
76 },
77 })
78 }
79
80 // Prevent possible process.exit() calls, e.g. from --browser
81 const exit = process.exit
82 process.exit = (() => { }) as never
83
84 const stdout = new Writable({
85 write(chunk, __, callback) {
86 if (runnerOptions.std === 'inherit') {
87 process.stdout.write(chunk.toString())
88 }
89 callback()
90 },
91 })
92
93 if (runnerOptions?.tty) {
94 (stdout as typeof process.stdout).isTTY = true
95 }
96
97 const stderr = new Writable({
98 write(chunk, __, callback) {
99 if (runnerOptions.std === 'inherit') {
100 process.stderr.write(chunk.toString())
101 }
102 callback()
103 },
104 })
105
106 // "node:tty".ReadStream doesn't work on Github Windows CI, let's simulate it
107 const stdin = new Readable({ read: () => '' }) as NodeJS.ReadStream
108 stdin.isTTY = true
109 stdin.setRawMode = () => stdin
110 const cli = new Cli({ stdin, stdout, stderr, preserveAnsi: runnerOptions.preserveAnsi })
111 // @ts-expect-error not typed global
112 const currentConfig: SerializedConfig = __vitest_worker__.ctx.config
113
114 let ctx: Vitest | undefined
115 let thrown = false
116

Callers 15

benchmark.test.tsFile · 0.90
mocking.test.tsFile · 0.90
runBrowserTestsFunction · 0.90
soft.test.tsFile · 0.90
domain.test.tsFile · 0.90
summary.test.tsFile · 0.90
obsolete.test.tsFile · 0.90

Calls 6

startVitestFunction · 0.90
inspectFunction · 0.85
afterEachFunction · 0.85
errorMethod · 0.80
onCloseMethod · 0.80
closeMethod · 0.45

Tested by 5

runFunction · 0.72
runFunction · 0.72
runFunction · 0.72
runFunction · 0.72
getConfigFunction · 0.72