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/package.json b/package.json index 87fa0a5d..bcf87a87 100644 --- a/package.json +++ b/package.json @@ -101,25 +101,6 @@ "scope": "resource", "default": "" }, - "vitest.include": { - "markdownDescription": "Include glob for test files. Default: `[\"**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}\"]`", - "type": "array", - "default": [ - "**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}" - ], - "scope": "resource" - }, - "vitest.exclude": { - "markdownDescription": "Exclude globs for test files. \nDefault: `[\"**/node_modules/**\", \"**/dist/**\", \"**/cypress/**\", \"**/.{idea,git,cache,output,temp}/**\"]`", - "type": "array", - "default": [ - "**/node_modules/**", - "**/dist/**", - "**/cypress/**", - "**/.{idea,git,cache,output,temp}/**" - ], - "scope": "resource" - }, "vitest.debugExclude": { "markdownDescription": "Automatically skip files covered by these glob patterns. \nDefault: `[\"/**\", \"**/node_modules/**\"]`", "type": "array", diff --git a/samples/basic/.vscode/settings.json b/samples/basic/.vscode/settings.json index 68d058c0..152ef396 100644 --- a/samples/basic/.vscode/settings.json +++ b/samples/basic/.vscode/settings.json @@ -1,9 +1,5 @@ { "vitest.nodeEnv": {}, - "vitest.include": [ - "**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}", - "**/src/should_included_test.ts" - ], "vitest.exclude": [ "**/node_modules/**", "**/dist/**", 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 }))