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

Function config

packages/vitest/src/node/plugins/workspace.ts:39–128  ·  view source on GitHub ↗
(viteConfig)

Source from the content-addressed store, hash-verified

37 name: 'vitest:project:name',
38 enforce: 'post',
39 config(viteConfig) {
40 const testConfig = viteConfig.test || {}
41
42 let { label: name, color } = typeof testConfig.name === 'string'
43 ? { label: testConfig.name }
44 : { label: '', ...testConfig.name }
45
46 if (!name) {
47 if (typeof options.workspacePath === 'string') {
48 // if there is a package.json, read the name from it
49 const dir = options.workspacePath.endsWith('/')
50 ? options.workspacePath.slice(0, -1)
51 : dirname(options.workspacePath)
52 const pkgJsonPath = resolve(dir, 'package.json')
53 if (existsSync(pkgJsonPath)) {
54 name = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')).name
55 }
56 if (typeof name !== 'string' || !name) {
57 name = basename(dir)
58 }
59 }
60 else {
61 name = options.workspacePath.toString()
62 }
63 }
64
65 const isUserBrowserEnabled = viteConfig.test?.browser?.enabled
66 const isBrowserEnabled = isUserBrowserEnabled ?? (viteConfig.test?.browser && project.vitest._cliOptions.browser?.enabled)
67 // keep project names to potentially filter it out
68 const workspaceNames = [name]
69 const browser = (viteConfig.test!.browser || {}) as BrowserConfigOptions
70 if (isBrowserEnabled && browser.name && !browser.instances?.length) {
71 // vitest injects `instances` in this case later on
72 workspaceNames.push(name ? `${name} (${browser.name})` : browser.name)
73 }
74
75 viteConfig.test?.browser?.instances?.forEach((instance) => {
76 // every instance is a potential project
77 instance.name ??= name ? `${name} (${instance.browser})` : instance.browser
78 if (isBrowserEnabled) {
79 workspaceNames.push(instance.name)
80 }
81 })
82
83 const filters = project.vitest.config.project
84 // if there is `--project=...` filter, check if any of the potential projects match
85 // if projects don't match, we ignore the test project altogether
86 // if some of them match, they will later be filtered again by `resolveWorkspace`
87 if (filters.length) {
88 const hasProject = workspaceNames.some((name) => {
89 return project.vitest.matchesProjectFilter(name)
90 })
91 if (!hasProject) {
92 throw new VitestFilteredOutProjectError()
93 }
94 }
95
96 const vitestConfig: UserConfig = {

Callers

nothing calls this directly

Calls 11

deleteDefineConfigFunction · 0.90
getDefaultResolveOptionsFunction · 0.90
resolveFsAllowFunction · 0.90
generateScopedClassNameFunction · 0.90
createViteLoggerFunction · 0.90
readFileSyncFunction · 0.85
matchesProjectFilterMethod · 0.80
resolveFunction · 0.50
relativeFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected