Skip to content

feat(nx-plugin): add vitest support for e2e tests#34041

Draft
Copilot wants to merge 24 commits intomasterfrom
copilot/add-vitest-support-e2e
Draft

feat(nx-plugin): add vitest support for e2e tests#34041
Copilot wants to merge 24 commits intomasterfrom
copilot/add-vitest-support-e2e

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

Implementation Plan for Vitest E2E Support

Changes Required:

  • Update plugin generator schema to support "vitest" as an e2eTestRunner option
  • Update e2e-project generator schema to add testRunner option
  • Update e2e-project generator implementation
    • Add new function addVitest() similar to addJest()
    • Update e2eProjectGeneratorInternal to conditionally call addJest or addVitest
    • Handle both .ts and .mts vitest config extensions
    • Address all code review feedback
    • Use ensurePackage for dynamic vitest import
    • Fix syntax errors
  • Update test template files
  • Update plugin generator to pass testRunner to e2e-project generator
  • Add tests for new functionality
    • Add unit tests
    • Add e2e test for vitest-backed plugin
  • Update documentation
  • Code review and refinement
    • Address all review feedback
    • Fix CI/Build failures (add @nx/vitest as optional peer dependency)

Changes

  • Schema updates: Added "vitest" to e2eTestRunner enum in @nx/plugin:plugin generator; added testRunner option to @nx/plugin:e2e-project generator
  • Implementation: Added addVitest() function that configures Vitest with globalSetup/globalTeardown for local registry management, uses fork pool with singleFork for proper isolation
  • Config handling: Detects .mts or .ts vitest config files, extracts existing indentation for consistent formatting when injecting global setup/teardown
  • Dependencies: Uses ensurePackage to dynamically import @nx/vitest only when needed; added as optional peer dependency
  • Testing: Added e2e test to verify vitest-backed plugins work correctly

Usage

# Generate plugin with Vitest e2e tests
nx g @nx/plugin:plugin my-plugin --e2eTestRunner=vitest

# Or generate e2e project separately
nx g @nx/plugin:e2e-project --pluginName my-plugin --testRunner vitest

Jest remains the default when no testRunner is specified.

Original prompt

This section details on the original issue you should resolve

<issue_title>vitest support for @nrwl/nx-plugin:e2e</issue_title>
<issue_description>

Description

I'd like to use Vitest instead of Jest for e2e testing of plugins.

Motivation

I use Vitest for everything else and it makes sense to use it for that as well.

Suggested Implementation

Add option for nx g @nrwl/nx-plugin:plugin to use Vitest

Alternate Implementations

I'm going to skip e2e tests altogether for now as I'm having trouble with Jest and my custom ESM setup.</issue_description>

<agent_instructions>This shouldn't be terribly difficult, you'll need to add a schema option for the e2e test runner to be possible to set it to vitest and scaffold a vitest project instead of a jest project. You'll likely need a separate set of templates for the generated e2e setup, since the current ones are jest tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@FrozenPandaz Would someone like to open a PR for this? @AgentEnder Reiterating what @FrozenPandaz said, nothing is technically blocking this feature. It should be as easy as adding a schema option and passing it through to the js generator, but we don't quite have the bandwidth to do this on the core team right now.

It would be a great first issue for a community member.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nx-dev Ready Ready Preview Jan 22, 2026 8:31pm

Request Review

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 7, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 4c65167
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69e3b81cd3d1f00008bc497b
😎 Deploy Preview https://deploy-preview-34041--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Add Vitest support for e2e testing of plugins feat(plugin): add vitest support for e2e tests Jan 7, 2026
Copilot AI requested a review from AgentEnder January 7, 2026 20:21
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jan 7, 2026

View your CI Pipeline Execution ↗ for commit 4c65167

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 7m 1s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 17s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 24s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 15s View ↗
nx affected -t e2e-macos-local --parallel=1 --b... ✅ Succeeded 28m 48s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-18 17:36:25 UTC

addProjectConfiguration(host, options.projectName, projectConfiguration);
}

