Closed the-spyke closed 11 months ago
@the-spyke
I did some testing:
npx mocha '**/*.spec.ts'
and "exclude": ["node_modules/**"]
npx mocha './**/*.spec.ts'
and "exclude": ["node_modules/**"]
npx mocha '**/*.spec.ts'
and "exclude": ["./node_modules/**"]
npx mocha './**/*.spec.ts'
and "exclude": ["./node_modules/**"]
Mocha first processes the globs (both spec and exclude) and then resolves the path of resulting files.
Since the string ./node_modules/runtypes/src/asynccontract.spec.ts
doesn't match the pattern node_modules/**
, the exclusion doesn't work. On the other hand when defining the globs consistently, either both with ./
or both without, then the exclusion works.
Imo we shouldn't fiddle around with user's globs and my proposition is to leave things as is.
Anyway it's better to not put your tests in the root folder, and add a separate test
folder for this purpose.
@juergba Giving you some context:
exclude
is defined in the config, but npx mocha 'path'
is called by devs when they want to test a single file. Not super convenient to have such behavior.There is an open issue on Minimatch, dated back in 2014.
Your ideas are welcome.
As a work-around you can set: "exclude": ["node_modules/**", "./node_modules/**"]
https://github.com/isaacs/minimatch/issues/30#issuecomment-1040599045 indicates this isn't a bug in minimatch:
**
does not match.
unless{dot:true}
is set, and even if it is set, it does not ever match.
or..
as path portions.Paths starting with
./
and../
never match a pattern that doesn't start explicitly with./
or../
, even if{dot:true}
is set.This is by design, and matches the behavior of bash 4.3+.
Given there's a quick workaround (https://github.com/mochajs/mocha/issues/4785#issuecomment-988050232), closing as wontfix. Someone please yell at me if I've misunderstood!
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Steps to Reproduce
Having
.mocharc.json
file:And running Mocha like this:
npx mocha './**/*.spec.ts'
Expected behavior: should run tests from all files excluding
node_modules
Actual behavior:
Fails inside a
spec
file of a dependency insidenode_modules
which meansexclude
doesn't work:And runs as it should if I remove
./
from the path like so:Reproduces how often: 100%
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 9.1.3node --version
: 16.13.0Additional Information