mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
feat: check related against forceRerunTriggers (#1595)
* feat: check related against forceRerunTriggers * chore: fix lock * check length of micromatch * add execa * add force-rerun tests and vitest config * update docs * watch false on related * typo * linting * fix lock and add timeout to tests * add defaults to forceRerunTriggers * chore: remove dist from forceRerunTriggers * Wording Co-authored-by: Vladimir Sheremet <sheremet.va@icloud.com>
This commit is contained in:
parent
0a642c6e57
commit
40fc526e55
@ -372,9 +372,9 @@ Glob pattern of file paths to be ignored from triggering watch rerun.
|
||||
### forceRerunTriggers
|
||||
|
||||
- **Type**: `string[]`
|
||||
- **Default:** `[]`
|
||||
- **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']`
|
||||
|
||||
Glob patter of file paths that will trigger the whole suite rerun.
|
||||
Glob pattern of file paths that will trigger the whole suite rerun. When paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff.
|
||||
|
||||
Useful if you are testing calling CLI commands, because Vite cannot construct a module graph:
|
||||
|
||||
|
||||
@ -83,6 +83,8 @@ Clears cache folder.
|
||||
|
||||
To run tests against changes made in the last commit, you can use `--changed HEAD~1`. You can also pass commit hash or branch name.
|
||||
|
||||
If paired with the `forceRerunTriggers` config option it will run the whole test suite if a match is found.
|
||||
|
||||
### shard
|
||||
|
||||
- **Type**: `string`
|
||||
|
||||
@ -62,7 +62,11 @@ const config = {
|
||||
hookTimeout: 10000,
|
||||
isolate: true,
|
||||
watchExclude: ['**/node_modules/**', '**/dist/**'],
|
||||
forceRerunTriggers: [],
|
||||
forceRerunTriggers: [
|
||||
'**/package.json/**',
|
||||
'**/vitest.config.*/**',
|
||||
'**/vite.config.*/**',
|
||||
],
|
||||
update: false,
|
||||
reporters: [],
|
||||
silent: false,
|
||||
|
||||
@ -189,6 +189,10 @@ export class Vitest {
|
||||
if (!related)
|
||||
return tests
|
||||
|
||||
const forceRerunTriggers = this.config.forceRerunTriggers
|
||||
if (forceRerunTriggers.length && mm(related, forceRerunTriggers).length)
|
||||
return tests
|
||||
|
||||
// don't run anything if no related sources are found
|
||||
if (!related.length)
|
||||
return []
|
||||
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@ -848,8 +848,10 @@ importers:
|
||||
|
||||
test/related:
|
||||
specifiers:
|
||||
execa: ^6.1.0
|
||||
vitest: workspace:*
|
||||
devDependencies:
|
||||
execa: 6.1.0
|
||||
vitest: link:../../packages/vitest
|
||||
|
||||
test/reporters:
|
||||
|
||||
8
test/related/force-rerun.vitest.config.ts
Normal file
8
test/related/force-rerun.vitest.config.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['tests/related.test.ts'],
|
||||
forceRerunTriggers: ['**/rerun.temp/**'],
|
||||
},
|
||||
})
|
||||
@ -2,9 +2,12 @@
|
||||
"name": "@vitest/test-related",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest related src/sourceA.ts --globals"
|
||||
"test": "nr test:related && nr test:rerun",
|
||||
"test:related": "vitest related src/sourceA.ts --globals --watch=false",
|
||||
"test:rerun": "vitest run rerun"
|
||||
},
|
||||
"devDependencies": {
|
||||
"execa": "^6.1.0",
|
||||
"vitest": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
||||
24
test/related/tests/force-rerun.test.ts
Normal file
24
test/related/tests/force-rerun.test.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { unlink, writeFile } from 'fs'
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import { execa } from 'execa'
|
||||
|
||||
const run = async () => await execa('vitest', ['run', '--changed', '--config', 'force-rerun.vitest.config.ts'])
|
||||
|
||||
const fileName = 'rerun.temp'
|
||||
|
||||
describe('forceRerunTrigger', () => {
|
||||
beforeEach(async () => {
|
||||
unlink(fileName, () => {})
|
||||
})
|
||||
|
||||
it('should run the whole test suite if file exists', async () => {
|
||||
writeFile(fileName, '', () => {})
|
||||
const { stdout } = await run()
|
||||
expect(stdout).toContain('1 passed')
|
||||
}, 60_000)
|
||||
|
||||
it('should run no tests if file does not exist', async () => {
|
||||
const { stdout } = await run()
|
||||
expect(stdout).toContain('No test files found, exiting with code 0')
|
||||
}, 60_000)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user