Skip to content

test(utils): isolate exists() tests from real filesystem#1982

Merged
asyncapi-bot merged 3 commits intoasyncapi:masterfrom
SHUBHANSHU602:utils-isolation-fix
Feb 18, 2026
Merged

test(utils): isolate exists() tests from real filesystem#1982
asyncapi-bot merged 3 commits intoasyncapi:masterfrom
SHUBHANSHU602:utils-isolation-fix

Conversation

@SHUBHANSHU602
Copy link
Contributor

@SHUBHANSHU602 SHUBHANSHU602 commented Feb 11, 2026

Summary

This PR improves test isolation for utils.exists() in apps/generator.

Previously, the unit tests relied on the real filesystem (e.g., using process.cwd() and actual files), which introduced environment dependency and broke determinism.

Changes

  • Replaced real filesystem access with a mocked fs.promises.stat using jest.spyOn.
  • Explicitly covered both execution paths:
    • file exists → resolves true
    • file does not exist → resolves false
  • Added mock restoration to prevent cross-test side effects.

Result

  • No dependency on actual files or working directory.
  • Deterministic and environment-independent tests.
  • Aligned with existing mock-driven test patterns in the codebase.

Resolves #1873

Summary by CodeRabbit

  • Tests
    • Improved test coverage for file-existence and JS-file detection.
    • Added mock cleanup to ensure isolation and reliability.
    • Enhanced log verification and assertions for clearer failure messages.
    • Fixed test descriptions and formatting for readability.

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

⚠️ No Changeset found

Latest commit: ae0f469

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Adds a top-level fs import to the test file, tightens #exists tests by restoring mocks after each test and mocking fs.promises.stat for success and failure cases (including log assertion), updates test descriptions, and adjusts spacing in the #isJsFile describe header.

Changes

Cohort / File(s) Summary
Test Suite Improvements
apps/generator/test/utils.test.js
Added const fs = require('fs'); renamed a test description; added afterEach to restore mocks; mocked fs.promises.stat for existing and non-existing file cases; asserted fs.constants.F_OK usage and log message format; fixed spacing in describe('#isJsFile', ...).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format with 'test:' prefix, uses imperative mood ('isolate'), and clearly describes the main change of mocking filesystem access in tests.
Linked Issues check ✅ Passed The PR fully addresses all coding objectives from #1873: mocks fs.promises.stat, removes real filesystem dependency, explicitly tests both file-exists and file-not-exists cases, restores mocks after each test, and follows existing mock-driven patterns.
Out of Scope Changes check ✅ Passed All changes are scoped to improving test isolation for utils.exists(). Minor formatting changes (test description, describe header spacing) are incidental improvements within the test file scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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

@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: 1

🤖 Fix all issues with AI agents
In `@apps/generator/test/utils.test.js`:
- Line 58: Update the test description string in the unit test for URL handling:
change the it block title from 'doesnot work with a url' to 'does not work with
a url' in the test function (the it(...) around the URL test) so the description
reads correctly; no other behavior changes required.

@SHUBHANSHU602
Copy link
Contributor Author

hey @Adi-204 if this one is good Please have a look at issue #1981 , while working on the utilis.test.js I found that the test coverage of ulitis.js and parser.js is quite poor , so I would love to take this while I am working same file.

@Adi-204 Adi-204 self-assigned this Feb 12, 2026
@Adi-204 Adi-204 moved this to In Progress in Maintainers work Feb 12, 2026
Copy link
Member

@Adi-204 Adi-204 left a comment

Choose a reason for hiding this comment

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

@SHUBHANSHU602 left few comments

@sonarqubecloud
Copy link

@derberg
Copy link
Member

derberg commented Feb 18, 2026

/rtm

@asyncapi-bot asyncapi-bot merged commit 8c7551e into asyncapi:master Feb 18, 2026
16 of 18 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Maintainers work Feb 18, 2026
@derberg derberg moved this from Done to Archive in Maintainers work Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Archive

Development

Successfully merging this pull request may close these issues.

[BUG] :Unit tests for utils.exists() rely on real filesystem, breaking test isolation and determinism

4 participants

Comments