Skip to content

chore(e2e): add warning message for e2e in nuxt vitest setup#1691

Open
yamachi4416 wants to merge 1 commit intonuxt:mainfrom
yamachi4416:warn-when-e2e-with-nuxt-environment
Open

chore(e2e): add warning message for e2e in nuxt vitest setup#1691
yamachi4416 wants to merge 1 commit intonuxt:mainfrom
yamachi4416:warn-when-e2e-with-nuxt-environment

Conversation

@yamachi4416
Copy link
Copy Markdown
Member

@yamachi4416 yamachi4416 commented May 8, 2026

🔗 Linked issue

📚 Description

As noted in our discussion in #1690, using defineVitestConfig for E2E tests is confusing. This PR adds a warning to clarify that these are only for client-environment tests and to guide developers to the correct setup.

Reproduction

https://stackblitz.com/edit/nuxt-test-utils-pull-1691?file=package.json

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1691
npm i https://pkg.pr.new/vitest-environment-nuxt@1691

commit: a59465b

@yamachi4416 yamachi4416 force-pushed the warn-when-e2e-with-nuxt-environment branch from c96751f to 0103291 Compare May 8, 2026 23:51
@yamachi4416 yamachi4416 changed the title chore(e2e): add warning message for e2e in nuxt-environment chore(e2e): add warning message for e2e in nuxt vitest setup May 9, 2026
@yamachi4416 yamachi4416 force-pushed the warn-when-e2e-with-nuxt-environment branch from 0103291 to b023dd1 Compare May 9, 2026 00:25
@yamachi4416 yamachi4416 force-pushed the warn-when-e2e-with-nuxt-environment branch from b023dd1 to a59465b Compare May 9, 2026 03:12
@yamachi4416 yamachi4416 marked this pull request as ready for review May 9, 2026 03:24
@yamachi4416 yamachi4416 requested a review from danielroe as a code owner May 9, 2026 03:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request introduces a __NUXT_VITEST_RESOLVED__ global constant injected into Vitest/Vite configuration to detect when the Nuxt resolver is active. The configuration layer adds this signal to the Vite define map. The e2e setup module includes a runtime guard that warns users if they attempt to use the Vitest resolver for end-to-end tests. Test files validate the signal behavior: one asserts the global is true in resolved Vitest contexts, another asserts it remains undefined in isolated unit test contexts. TypeScript type declarations ensure the global is properly typed across modules.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a warning message for e2e setup in Nuxt Vitest configuration, which is the core functionality across all modified files.
Description check ✅ Passed The description is relevant to the changeset, explaining why the warning is needed (clarity about defineVitestConfig usage) and referencing the related issue #1690.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/e2e/setup/index.ts (2)

78-82: 💤 Low value

Clear and helpful warning message.

The warning effectively guides users away from using defineVitestConfig/defineVitestProject for E2E tests. The condition is defensively checking both the type and value, which is acceptable.

Optional: Simplify the condition

Since __NUXT_VITEST_RESOLVED__ is always true when defined by the Vite config, the condition could be simplified:

-  if (typeof __NUXT_VITEST_RESOLVED__ === 'boolean' && __NUXT_VITEST_RESOLVED__) {
+  if (__NUXT_VITEST_RESOLVED__ === true) {

However, the current defensive approach is also reasonable and provides extra runtime safety.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/e2e/setup/index.ts` around lines 78 - 82, Simplify the defensive runtime
check around the warning by replacing the verbose typeof/value test with a
direct truthy check of __NUXT_VITEST_RESOLVED__ in the block that logs the
console.warn (the warning block using __NUXT_VITEST_RESOLVED__); update the
condition to simply check __NUXT_VITEST_RESOLVED__ (or __NUXT_VITEST_RESOLVED__
=== true if you prefer explicitness) so the warning still prints in Vite-set
environments but the code is clearer and shorter.

91-91: ⚡ Quick win

Move type declaration to a global scope.

The declare const __NUXT_VITEST_RESOLVED__ declaration in this module-scoped file is not globally accessible, which is why test files require @ts-expect-error directives.

To provide proper type support across the codebase, this declaration should be moved to a .d.ts file or use global augmentation.

Recommended: Create a global type declaration file

Option 1: Create a new file src/types/globals.d.ts:

declare global {
  const __NUXT_VITEST_RESOLVED__: boolean | undefined
}

export {}

Option 2: Use global augmentation in this file:

-declare const __NUXT_VITEST_RESOLVED__: boolean | undefined
+declare global {
+  const __NUXT_VITEST_RESOLVED__: boolean | undefined
+}

This will eliminate the need for @ts-expect-error in test files and provide proper autocomplete and type checking.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/e2e/setup/index.ts` at line 91, The module-scoped declaration for
__NUXT_VITEST_RESOLVED__ must be moved to global scope so tests don't need
`@ts-expect-error`; create a new global declaration file (e.g., globals.d.ts) or
add a global augmentation that declares: declare global { const
__NUXT_VITEST_RESOLVED__: boolean | undefined } export {} so the symbol
__NUXT_VITEST_RESOLVED__ is available project-wide, then remove the local
declare in the e2e setup file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/e2e/setup/index.ts`:
- Around line 78-82: Simplify the defensive runtime check around the warning by
replacing the verbose typeof/value test with a direct truthy check of
__NUXT_VITEST_RESOLVED__ in the block that logs the console.warn (the warning
block using __NUXT_VITEST_RESOLVED__); update the condition to simply check
__NUXT_VITEST_RESOLVED__ (or __NUXT_VITEST_RESOLVED__ === true if you prefer
explicitness) so the warning still prints in Vite-set environments but the code
is clearer and shorter.
- Line 91: The module-scoped declaration for __NUXT_VITEST_RESOLVED__ must be
moved to global scope so tests don't need `@ts-expect-error`; create a new global
declaration file (e.g., globals.d.ts) or add a global augmentation that
declares: declare global { const __NUXT_VITEST_RESOLVED__: boolean | undefined }
export {} so the symbol __NUXT_VITEST_RESOLVED__ is available project-wide, then
remove the local declare in the e2e setup file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1b8cd5b0-4286-41a6-b7e1-33bccd99250b

📥 Commits

Reviewing files that changed from the base of the PR and between 1acb407 and a59465b.

📒 Files selected for processing (4)
  • examples/app-vitest-workspace/app1/test/app.nuxt.spec.ts
  • examples/app-vitest-workspace/app1/test/index.unit.spec.ts
  • src/config.ts
  • src/e2e/setup/index.ts

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.

1 participant