Skip to content
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

🚀 Feature: Change default value for --ignore to **/node_modules, **/.git #5131

Open
3 tasks done
Danielku15 opened this issue Mar 31, 2024 · 4 comments
Open
3 tasks done
Labels
semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Milestone

Comments

@Danielku15
Copy link

Danielku15 commented Mar 31, 2024

Feature Request Checklist

Overview

Looking at the current behavior of Mocha there is an inconsistency between normal execution and watch execution due to different defaults in --ignore and --watch-ignore.

I think many devs will agree that picking up data from the node_modules folder is not in their interest when maintaining any project and running tests.

Additionally the node_modules folder might live in a subfolder (mono repos) but still is subject of being ignored. The current pattern only ignores node_modules on the level of the mocharc config file.

Suggested Solution

  1. The default values for the two options should be set to the same value.
  2. The default patterns should also ignore these folders if they are in subfolders.

Hence the new default for both options should be similar to: ['**/node_modules/', '**/.git/']

Alternatives

If this is the intended behavior and has a reasoning, this reasoning should be documented on the website.

Additional Info

When using NPM workspaces (common in mono-repos) there will be symlinks from node_modules to the directories of the packages. https://docs.npmjs.com/cli/v10/using-npm/workspaces
Running Mocha with --reporter=json then shows that rather the tests in the node_modules are picked up than the real working directory.

image

This can lead to further problems when processing the test reports or in case external tooling relies on these paths.

The problem became visible while working on a VS Code Extension and tests from node_modules were listed.

CoderLine/mocha-vscode#1

@Danielku15 Danielku15 added status: in triage a maintainer should (re-)triage (review) this issue type: feature enhancement proposal labels Mar 31, 2024
@JoshuaKGoldberg

This comment has been minimized.

@JoshuaKGoldberg JoshuaKGoldberg changed the title 🚀 Feature: Unify --ignore and --watch-ignore and make the patterns recursive 🚀 Feature: Unify default values for --ignore and --watch-ignore and make the patterns recursive Oct 8, 2024
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Oct 8, 2024

Ok coming back to this: I think I better understand things now, and am not in favor of unifying the two just yet. It's feasible that a project could want to have a separate glob for test files (--ignore) as opposed to watching files (--watch-ignore). For reference, Jest has separate options for testPathIgnorePatterns vs. watchPathIgnorePatterns. Given that this is the only issue I've seen about separating the two options, let's hold off on unifying them for now.

However, changing the default values makes a lot of sense to me. I think the values were first set before JavaScript monorepos were widespread & popular. Accepting PRs for the single change of setting the defaults of both --ignore and --watch-ignore to be the recursive ['**/node_modules/', '**/.git/'].

Note that this would be a semver-major breaking change. Which means we wouldn't be able to merge until we're working on Mocha 12.

Edit: ah, #5203 exists to track --watch-ignore switching to the recursive form. So let's use this issue to track changing --ignore to default to the recursive ['**/node_modules/', '**/.git/'].

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! semver-major implementation requires increase of "major" version number; "breaking changes" and removed status: in triage a maintainer should (re-)triage (review) this issue labels Oct 8, 2024
@JoshuaKGoldberg JoshuaKGoldberg added this to the v12.0.0 milestone Oct 8, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title 🚀 Feature: Unify default values for --ignore and --watch-ignore and make the patterns recursive 🚀 Feature: Change default value for --ignore to **/node_modules, **/.git Oct 8, 2024
@Danielku15
Copy link
Author

Ok coming back to this: I think I better understand things now, and am not in favor of unifying the two just yet. It's feasible that a project could want to have a separate glob for test files (--ignore) as opposed to watching files (--watch-ignore). For reference, Jest has separate options for testPathIgnorePatterns vs. watchPathIgnorePatterns. Given that this is the only issue I've seen about separating the two options, let's hold off on unifying them for now.

Looks like there was some sort of mistunderstanding. In my original post I had proposed to only unify the default values of the options. My intention was never to have only one option. The initial title was badly phrased and a bit misleading, the body represents better my intentions. I agree that it makes sense to have two options and I don't see a need to change Mocha to only have one.

However, changing the default values makes a lot of sense to me. I think the values were first set before JavaScript monorepos were widespread & popular. Accepting PRs for the single change of setting the defaults of both --ignore and --watch-ignore to be the recursive ['**/node_modules/', '**/.git/'].

This matches my proposed solution. 👍 from my side to keep both options and change their defaults to the same pattern as noted.

Note that this would be a semver-major breaking change. Which means we wouldn't be able to merge until we're working on Mocha 12.

Edit: ah, #5203 exists to track --watch-ignore switching to the recursive form. So let's use this issue to track changing --ignore to default to the recursive ['**/node_modules/', '**/.git/'].

Fine for me. Not sure how long the road to Mocha 12 is, until then maybe some few docs on that inconsistency and plan could help avoiding problems. This will also help in cases where people might report bugs to the vscode extension.

@JoshuaKGoldberg
Copy link
Member

proposed only to unify the default values

Ah great! Sorry for misinterpreting then 🙂.

until then maybe some few docs on that inconsistency and plan could help avoiding problems. This will also help in cases where people might report bugs to the vscode extension.

Great idea. I'd 👍 a PR that adds notes to the mochajs.org docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

2 participants