-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
test(nuxt): add unit tests for watch strategies #32138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds unit tests for the Nuxt watch option to ensure that file changes trigger the correct restart behavior when using different watcher strategies.
- Adds tests for various watcher strategies including 'chokidar', 'chokidar-granular', and 'parcel'.
- Verifies that file additions in specific directories correctly trigger Nuxt restarts and builder:watch events.
WalkthroughA new test suite named ✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/test/builder.test.ts (1)
41-45
: Consider waiting for both file eventsThe test currently waits for just the first watch event before proceeding. Consider waiting for both files to be detected to ensure complete processing before closing Nuxt.
- const watchPromise = new Promise(resolve => nuxt.hooks.hookOnce('builder:watch', resolve)) + const watchPromises = [ + new Promise(resolve => nuxt.hook('builder:watch', (event, path) => { + if (event === 'add' && path.endsWith('test')) resolve() + })), + new Promise(resolve => nuxt.hook('builder:watch', (event, path) => { + if (event === 'add' && path.endsWith('other')) resolve() + })) + ] writeFileSync(join(tmpDir, 'test'), 'something') writeFileSync(join(tmpDir, 'other'), 'something') - await watchPromise + await Promise.all(watchPromises)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nuxt/test/builder.test.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/nuxt/test/builder.test.ts (1)
packages/nuxt/src/core/builder.ts (1)
build
(14-80)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: code
- GitHub Check: build
- GitHub Check: codeql (javascript-typescript)
🔇 Additional comments (7)
packages/nuxt/test/builder.test.ts (7)
1-8
: Well-structured importsThe imports are appropriately organized, separating Node.js built-ins from external dependencies, and include all necessary utilities for the test suite.
9-18
: Good test environment setup and cleanupThe test suite properly creates a temporary directory for testing and ensures it's cleaned up both before each test and after all tests complete. This follows best practices for test isolation.
19-19
: Appropriate test parameterisationUsing
it.each
with the watcher strategies array is an efficient approach to test all three strategies without code duplication. Theas const
assertion ensures type safety.
20-28
: Comprehensive Nuxt configurationThe Nuxt instance is properly configured with development mode enabled and the experimental watcher strategy set correctly. The watch paths configuration includes both a relative path ('test') and an absolute path (join(tmpDir, 'other')), which is a good test coverage decision.
29-37
: Effective event tracking setupThe test sets up appropriate hooks to count restarts and track file addition events. Converting the path to be relative to the temporary directory simplifies assertions later in the test.
48-49
: Good use of soft expectationsUsing
expect.soft()
allows all assertions to run even if earlier ones fail, which improves test diagnostics when failures occur.
1-51
: Overall well-structured testThis test suite effectively verifies that the Nuxt builder correctly detects file additions and triggers restarts across multiple watcher implementations. The test is well-structured with appropriate setup, execution, and assertions.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #32138 will not alter performanceComparing Summary
|
🔗 Linked issue
#29244
📚 Description
this adds some tests for the
watch
option