Skip to content

Commit 19ecc6c

Browse files
authoredJun 6, 2023
fix!: improve globs (#3392)
1 parent 1ad63b0 commit 19ecc6c

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed
 

‎docs/config/index.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ All configuration options that are not supported inside a [workspace](/guide/wor
8181
### include
8282

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

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

@@ -226,7 +226,7 @@ Options used when running `vitest bench`.
226226
#### benchmark.include
227227

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

231231
Include globs for benchmark test files
232232

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

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

13631362
Glob pattern for files that should be treated as test files
13641363

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"pre-commit": "npx lint-staged"
8383
},
8484
"lint-staged": {
85-
"*.{js,ts,tsx,vue,md}": [
85+
"*.{[jt]s?(x),vue,md}": [
8686
"eslint --cache --fix"
8787
]
8888
}

‎packages/vitest/src/defaults.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { BenchmarkUserOptions, ResolvedCoverageOptions, UserConfig } from './types'
22
import { isCI } from './utils/env'
33

4-
export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
4+
export const defaultInclude = ['**/__tests__/**/*.?(c|m)[jt]s?(x)', '**/?(*.){test,spec}.?(c|m)[jt]s?(x)']
55
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.*']
66
export const benchmarkConfigDefaults: Required<Omit<BenchmarkUserOptions, 'outputFile'>> = {
7-
include: ['**/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
7+
include: ['**/*.{bench,benchmark}.?(c|m)[jt]s?(x)'],
88
exclude: defaultExclude,
99
includeSource: [],
1010
reporters: ['default'],
@@ -13,16 +13,15 @@ export const benchmarkConfigDefaults: Required<Omit<BenchmarkUserOptions, 'outpu
1313
const defaultCoverageExcludes = [
1414
'coverage/**',
1515
'dist/**',
16-
'packages/*/test{,s}/**',
16+
'packages/*/test?(s)/**',
1717
'**/*.d.ts',
1818
'cypress/**',
19-
'test{,s}/**',
20-
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
21-
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
22-
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
19+
'test?(s)/**',
20+
'test?(-*).?(c|m)[jt]s?(x)',
21+
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
2322
'**/__tests__/**',
2423
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
25-
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
24+
'**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}',
2625
]
2726

2827
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
@@ -91,7 +90,7 @@ const config = {
9190
dangerouslyIgnoreUnhandledErrors: false,
9291
typecheck: {
9392
checker: 'tsc' as const,
94-
include: ['**/*.{test,spec}-d.{ts,js}'],
93+
include: ['**/?(*.){test,spec}-d.?(c|m)[jt]s?(x)'],
9594
exclude: defaultExclude,
9695
},
9796
slowTestThreshold: 300,

‎packages/vitest/src/types/benchmark.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface BenchmarkUserOptions {
99
/**
1010
* Include globs for benchmark test files
1111
*
12-
* @default ['**\/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
12+
* @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
1313
*/
1414
include?: string[]
1515

‎packages/vitest/src/types/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export interface InlineConfig {
146146
/**
147147
* Include globs for test files
148148
*
149-
* @default ['**\/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
149+
* @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
150150
*/
151151
include?: string[]
152152

‎test/stacktraces/fixtures/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default defineConfig({
4343
test: {
4444
threads: false,
4545
isolate: false,
46-
include: ['**/*.{test,spec}.{imba,js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
46+
include: ['**/*.{test,spec}.{imba,?(c|m)[jt]s?(x)}'],
4747
setupFiles: ['./setup.js'],
4848
},
4949
})

0 commit comments

Comments
 (0)
Please sign in to comment.