From f5b436c6e1d8216f80d7daae452679d0e4460b9d Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 11:20:43 +0100 Subject: [PATCH 01/13] feat: check related against forceRerunTriggers --- packages/vitest/src/node/core.ts | 4 ++++ pnpm-lock.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index d31b0c1e1505..2cac57f3eb10 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -189,6 +189,10 @@ export class Vitest { if (!related) return tests + const forceRerunTriggers = this.config.forceRerunTriggers + if (forceRerunTriggers.length && mm(related, forceRerunTriggers)) + return tests + // don't run anything if no related sources are found if (!related.length) return [] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da25c0660e89..e0e873b54ba3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15235,7 +15235,7 @@ packages: dev: true /lz-string/1.4.4: - resolution: {integrity: sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=} + resolution: {integrity: sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==} hasBin: true dev: true From aa0c36f17a527627839808439ece8ae3729f861e Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 11:29:05 +0100 Subject: [PATCH 02/13] chore: fix lock --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0e873b54ba3..da25c0660e89 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15235,7 +15235,7 @@ packages: dev: true /lz-string/1.4.4: - resolution: {integrity: sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==} + resolution: {integrity: sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=} hasBin: true dev: true From 37451a0b3bebf4370b35d58dc03b321f8d4c8d38 Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:57:30 +0100 Subject: [PATCH 03/13] check length of micromatch --- packages/vitest/src/node/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 2cac57f3eb10..108d1a44126c 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -190,7 +190,7 @@ export class Vitest { return tests const forceRerunTriggers = this.config.forceRerunTriggers - if (forceRerunTriggers.length && mm(related, forceRerunTriggers)) + if (forceRerunTriggers.length && mm(related, forceRerunTriggers).length) return tests // don't run anything if no related sources are found From 363d9268422821444e91e5859295da59c0dc545f Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:58:17 +0100 Subject: [PATCH 04/13] add execa --- pnpm-lock.yaml | 4 +++- test/related/package.json | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da25c0660e89..dd44ec99a7bf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: @@ -6335,7 +6337,7 @@ packages: dev: true /@types/form-data/0.0.33: - resolution: {integrity: sha512-8BSvG1kGm83cyJITQMZSulnl6QV8jqAGreJsc5tPu1Jq0vTSOiY/k24Wx82JRpWwZSqrala6sd5rWi6aNXvqcw==} + resolution: {integrity: sha1-yayFsqX9GENbjIXZ7LUObWyJP/g=} dependencies: '@types/node': 17.0.40 dev: true diff --git a/test/related/package.json b/test/related/package.json index c063a9e6e04c..59223d356a26 100644 --- a/test/related/package.json +++ b/test/related/package.json @@ -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 run related src/sourceA.ts --globals", + "test:rerun": "vitest run rerun" }, "devDependencies": { + "execa": "^6.1.0", "vitest": "workspace:*" } } From 8dba05710ebff9a56ba6e287f07ae53f877c4ca9 Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:58:31 +0100 Subject: [PATCH 05/13] add force-rerun tests and vitest config --- test/related/force-rerun.vitest.config.ts | 8 ++++++++ test/related/tests/force-rerun.test.ts | 24 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/related/force-rerun.vitest.config.ts create mode 100644 test/related/tests/force-rerun.test.ts diff --git a/test/related/force-rerun.vitest.config.ts b/test/related/force-rerun.vitest.config.ts new file mode 100644 index 000000000000..024909c6a773 --- /dev/null +++ b/test/related/force-rerun.vitest.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + include: ['tests/related.test.ts'], + forceRerunTriggers: ['**/rerun.temp/**'], + }, +}) diff --git a/test/related/tests/force-rerun.test.ts b/test/related/tests/force-rerun.test.ts new file mode 100644 index 000000000000..b8f938c3ff9b --- /dev/null +++ b/test/related/tests/force-rerun.test.ts @@ -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, '', error => console.error(error)) + const { stdout } = await run() + expect(stdout).toContain('1 passed') + }) + + 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') + }) +}) From 497c33c9231c2f21327ed78b0d96540880160b4c Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:09:05 +0100 Subject: [PATCH 06/13] update docs --- docs/config/index.md | 2 +- docs/guide/cli.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index cb8b8eacc7ac..85a129fa9e2f 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -374,7 +374,7 @@ Glob pattern of file paths to be ignored from triggering watch rerun. - **Type**: `string[]` - **Default:** `[]` -Glob patter of file paths that will trigger the whole suite rerun. +Glob patter of file paths that will trigger the whole suite rerun. This 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: diff --git a/docs/guide/cli.md b/docs/guide/cli.md index e43fccc19775..7777795025b7 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -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` From 8d73fe4dd352ea367ed9e8d3a09b3f473ab4c30c Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:19:13 +0100 Subject: [PATCH 07/13] watch false on related --- test/related/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/related/package.json b/test/related/package.json index 59223d356a26..4015ccb31e0a 100644 --- a/test/related/package.json +++ b/test/related/package.json @@ -3,9 +3,10 @@ "private": true, "scripts": { "test": "nr test:related && nr test:rerun", - "test:related": "vitest run related src/sourceA.ts --globals", + "test:related": "vitest related src/sourceA.ts --globals --watch=false", "test:rerun": "vitest run rerun" }, + "devDependencies": { "execa": "^6.1.0", "vitest": "workspace:*" From 7c6b2bfff6fc2115a024486938d4a158a0b90d1d Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:26:34 +0100 Subject: [PATCH 08/13] typo --- docs/config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 85a129fa9e2f..e2b75cc3877e 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -374,7 +374,7 @@ Glob pattern of file paths to be ignored from triggering watch rerun. - **Type**: `string[]` - **Default:** `[]` -Glob patter of file paths that will trigger the whole suite rerun. This paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff. +Glob pattern of file paths that will trigger the whole suite rerun. This 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: From 1171d462c2163c33d411827b24319408825883fc Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:30:49 +0100 Subject: [PATCH 09/13] linting --- test/related/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/test/related/package.json b/test/related/package.json index 4015ccb31e0a..1d0653ebf985 100644 --- a/test/related/package.json +++ b/test/related/package.json @@ -6,7 +6,6 @@ "test:related": "vitest related src/sourceA.ts --globals --watch=false", "test:rerun": "vitest run rerun" }, - "devDependencies": { "execa": "^6.1.0", "vitest": "workspace:*" From 0e6a9a54516b89d927ad89e39a3e98a8e2baadcc Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Mon, 4 Jul 2022 22:28:24 +0100 Subject: [PATCH 10/13] fix lock and add timeout to tests --- pnpm-lock.yaml | 2 +- test/related/tests/force-rerun.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dd44ec99a7bf..3acdc0234731 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6337,7 +6337,7 @@ packages: dev: true /@types/form-data/0.0.33: - resolution: {integrity: sha1-yayFsqX9GENbjIXZ7LUObWyJP/g=} + resolution: {integrity: sha512-8BSvG1kGm83cyJITQMZSulnl6QV8jqAGreJsc5tPu1Jq0vTSOiY/k24Wx82JRpWwZSqrala6sd5rWi6aNXvqcw==} dependencies: '@types/node': 17.0.40 dev: true diff --git a/test/related/tests/force-rerun.test.ts b/test/related/tests/force-rerun.test.ts index b8f938c3ff9b..11331a43f072 100644 --- a/test/related/tests/force-rerun.test.ts +++ b/test/related/tests/force-rerun.test.ts @@ -15,10 +15,10 @@ describe('forceRerunTrigger', () => { writeFile(fileName, '', error => console.error(error)) 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) }) From 1d52d9a3d72e3cff04d3193045d3fb8d5607df79 Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Tue, 5 Jul 2022 08:23:33 +0100 Subject: [PATCH 11/13] add defaults to forceRerunTriggers --- docs/config/index.md | 2 +- packages/vitest/src/defaults.ts | 7 ++++++- test/related/tests/force-rerun.test.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index e2b75cc3877e..5d8af166e715 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -372,7 +372,7 @@ Glob pattern of file paths to be ignored from triggering watch rerun. ### forceRerunTriggers - **Type**: `string[]` -- **Default:** `[]` +- **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**', '**/dist/**']` Glob pattern of file paths that will trigger the whole suite rerun. This paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff. diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index d757080c296a..843ba46cc82b 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -62,7 +62,12 @@ const config = { hookTimeout: 10000, isolate: true, watchExclude: ['**/node_modules/**', '**/dist/**'], - forceRerunTriggers: [], + forceRerunTriggers: [ + '**/package.json/**', + '**/vitest.config.*/**', + '**/vite.config.*/**', + '**/dist/**', + ], update: false, reporters: [], silent: false, diff --git a/test/related/tests/force-rerun.test.ts b/test/related/tests/force-rerun.test.ts index 11331a43f072..420c15269023 100644 --- a/test/related/tests/force-rerun.test.ts +++ b/test/related/tests/force-rerun.test.ts @@ -12,7 +12,7 @@ describe('forceRerunTrigger', () => { }) it('should run the whole test suite if file exists', async () => { - writeFile(fileName, '', error => console.error(error)) + writeFile(fileName, '', () => {}) const { stdout } = await run() expect(stdout).toContain('1 passed') }, 60_000) From 95bd18e2803a41ffb47ca09a09b22fe5148dc10d Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 5 Jul 2022 10:45:59 +0300 Subject: [PATCH 12/13] chore: remove dist from forceRerunTriggers --- docs/config/index.md | 2 +- packages/vitest/src/defaults.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 5d8af166e715..33fe47ed1e42 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -372,7 +372,7 @@ Glob pattern of file paths to be ignored from triggering watch rerun. ### forceRerunTriggers - **Type**: `string[]` -- **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**', '**/dist/**']` +- **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']` Glob pattern of file paths that will trigger the whole suite rerun. This paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff. diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index 843ba46cc82b..71bd641ac6c6 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -66,7 +66,6 @@ const config = { '**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**', - '**/dist/**', ], update: false, reporters: [], From 273a7c8735c49fb44673910d9f77eb39bce08b18 Mon Sep 17 00:00:00 2001 From: Elliot Westlake <17042376+elliotwestlake@users.noreply.github.com> Date: Tue, 5 Jul 2022 08:55:35 +0100 Subject: [PATCH 13/13] Wording --- docs/config/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 33fe47ed1e42..9b8322239046 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -374,7 +374,7 @@ Glob pattern of file paths to be ignored from triggering watch rerun. - **Type**: `string[]` - **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']` -Glob pattern of file paths that will trigger the whole suite rerun. This paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff. +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: