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: Add option to follow symlinks found by glob patterns #3584

Open
4 tasks done
mbeerta-factset opened this issue Nov 28, 2018 · 8 comments
Open
4 tasks done
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@mbeerta-factset
Copy link

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

This is related to #1223 where util.lookupFiles does not follow symlinks and this still happens if provided with a glob pattern. The solution would be to add a {follow: true} argument to the glob.sync call.

Steps to Reproduce

Create a symlink to a directory containing test files, call mocha with a glob to that directory.

Expected behavior: Tests in symlinked folders will be executed

Actual behavior: Tests are ignored

Reproduces how often: every time

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: latest
  • The output of node --version:
  • The version and architecture of your operating system: X64 Linux
  • Your shell (bash, zsh, PowerShell, cmd, etc.): bash
  • Your browser and version (if running browser tests): -
  • Any other third party Mocha related modules (with versions): -
  • The code transpiler being used: -

Additional Information

I'm happy to create a pull request, however i'm not familiar with the implications such a change might have.

@plroebuck
Copy link
Contributor

I'm not sure if we specify a minimum Windows OS version, so someone else will need to interpret its impact. Unsure whether this was done intentionally to "return the same results" on all platforms.

See NTFS symlinks.

@bluelovers
Copy link

fast-glob is support followSymlinkedDirectories

so i think can replace glob => fast-glob in dependencies

@Bamieh Bamieh added future needs to wait good first issue new contributors should look here! area: node.js command-line-or-Node.js-specific labels Dec 3, 2018
@Bamieh
Copy link
Contributor

Bamieh commented Dec 3, 2018

Maybe this should be added as an additional flag rather than the default behavior? I added the "future" tag since I believe it might be a good idea to land yargs first (#3556) (feel free to disagree)

@boneskull boneskull added the type: feature enhancement proposal label Dec 4, 2018
@boneskull
Copy link
Contributor

Agree it would probably not be a great idea to make this the default behavior.

@mbeerta-factset Are there any workarounds at present time?

@mbeerta-factset
Copy link
Author

unfortunately not, but i had the same thoughts of making this switchable. Might be reusing the --preserve-symlinks option a viable approach (although it is also passed to the node runtime)?

@shubham-rocko
Copy link

Hi, I would love to do this issue if it isn't fixed yet.

@cristian-spiescu
Copy link

I'm posting here my current workaround (via monkeypatching) for this:

mocha-monkeypatched.js:

// monkeypatching libs
var Module = require('module');
var originalRequire = Module.prototype.require;

let globMonkeyPatched = false;

Module.prototype.require = function () {
    const original = originalRequire.apply(this, arguments);

    if (!globMonkeyPatched && "glob" === arguments[0]) {
        // BUG #1: cf. https://github.com/mochajs/mocha/issues/3584
        // mocha doesn't detect test files in linked dirs
        var originalSync = original.sync;
        original.sync = function () {
            const options = arguments[1];
            options.follow = true;
            return originalSync.apply(this, arguments);
        }
        globMonkeyPatched = true;
    }

    return original;
};

// BUG #2: cf. https://github.com/paulmillr/chokidar/issues/987
// mocha cannot watch multiple file extensions; hence this workaround
process.argv.push("-w", "--watch-files", ".");

// INIT_CWD only exists when launched w/ npm run ...; if needed to run as stand alone, a solution around process.argv[1] can be built
require(process.env.INIT_CWD + "/node_modules/mocha/bin/_mocha");

package.json:

    "test": "set NODE_OPTIONS=--preserve-symlinks && node mocha-monkeypatched"

NOTE: I also discovered another issue regarding linked files, but related to watching.

@JoshuaKGoldberg JoshuaKGoldberg removed the good first issue new contributors should look here! label Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title Mocha won't follow symbolic links when provided with a glob pattern 🚀 Feature: Add option to follow symlinks found by glob patterns Dec 27, 2023
@JoshuaKGoldberg
Copy link
Member

👍 that making this the default behavior is too scary of a change, but that as a new option it would be good.

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! and removed future needs to wait labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

8 participants