chore(e2e): add warning message for e2e in nuxt vitest setup#1691
chore(e2e): add warning message for e2e in nuxt vitest setup#1691yamachi4416 wants to merge 1 commit intonuxt:mainfrom
Conversation
commit: |
c96751f to
0103291
Compare
0103291 to
b023dd1
Compare
b023dd1 to
a59465b
Compare
📝 WalkthroughWalkthroughThis pull request introduces a Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/e2e/setup/index.ts (2)
78-82: 💤 Low valueClear and helpful warning message.
The warning effectively guides users away from using
defineVitestConfig/defineVitestProjectfor E2E tests. The condition is defensively checking both the type and value, which is acceptable.Optional: Simplify the condition
Since
__NUXT_VITEST_RESOLVED__is alwaystruewhen 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 winMove 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-errordirectives.To provide proper type support across the codebase, this declaration should be moved to a
.d.tsfile 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-errorin 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
📒 Files selected for processing (4)
examples/app-vitest-workspace/app1/test/app.nuxt.spec.tsexamples/app-vitest-workspace/app1/test/index.unit.spec.tssrc/config.tssrc/e2e/setup/index.ts
🔗 Linked issue
📚 Description
As noted in our discussion in #1690, using
defineVitestConfigfor 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