const vitestTask = await vitestConfigurationGenerator(host, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot This call should use ensurePackage, as vitest may not be installed yet. We can't directly import this, though we can import it's types so we can reference them in the dynamic import.

coverageProvider should likely be null, since its e2e we wouldn't really collect coverage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use ensurePackage for dynamic import of @nx/vitest and removed explicit coverageProvider since it will use the default. Changes in commit bcce4fe.

Comment on lines +248 to +249
expect(vitestConfig).toContain('globalSetup');
expect(vitestConfig).toContain('globalTeardown');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets add an e2e test to e2e/plugin that tests that these work for vitest backed plugins, I'm a bit hesitant without it. @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added e2e test in e2e/plugin/src/nx-plugin.test.ts that verifies plugins can be generated with vitest as the e2e test runner and that the tests execute successfully. Commit 6add8ac.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

@AgentEnder
Copy link
Copy Markdown
Member

Nx Cloud is proposing a fix for your failed CI:

These changes fix the ESLint dependency-checks error by adding @nx/vitest to the dependencies section of packages/plugin/package.json. The PR introduced code that imports from @nx/vitest/generators, creating a runtime dependency that was not declared in the package manifest.

We verified this fix by re-running plugin:lint.

diff --git a/packages/plugin/package.json b/packages/plugin/package.json
index 9c8f175788..279050c071 100644
--- a/packages/plugin/package.json
+++ b/packages/plugin/package.json
@@ -31,7 +31,8 @@
     "@nx/devkit": "workspace:*",
     "@nx/jest": "workspace:*",
     "@nx/js": "workspace:*",
-    "@nx/eslint": "workspace:*"
+    "@nx/eslint": "workspace:*",
+    "@nx/vitest": "workspace:*"
   },
   "devDependencies": {
     "nx": "workspace:*"

[!NOTE]
Auto-apply was skipped. The previous CI pipeline execution was triggered by Nx Cloud

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally J7A3-AuSY

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 Learn more about Self-Healing CI on nx.dev

@copilot this is close, but it should be an optional peer dep

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 7, 2026

Nx Cloud is proposing a fix for your failed CI:

These changes fix the ESLint dependency-checks error by adding @nx/vitest to the dependencies section of packages/plugin/package.json. The PR ...

Added @nx/vitest as an optional peer dependency in package.json following the same pattern as other optional dependencies in the monorepo. Commit 37cacee.

Copilot AI and others added 9 commits April 2, 2026 12:37
- Initialize vitestConfigPath with undefined to avoid uninitialized variable
- Add explicit error handling when vitest config file is not found
- Add comment explaining mts extension precedence
- Store regex in variable for better readability

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
- Extract indentation from existing config for consistent formatting
- Add better error handling for test config block not found
- Remove redundant undefined initialization
- Insert globalSetup/globalTeardown as separate lines to avoid overwriting existing properties

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
…eProvider

- Use ensurePackage to dynamically import @nx/vitest since it may not be installed yet
- Import VitestGeneratorSchema type for type safety
- Remove explicit coverageProvider since e2e tests don't need coverage collection

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Add end-to-end test to verify that plugins can be generated with vitest
as the e2e test runner and that the e2e tests execute successfully.

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
Co-authored-by: Copilot <Copilot@users.noreply.github.com>
Add @nx/vitest as an optional peer dependency instead of a regular
dependency to properly declare the runtime dependency while keeping
it optional for users who don't use vitest for e2e tests.

Co-authored-by: AgentEnder <6933928+AgentEnder@users.noreply.github.com>
@AgentEnder AgentEnder force-pushed the copilot/add-vitest-support-e2e branch from 0492be6 to 7fe23b8 Compare April 2, 2026 16:37
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

Nx Cloud has identified a flaky task in your failed CI:

Note

We tried rerunning the flaky task 5 times, but the task is still failing. You can trigger a rerun manually, or investigate the task.

Trigger a rerun:

Rerun CI

Or trigger a rerun manually by pushing an empty commit:

git commit --allow-empty -m "chore: trigger rerun"
git push

Nx Cloud View detailed reasoning in Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vitest support for @nrwl/nx-plugin:e2e

3 participants