Skip to content

Commit

Permalink
fix!: improve globs (#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmccurdy committed Jun 6, 2023
1 parent 1ad63b0 commit 19ecc6c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
17 changes: 8 additions & 9 deletions docs/config/index.md
Expand Up @@ -81,7 +81,7 @@ All configuration options that are not supported inside a [workspace](/guide/wor
### include

- **Type:** `string[]`
- **Default:** `['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']`
- **Default:** `['**/__tests__/**/*.?(c|m)[jt]s?(x)', '**/?(*.){test,spec}.?(c|m)[jt]s?(x)']`

Files to include in the test run, using glob pattern.

Expand Down Expand Up @@ -226,7 +226,7 @@ Options used when running `vitest bench`.
#### benchmark.include

- **Type:** `string[]`
- **Default:** `['**/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']`
- **Default:** `['**/*.{bench,benchmark}.?(c|m)[jt]s?(x)']`

Include globs for benchmark test files

Expand Down Expand Up @@ -718,16 +718,15 @@ List of files included in coverage as glob patterns
[
'coverage/**',
'dist/**',
'packages/*/test{,s}/**',
'packages/*/test?(s)/**',
'**/*.d.ts',
'cypress/**',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
'test?(s)/**',
'test?(-*).?(c|m)[jt]s?(x)',
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
'**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}',
]
```
- **Available for providers:** `'c8' | 'istanbul'`
Expand Down Expand Up @@ -1358,7 +1357,7 @@ You can also pass down a path to custom binary or command name that produces the
#### typecheck.include

- **Type**: `string[]`
- **Default**: `['**/*.{test,spec}-d.{ts,js}']`
- **Default**: `['**/?(*.){test,spec}-d.?(c|m)[jt]s?(x)']`

Glob pattern for files that should be treated as test files

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -82,7 +82,7 @@
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,ts,tsx,vue,md}": [
"*.{[jt]s?(x),vue,md}": [
"eslint --cache --fix"
]
}
Expand Down
17 changes: 8 additions & 9 deletions packages/vitest/src/defaults.ts
@@ -1,10 +1,10 @@
import type { BenchmarkUserOptions, ResolvedCoverageOptions, UserConfig } from './types'
import { isCI } from './utils/env'

export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
export const defaultInclude = ['**/__tests__/**/*.?(c|m)[jt]s?(x)', '**/?(*.){test,spec}.?(c|m)[jt]s?(x)']
export const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*']
export const benchmarkConfigDefaults: Required<Omit<BenchmarkUserOptions, 'outputFile'>> = {
include: ['**/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
include: ['**/*.{bench,benchmark}.?(c|m)[jt]s?(x)'],
exclude: defaultExclude,
includeSource: [],
reporters: ['default'],
Expand All @@ -13,16 +13,15 @@ export const benchmarkConfigDefaults: Required<Omit<BenchmarkUserOptions, 'outpu
const defaultCoverageExcludes = [
'coverage/**',
'dist/**',
'packages/*/test{,s}/**',
'packages/*/test?(s)/**',
'**/*.d.ts',
'cypress/**',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
'test?(s)/**',
'test?(-*).?(c|m)[jt]s?(x)',
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
'**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}',
]

// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
Expand Down Expand Up @@ -91,7 +90,7 @@ const config = {
dangerouslyIgnoreUnhandledErrors: false,
typecheck: {
checker: 'tsc' as const,
include: ['**/*.{test,spec}-d.{ts,js}'],
include: ['**/?(*.){test,spec}-d.?(c|m)[jt]s?(x)'],
exclude: defaultExclude,
},
slowTestThreshold: 300,
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/benchmark.ts
Expand Up @@ -9,7 +9,7 @@ export interface BenchmarkUserOptions {
/**
* Include globs for benchmark test files
*
* @default ['**\/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
* @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
*/
include?: string[]

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/config.ts
Expand Up @@ -146,7 +146,7 @@ export interface InlineConfig {
/**
* Include globs for test files
*
* @default ['**\/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
* @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
*/
include?: string[]

Expand Down
2 changes: 1 addition & 1 deletion test/stacktraces/fixtures/vite.config.ts
Expand Up @@ -43,7 +43,7 @@ export default defineConfig({
test: {
threads: false,
isolate: false,
include: ['**/*.{test,spec}.{imba,js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
include: ['**/*.{test,spec}.{imba,?(c|m)[jt]s?(x)}'],
setupFiles: ['./setup.js'],
},
})

0 comments on commit 19ecc6c

Please sign in to comment.