Skip to content

fix: lookupFiles() now returns string[] for direct file paths#5941

Merged
JoshuaKGoldberg merged 3 commits into
mochajs:mainfrom
maniktyagi04:fix/lookup-files-returns-string-not-array
May 18, 2026
Merged

fix: lookupFiles() now returns string[] for direct file paths#5941
JoshuaKGoldberg merged 3 commits into
mochajs:mainfrom
maniktyagi04:fix/lookup-files-returns-string-not-array

Conversation

@maniktyagi04
Copy link
Copy Markdown
Contributor

@maniktyagi04 maniktyagi04 commented May 4, 2026

PR Checklist

Overview

This PR addresses a return-type inconsistency in lookupFiles(). As documented in its JSDoc, the function should return string[], but it was returning a bare string when a direct file path was provided.

Changes

  • Modified lib/cli/lookup-files.mjs to wrap direct file path returns in an array.

Verified locally using smoke tests and by confirming Array.isArray() on the return value for direct file paths.

Previously, when a file path was passed directly (not a glob or
directory), the function returned a bare string, violating its
documented return type of string[].

Closes mochajs#5940
Copilot AI review requested due to automatic review settings May 4, 2026 19:59
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 4, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions

This comment has been minimized.

@maniktyagi04 maniktyagi04 changed the title fix: lookupFiles() now returns string[] fo### What changedr direct file paths fix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] fo### What changedr direct file paths May 4, 2026
@maniktyagi04 maniktyagi04 changed the title fix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] fo### What changedr direct file paths fix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] fo### What changedr direct file paths May 4, 2026
Copy link
Copy Markdown
Contributor

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 fixes a return-type inconsistency in Mocha’s CLI file-discovery helper lookupFiles(): when an existing direct file path is provided (not a glob or directory), it now returns a string[] (singleton array) instead of a bare string, matching the function’s documented JSDoc return type.

Changes:

  • Adjusted the direct-filepath short-circuit in lookupFiles() to return [filepath] instead of filepath.

Comment thread lib/cli/lookup-files.mjs
@maniktyagi04 maniktyagi04 changed the title fix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] for direct file pathsfix: lookupFiles() now returns string[] fo### What changedr direct file paths fix: lookupFiles() now returns string[] for direct file paths May 4, 2026
@JoshuaKGoldberg
Copy link
Copy Markdown
Member

🤔🤔🤔

@maniktyagi04
Copy link
Copy Markdown
Contributor Author

@JoshuaKGoldberg
Thanks for pointing that out! I tried removing/updating that checklist item, but the automated PR checks require it to be present and checked, otherwise the build fails. So I’ve kept it as-is to satisfy CI.

Happy to adjust if there’s an alternative way to handle this.

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.85%. Comparing base (724fb50) to head (8a4b980).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5941   +/-   ##
=======================================
  Coverage   80.85%   80.85%           
=======================================
  Files          64       64           
  Lines        4566     4566           
  Branches      977      958   -19     
=======================================
  Hits         3692     3692           
  Misses        874      874           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JoshuaKGoldberg
Copy link
Copy Markdown
Member

Unrelated integration test flake, I believe.

@JoshuaKGoldberg JoshuaKGoldberg merged commit 4718476 into mochajs:main May 18, 2026
223 of 225 checks passed
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.

bug: lookupFiles() returns a string instead of string[] when given a direct file path

3 participants