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

mocha, ts-node and recursively loading files #3115

alexpchin opened this issue Nov 23, 2017 · 1 comment

mocha, ts-node and recursively loading files #3115

alexpchin opened this issue Nov 23, 2017 · 1 comment
question support question


Copy link

Using this script:

"test": "./node_modules/mocha/bin/mocha --recursive --require ts-node/register ./test/**/*.spec.ts --opts ./test/mocha.opts",

I've tried to load some test files inside the tree:

├── controllers
│   ├── admin
│   │   └── users.spec.ts
│   ├── authentications.spec.ts

The authentications.spec.ts test file gets loaded but the users.spec.ts doesn't.

My mocha.opts file looks like just:

--timeout 5000

I've also tried to remove the --recursive flag and just have a glob but it doesn't work.

I can't work out whether the problem is with ts-node or with mocha?

Any ideas?

@ScottFreeCode ScottFreeCode added the question support question label Nov 23, 2017
Copy link

Quote the glob, "./test/**/*.spec.ts" instead of ./test/**/*.spec.ts, so the shell doesn't interpret the **. (Most shells treat that as including any number of directories, but it's technically an extension and isn't enabled in all of them by default; quoting forces the original glob to be passed to Mocha, which interprets it the same no matter which OS or shell it's inside.) If for some reason that doesn't resolve your issue, please let us know!

Tangentially, --recursive doesn't typically affect globs one way or the other; at least, it doesn't affect glob interpretation (* is never recursive and ** in Mocha is always recursive), and won't kick in when the glob only matches files (I'm not certain whether it comes into play when a glob matches a directory; I haven't ever had a reason to try). It changes whether Mocha looks for JS files inside subdirectories or only that exact directory when a directory is specified as the filepath. (So, for instance, if your tests are all JS files somewhere under the default test folder, you can put --recursive in mocha.opts to make Mocha run all the tests by default without having specified a path/glob, then specify a path/glob when running it to effectively override that and run only some files. In fact, I'm not sure what other good use cases it has.)

(Also, ./test/mocha.opts is the default opts file location, so you should be able to omit the --opts parameter when it's at that path.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
question support question
None yet

No branches or pull requests

2 participants