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

Sub folders ignored (even with --recursive) when tests present in parent folder #2138

Closed
adamreisnz opened this issue Mar 2, 2016 · 11 comments
Labels
stale this has been inactive for a while...

Comments

@adamreisnz
Copy link

I'm encountering a strange issue, which I assume is a bug.

The relevant folder structure looks roughly like this:

app
  |_ shared
    |_ helpers

My mocha.opts contains the following:

--recursive
--require test/helpers/setup
--require mocha-clean

And I am running Mocha using an NPM run script, using:

mocha app/**/*.spec.js

This was working fine as long as I only had tests in the shared/helpers folder. The moment I created a .spec.js file in the shared folder itself, the tests from shared/helpers were no longer executed.

I found a fix for this on StackOverflow, which recommended putting the tests command in a string, like so:

mocha "app/**/*.spec.js"

However, not sure if that's an artefact of npm or an issue with Mocha.

I also tried to put app/**/*.spec.js as the last parameter in mocha.opts, but that had the same effect, and putting quotes around it in there caused Mocha to crash.

If any more information is required to reproduce/debug this please let me know.

@stephanebruckert
Copy link

Kind of the same for me, but in the opposite order. Only the tests in the sub folders were executed (shared/helpers) and the ones in the current folder (shared) weren't.

Thanks for pointing a fix out, surrounding the path with quotes fixed the issue.

@actonw
Copy link

actonw commented Aug 4, 2016

Running into this as well.

@drazisil drazisil added type: bug a defect, confirmed by a maintainer unconfirmed labels Mar 30, 2017
@stale
Copy link

stale bot commented Oct 17, 2017

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot added the stale this has been inactive for a while... label Oct 17, 2017
@ScottFreeCode
Copy link
Contributor

This is Posix shells expanding the path before passing it to Mocha; if they're not configured to treat ** recursively, they'll replace it with only one level of directories, so to make your paths reliable you have to quote them, otherwise Mocha never gets the chance to do anything about it.

@ScottFreeCode ScottFreeCode removed type: bug a defect, confirmed by a maintainer unconfirmed-bug labels Oct 17, 2017
@avocadoslab
Copy link

avocadoslab commented Feb 13, 2018

Had exactly same issue on Mac and adding single quotes around path after --recursive fixed the issues.

@mscottx88
Copy link

Unfortunately, this fix does not work cross-platform.

On Windows:
mocha -c --reporter=spec --require test/setup.js --recursive test/integration/**/*.spec.js 👍
mocha -c --reporter=spec --require test/setup.js --recursive 'test/integration/**/*.spec.js' 👎

On Mac:
mocha -c --reporter=spec --require test/setup.js --recursive test/integration/**/*.spec.js 👎
mocha -c --reporter=spec --require test/setup.js --recursive 'test/integration/**/*.spec.js' 👍

Keep trying!

@harrysarson
Copy link
Contributor

@mscottx88 Does replacing ' with " fix the problem on windows?

@mscottx88
Copy link

mscottx88 commented Feb 13, 2018

Yes it does :) That is the cross-platform solution we needed!

mocha -c --reporter=spec --require test/setup.js --recursive \"test/integration/**/*.spec.js\"
(as embedded in an npm run "integration" script)

Windows & Mac 👍 👍

@hilleer
Copy link

hilleer commented Apr 16, 2019

I just came across this issue and for others that might find it too, I can confirm surrounding the path with double quotes solved the issue for me too (on mac).

@basickarl
Copy link

Yes it does :) That is the cross-platform solution we needed!

mocha -c --reporter=spec --require test/setup.js --recursive \"test/integration/**/*.spec.js\"
(as embedded in an npm run "integration" script)

Windows & Mac

Doesn't work on Bash on Linux.

GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Linux version 4.10.0-32-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu116.04.4) ) #3616.04.1-Ubuntu SMP Wed Aug 9 09:19:02 UTC 2017

@ericminio
Copy link

ericminio commented Jun 3, 2023

Working on Bash on Ubuntu 20.04: mocha $(find <folder> -name '*.spec.js')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale this has been inactive for a while...
Projects
None yet
Development

No branches or pull requests