Skip to content

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

Merged
merged 2 commits into from
May 17, 2025
Merged

test(nuxt): add unit tests for watch strategies #32138

merged 2 commits into from
May 17, 2025

Conversation

danielroe
Copy link
Member

🔗 Linked issue

#29244

📚 Description

this adds some tests for the watch option

@Copilot Copilot AI review requested due to automatic review settings May 17, 2025 18:16
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

@Copilot Copilot AI left a 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.

Copy link

coderabbitai bot commented May 17, 2025

Walkthrough

A new test suite named builder:watch has been added to the Nuxt builder test file. This suite tests the builder's restart behaviour when files are added under three different watcher strategies: chokidar, chokidar-granular, and parcel. The tests set up a temporary directory, configure Nuxt to watch specific paths, and listen for builder restart and file watch events. Files are then added to the watched directories to trigger these events. The tests assert that the builder restarts twice and that the correct files are detected, ensuring consistent file watching across all strategies.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch test/watchers
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/nuxt/test/builder.test.ts (1)

41-45: Consider waiting for both file events

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9473c6d and 48b694a.

📒 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 imports

The 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 cleanup

The 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 parameterisation

Using it.each with the watcher strategies array is an efficient approach to test all three strategies without code duplication. The as const assertion ensures type safety.


20-28: Comprehensive Nuxt configuration

The 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 setup

The 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 expectations

Using expect.soft() allows all assertions to run even if earlier ones fail, which improves test diagnostics when failures occur.


1-51: Overall well-structured test

This 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.

Copy link

pkg-pr-new bot commented May 17, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32138

nuxt

npm i https://pkg.pr.new/nuxt@32138

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32138

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32138

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32138

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32138

commit: 48b694a

Copy link

codspeed-hq bot commented May 17, 2025

CodSpeed Performance Report

Merging #32138 will not alter performance

Comparing test/watchers (48b694a) with main (146acb7)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe merged commit a4326de into main May 17, 2025
47 checks passed
@danielroe danielroe deleted the test/watchers branch May 17, 2025 18:32
@github-actions github-actions bot mentioned this pull request May 17, 2025
@github-actions github-actions bot mentioned this pull request May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy