Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: improve globs #3392

Merged
merged 13 commits into from
Jun 6, 2023
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ body:
id: system-info
attributes:
label: System Info
description: Output of `npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers`
description: Output of `npx envinfo --system --npmPackages '{vite?(st),@vite{js,st}/*}' --binaries --browsers`
render: shell
placeholder: System, Binaries, Browsers
validations:
Expand Down
21 changes: 10 additions & 11 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ 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__/**/*.?([cm])[jt]s?(x)', '**/?(*.){test,spec}.?([cm])[jt]s?(x)']`
nickserv marked this conversation as resolved.
Show resolved Hide resolved

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the readability of these patterns is clear enough anymore. Maybe we should have some kind of description here exactly as Jest has? https://jestjs.io/docs/configuration#testmatch-arraystring

Just to describe what exactly is considered as test file. Especially the new special handling for __tests__ directory where even __tests__/test-utils.ts would be considered as test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheremet-va I noticed you resolved this discussion. Do you think it's unnecessary? I was going to document it, just haven't had time yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was implemented, sorry. We should definitely document it.


### exclude

- **Type:** `string[]`
- **Default:** `['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*']`
- **Default:** `['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite?(st),jest,ava,babel,nyc,cypress,tsup,build}.config.*']`
nickserv marked this conversation as resolved.
Show resolved Hide resolved

Files to exclude from the test run, using glob pattern.

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

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

Include globs for benchmark test files

Expand Down Expand Up @@ -698,16 +698,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?(-*).?([cm])[jt]s?(x)',
'**/*{.,-}{test,spec}.?([cm])[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
'**/{karma,rollup,webpack,vite?(st),jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{?([cm])js,yml}',
]
```
- **Available for providers:** `'c8' | 'istanbul'`
Expand Down Expand Up @@ -1328,7 +1327,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.?([cm])[jt]s?(x)']`

Glob pattern for files that should be treated as test files

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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
21 changes: 10 additions & 11 deletions packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -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 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 defaultInclude = ['**/__tests__/**/*.?([cm])[jt]s?(x)', '**/?(*.){test,spec}.?([cm])[jt]s?(x)']
export const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite?(st),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?(mark).?([cm])[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?(-*).?([cm])[jt]s?(x)',
'**/*{.,-}{test,spec}.?([cm])[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
'**/{karma,rollup,webpack,vite?(st),jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/.{eslint,mocha,prettier}rc.{?([cm])js,yml}',
]

// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
Expand Down Expand Up @@ -90,7 +89,7 @@ const config = {
dangerouslyIgnoreUnhandledErrors: false,
typecheck: {
checker: 'tsc' as const,
include: ['**/*.{test,spec}-d.{ts,js}'],
include: ['**/?(*.){test,spec}-d.?([cm])[jt]s?(x)'],
exclude: defaultExclude,
},
slowTestThreshold: 300,
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/benchmark.ts
Original file line number Diff line number Diff line change
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?(mark).?([cm])[jt]s?(x)']
*/
include?: string[]

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

Expand Down
2 changes: 1 addition & 1 deletion test/stacktraces/fixtures/vite.config.ts
Original file line number Diff line number Diff line change
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,?([cm]){j,t}s?(x)}'],
setupFiles: ['./setup.js'],
},
})