Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ These options are resolved relative to the [workspace file](https://code.visuals
- `vitest.debugExclude`: Excludes files matching specified glob patterns from debugging. Default:
`[\"<node_internals>/**\", \"**/node_modules/**\"]`
- `vitest.debugOutFiles`: If source maps are enabled, these glob patterns specify the generated JavaScript files. If a pattern starts with `!` the files are excluded. If not specified, the generated code is expected in the same directory as its source. Default: `["${workspaceFolder}/**/*.(m|c|)js", "!**/node_modules/**"]`
- `vitest.maximumConfigs`: The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file. Default: `3`
- `vitest.maximumConfigs`: The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file. Default: `5`
- `vitest.logLevel`: How verbose should the logger be in the "Output" channel. Default: `info`
- `vitest.applyDiagnostic`: Show a squiggly line where the error was thrown. This also enables the error count in the File Tab. Default: `true`
- `vitest.experimentalStaticAstCollect`: uses AST parses to collect tests instead of running files and collecting them at runtime. Default: `true`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"vitest.maximumConfigs": {
"description": "The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file.",
"type": "number",
"default": 3,
"default": 5,
"scope": "window"
},
"vitest.debugExclude": {
Expand Down
24 changes: 14 additions & 10 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from 'vscode'
import { log } from './log'
import type { ExtensionWorkerEvents, SerializedTestSpecification, VitestRPC } from './api/rpc'
import type { VitestPackage } from './api/pkg'
import { createVitestWorkspaceFile, noop, showVitestError } from './utils'
import { showVitestError } from './utils'
import { createVitestTerminalProcess } from './api/terminal'
import { getConfig } from './config'
import { createVitestProcess } from './api/child_process'
Expand Down Expand Up @@ -280,7 +280,7 @@ export async function resolveVitestAPI(workspaceConfigs: VitestPackage[], config
return depthA - depthB
})

const maximumConfigs = getConfig().maximumConfigs ?? 3
const maximumConfigs = getConfig().maximumConfigs ?? 5

const workspaceRoots: string[] = apis
.map(api => api.workspaceSource ? dirname(api.workspaceSource) : null)
Expand Down Expand Up @@ -345,27 +345,31 @@ function isCoveredByWorkspace(workspacesRoots: string[], currentConfig: string):
}

function warnPerformanceConfigLimit(configsToResolve: VitestPackage[]) {
const maximumConfigs = getConfig().maximumConfigs ?? 3
const maximumConfigs = getConfig().maximumConfigs ?? 5
const warningMessage = [
'Vitest found multiple config files.',
'Vitest found multiple projects.',
`The extension will use only the first ${maximumConfigs} due to performance concerns.`,
'Consider using a workspace configuration to group your configs or increase',
'Consider using a projects configuration to group your configs or increase',
'the limit via "vitest.maximumConfigs" option.',
].join(' ')

const folders = Array.from(new Set(configsToResolve.map(c => c.folder)))
const allConfigs = [...configsToResolve]
// remove all but the first 3
// remove all but the first 5
const discardedConfigs = configsToResolve.splice(maximumConfigs)

if (folders.every(f => getConfig(f).disableWorkspaceWarning !== true)) {
vscode.window.showWarningMessage(
warningMessage,
'Create vitest.workspace.js',
'Documentation',
'Disable notification',
).then((result) => {
if (result === 'Create vitest.workspace.js')
createVitestWorkspaceFile(allConfigs).catch(noop)
if (result === 'Documentation') {
vscode.commands.executeCommand(
'vscode.open',
// /workspace redirects to /projects on the new version
vscode.Uri.parse('https://vitest.dev/guide/workspace'),
)
}

if (result === 'Disable notification') {
folders.forEach((folder) => {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {
workspaceConfig: resolveConfigPath(workspaceConfig),
rootConfig: resolveConfigPath(rootConfigFile),
configSearchPatternExclude,
maximumConfigs: get<number>('maximumConfigs', 3),
maximumConfigs: get<number>('maximumConfigs', 5),
nodeExecutable: resolveConfigPath(nodeExecutable),
disableWorkspaceWarning: get<boolean>('disableWorkspaceWarning', false),
debuggerPort: get<number>('debuggerPort') || undefined,
Expand Down
27 changes: 0 additions & 27 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@ export function formatPkg(pkg: VitestPackage) {
return `Vitest v${pkg.version} (${relative(dirname(pkg.cwd), pkg.id)})`
}

export async function createVitestWorkspaceFile(vitest: VitestPackage[]) {
const folders = new Set(vitest.map(x => x.folder))
const encoder = new TextEncoder()
const promises = [...folders].map(async (folder) => {
const configFiles = vitest.filter(x => x.folder === folder).map(x => relative(folder.uri.fsPath, x.configFile!))
const ext = configFiles.every(x => /\.m?ts$/.test(x)) ? 'ts' : 'js'
const workspaceFileUri = vscode.Uri.joinPath(folder.uri, `vitest.workspace.${ext}`)

const workspaceContent = `
import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
${configFiles.map(file => `"./${file}"`).join(',\n ')}
])
`.trimStart()

await vscode.workspace.fs.writeFile(workspaceFileUri, encoder.encode(workspaceContent))
return await vscode.workspace.openTextDocument(workspaceFileUri)
})

const results = await Promise.all(promises)
if (results[0])
await vscode.window.showTextDocument(results[0])

await vscode.window.showInformationMessage('Created vitest.workspace.js. You might need to run \`npm i --save-dev vitest\` in the root folder to install Vitest.')
}

function _showVitestError(message: string, error?: any) {
if (error)
log.error(error)
Expand Down
Loading