diff --git a/README.md b/README.md index 2e38d04c..117e52a5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ # Config -- `vitest.include` and `vitest.exclude`` are deprecated. The extension now loads the include and exclude paths from your vitest config file. - `vitest.enable`: This plugin will try to detect whether the current project is set up with Vitest to activate itself. If detection fails, you can enable the plugin manually. - `vitest.nodeEnv`: The env passed to runner process in addition to diff --git a/src/config.ts b/src/config.ts index 44a68a93..33ec812c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,4 @@ import semver from 'semver' -import type { ResolvedConfig } from 'vitest' import type { WorkspaceConfiguration, WorkspaceFolder } from 'vscode' import * as vscode from 'vscode' import { log } from './log' @@ -7,17 +6,6 @@ import { isDefinitelyVitestEnv, mayBeVitestEnv } from './pure/isVitestEnv' import { getVitestCommand, getVitestVersion, isNodeAvailable } from './pure/utils' export const extensionId = 'zxch3n.vitest-explorer' -// Copied from https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/defaults.ts -// "import { configDefaults } from 'vitest'" throws unexpected URL error -const defaultInclude = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'] -const defaultExclude = [ - '**/node_modules/**', - '**/dist/**', - '**/cypress/**', - '**/.{idea,git,cache,output,temp}/**', - '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*', -] - export function getConfigValue( rootConfig: WorkspaceConfiguration, folderConfig: WorkspaceConfiguration, @@ -43,21 +31,11 @@ export function getConfig(workspaceFolder?: WorkspaceFolder | vscode.Uri | strin env: get>('nodeEnv', null), commandLine: get('commandLine', undefined), watchOnStartup: get('watchOnStartup', false), - include: get('include'), - exclude: get('exclude'), enable: get('enable', false), debugExclude: get('debugExclude', []), } } -export function getCombinedConfig(config: ResolvedConfig, workspaceFolder?: WorkspaceFolder | vscode.Uri | string) { - const vitestConfig = getConfig(workspaceFolder) - return { - exclude: vitestConfig.exclude?.concat(config.exclude) || defaultExclude, - include: vitestConfig.include?.concat(config.include) || defaultInclude, - } -} - export function getRootConfig() { const rootConfig = vscode.workspace.getConfiguration('vitest') diff --git a/src/discover.ts b/src/discover.ts index 57979725..8d121bbf 100644 --- a/src/discover.ts +++ b/src/discover.ts @@ -14,7 +14,7 @@ import parse from './pure/parsers' import type { NamedBlock } from './pure/parsers/parser_nodes' import { shouldIncludeFile } from './vscodeUtils' -import { getCombinedConfig, vitestEnvironmentFolders } from './config' +import { vitestEnvironmentFolders } from './config' import { log } from './log' import { openTestTag } from './tags' @@ -53,8 +53,8 @@ export class TestFileDiscoverer extends vscode.Disposable { const watchers = [] as vscode.FileSystemWatcher[] await Promise.all( vitestEnvironmentFolders.map(async (workspaceFolder) => { - const exclude = getCombinedConfig(this.config, workspaceFolder).exclude - for (const include of getCombinedConfig(this.config, workspaceFolder).include) { + const exclude = this.config.exclude + for (const include of this.config.include) { const pattern = new vscode.RelativePattern( workspaceFolder.uri, include, @@ -108,8 +108,8 @@ export class TestFileDiscoverer extends vscode.Disposable { await Promise.all( vscode.workspace.workspaceFolders.map(async (workspaceFolder) => { const workspacePath = workspaceFolder.uri.fsPath - const exclude = getCombinedConfig(this.config, workspaceFolder).exclude - for (const include of getCombinedConfig(this.config, workspaceFolder).include) { + const exclude = this.config.exclude + for (const include of this.config.include) { const pattern = new vscode.RelativePattern( workspaceFolder.uri, include, diff --git a/src/vscodeUtils.ts b/src/vscodeUtils.ts index d0e3f5e5..266bc4fe 100644 --- a/src/vscodeUtils.ts +++ b/src/vscodeUtils.ts @@ -1,9 +1,8 @@ +import minimatch from 'minimatch' import { TextDecoder } from 'util' +import type { ResolvedConfig } from 'vitest' import type { Uri } from 'vscode' import { workspace } from 'vscode' -import minimatch from 'minimatch' -import type { ResolvedConfig } from 'vitest' -import { getCombinedConfig } from './config' const textDecoder = new TextDecoder('utf-8') @@ -19,7 +18,7 @@ export const getContentFromFilesystem = async (uri: Uri) => { } export function shouldIncludeFile(path: string, config: ResolvedConfig) { - const { include, exclude } = getCombinedConfig(config) + const { include, exclude } = config return ( include.some(x => minimatch(path, x)) && exclude.every(x => !minimatch(path, x, { dot: true }))