From 445916f18a3065fcabd1bac0e1a4369ad1ec1d73 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Thu, 23 May 2024 16:45:29 -0400 Subject: [PATCH] feat(testing): remove --watch=false from inferred vitest targets to keep things inlined with vitest recommendations (#25975) Users should use `vitest`, which will run with watch mode for local dev, and non-watch mode in CI. If users need to run `affected` or `run-many` locally they can always pass `--watch=false` manually. This is the same as running through npm workspaces or other monorepo tools. IMO, users should be running tests from their IDEs anyway. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- e2e/vite/src/vite-crystal.test.ts | 4 ++-- .../vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap | 4 +++- .../src/plugins/__snapshots__/plugin-with-test.spec.ts.snap | 4 +++- packages/vite/src/plugins/plugin.ts | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/e2e/vite/src/vite-crystal.test.ts b/e2e/vite/src/vite-crystal.test.ts index 5b36a4291b097..96ab29489249b 100644 --- a/e2e/vite/src/vite-crystal.test.ts +++ b/e2e/vite/src/vite-crystal.test.ts @@ -49,7 +49,7 @@ describe('@nx/vite/plugin', () => { }, 200_000); it('should test application', () => { - const result = runCLI(`test ${myApp}`); + const result = runCLI(`test ${myApp} --watch=false`); expect(result).toContain('Successfully ran target test'); }, 200_000); }); @@ -60,7 +60,7 @@ describe('@nx/vite/plugin', () => { }, 200_000); it('should test application', () => { - const result = runCLI(`test ${myVueApp}`); + const result = runCLI(`test ${myVueApp} --watch=false`); expect(result).toContain('Successfully ran target test'); }, 200_000); }); diff --git a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap index c9b3a5b294d3a..0783dd31753d7 100644 --- a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap +++ b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap @@ -17,10 +17,12 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = ` "vitest", ], }, + { + "env": "CI", + }, ], "options": { "cwd": ".", - "watch": false, }, "outputs": [ "{projectRoot}/coverage", diff --git a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap index 8935cd251350b..09f1baa108340 100644 --- a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap +++ b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap @@ -17,10 +17,12 @@ exports[`@nx/vite/plugin with test node root project should create nodes - with "vitest", ], }, + { + "env": "CI", + }, ], "options": { "cwd": ".", - "watch": false, }, "outputs": [ "{projectRoot}/coverage", diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts index 05859050971e9..f28d1b6faadbf 100644 --- a/packages/vite/src/plugins/plugin.ts +++ b/packages/vite/src/plugins/plugin.ts @@ -216,7 +216,7 @@ async function testTarget( ) { return { command: `vitest`, - options: { cwd: joinPathFragments(projectRoot), watch: false }, + options: { cwd: joinPathFragments(projectRoot) }, cache: true, inputs: [ ...('production' in namedInputs @@ -225,6 +225,7 @@ async function testTarget( { externalDependencies: ['vitest'], }, + { env: 'CI' }, ], outputs, };