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

Function runVitest

test/coverage-test/utils.ts:29–90  ·  test/coverage-test/utils.ts::runVitest
(config: TestUserConfig, options = { throwOnError: true }, viteOverrides: ViteUserConfig = {})

Source from the content-addressed store, hash-verified

27 : vitestTest
28
29export async function runVitest(config: TestUserConfig, options = { throwOnError: true }, viteOverrides: ViteUserConfig = {}) {
30 const provider = process.env.COVERAGE_PROVIDER as any
31
32 const result = await testUtils.runVitest({
33 config: class="st">'fixtures/configs/vitest.config.ts',
34 pool: class="st">'threads',
35 ...config,
36 env: {
37 COVERAGE_TEST: class="st">'true',
38 ...config.env,
39 },
40 coverage: {
41 enabled: true,
42 reporter: [],
43 ...config.coverage,
44 provider,
45 customProviderModule: provider === class="st">'custom' ? class="st">'fixtures/custom-provider' : undefined,
46 },
47 browser: {
48 enabled: process.env.COVERAGE_BROWSER === class="st">'true',
49 headless: true,
50 instances: [{ browser: class="st">'chromium' }],
51 provider: playwright(),
52 ...config.browser,
53 },
54 experimental: {
55 ...config.experimental,
56 viteModuleRunner: process.env.VITE_MODULE_RUNNER === class="st">'false' ? false : config.experimental?.viteModuleRunner,
57 },
58 setupFiles: [
59 resolve(import.meta.dirname, class="st">'setup.native.ts'),
60 ...config.setupFiles ?? [],
61 ],
62
63 projects: config.projects?.map((project) => {
64 if (typeof project !== class="st">'string' && class="st">'test' in project) {
65 project.test ||= {}
66 project.test.setupFiles = toArray(project.test.setupFiles)
67 project.test.setupFiles.push(resolve(import.meta.dirname, class="st">'setup.native.ts'))
68 }
69
70 return project
71 }),
72
73 $viteConfig: viteOverrides,
74 })
75
76 if (TestRunner.getCurrentTest()) {
77 onTestFailed(() => {
78 console.error(class="st">'stderr:', result.stderr)
79 console.error(class="st">'stdout:', result.stdout)
80 })
81 }
82
83 if (options.throwOnError) {
84 if (result.stderr !== class="st">'') {
85 throw new Error(`stderr:\n${result.stderr}\n\nstdout:\n${result.stdout}`)
86 }

Calls 4

playwrightFunction · 0.90
toArrayFunction · 0.90
errorMethod · 0.80
resolveFunction · 0.70

Tested by 2

startWatchModeFunction · 0.72
runFunction · 0.40