Skip to content

Commit 7063d4d

Browse files
authored
docs(migration): add excludes section (#9041)
1 parent 042c60c commit 7063d4d

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

docs/guide/migration.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,44 @@ See also new guides:
7171
- [Including and excluding files from coverage report](/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples
7272
- [Profiling Test Performance | Code coverage](/guide/profiling-test-performance.html#code-coverage) for tips about debugging coverage generation
7373

74+
### Simplified `exclude`
75+
76+
By default, Vitest now only excludes tests from `node_modules` and `.git` folders. This means that Vitest no longer excludes:
77+
78+
- `dist` and `cypress` folders
79+
- `.idea`, `.cache`, `.output`, `.temp` folders
80+
- config files like `rollup.config.js`, `prettier.config.js`, `ava.config.js` and so on
81+
82+
If you need to limit the directory where your tests files are located, use the [`test.dir`](/config/dir) option instead because it is more performant than excluding files:
83+
84+
```ts
85+
import { configDefaults, defineConfig } from 'vitest/config'
86+
87+
export default defineConfig({
88+
test: {
89+
dir: './frontend/tests', // [!code ++]
90+
},
91+
})
92+
```
93+
94+
To restore the previous behaviour, specify old `excludes` manually:
95+
96+
```ts
97+
import { configDefaults, defineConfig } from 'vitest/config'
98+
99+
export default defineConfig({
100+
test: {
101+
exclude: [
102+
...configDefaults.exclude,
103+
'**/dist/**', // [!code ++]
104+
'**/cypress/**', // [!code ++]
105+
'**/.{idea,git,cache,output,temp}/**', // [!code ++]
106+
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*' // [!code ++]
107+
],
108+
},
109+
})
110+
```
111+
74112
### `spyOn` and `fn` Support Constructors
75113

76114
Previously, if you tried to spy on a constructor with `vi.spyOn`, you would get an error like `Constructor <name> requires 'new'`. Since Vitest 4, all mocks called with a `new` keyword construct the instance instead of calling `mock.apply`. This means that the mock implementation has to use either the `function` or the `class` keyword in these cases:

0 commit comments

Comments
 (0)