Skip to content

Commit

Permalink
fix!: remove default include and exclude (#241)
Browse files Browse the repository at this point in the history
* fix!: remove default include and exclude

* fix: remove obsolete settings from manifest

* fix: lockfile out of date
  • Loading branch information
ffMathy authored Feb 18, 2024
1 parent bdaf3bd commit f64a8ab
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 55 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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_internals>/**\", \"**/node_modules/**\"]`",
"type": "array",
Expand Down
4 changes: 0 additions & 4 deletions samples/basic/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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/**",
Expand Down
22 changes: 0 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import semver from 'semver'
import type { ResolvedConfig } from 'vitest'
import type { WorkspaceConfiguration, WorkspaceFolder } from 'vscode'
import * as vscode from 'vscode'
import { log } from './log'
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<T>(
rootConfig: WorkspaceConfiguration,
folderConfig: WorkspaceConfiguration,
Expand All @@ -43,21 +31,11 @@ export function getConfig(workspaceFolder?: WorkspaceFolder | vscode.Uri | strin
env: get<null | Record<string, string>>('nodeEnv', null),
commandLine: get<string | undefined>('commandLine', undefined),
watchOnStartup: get<boolean>('watchOnStartup', false),
include: get<string[]>('include'),
exclude: get<string[]>('exclude'),
enable: get<boolean>('enable', false),
debugExclude: get<string[]>('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')

Expand Down
10 changes: 5 additions & 5 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/vscodeUtils.ts
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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 }))
Expand Down

0 comments on commit f64a8ab

Please sign in to comment.