Mocha: enhancement: use --watch-extensions for default files list pattern

Created on 7 Jan 2016  路  5Comments  路  Source: mochajs/mocha

IMHO, it would make sense to augment the default file list pattern (./test/**/*.js) with the extensions provided with the --watch-extensions flag; e.g.:

mocha --watch-extensions js,jsx ...

should result in the default file list pattern:

./test/**/*.@(js|jsx)

And maybe the same for the extensions given for --compilers flag?

documentation feature

Most helpful comment

Is it me or is --watch-extensions entirely unused? It's listed in --help, but not mentioned in _mocha at all.

All 5 comments

Is it me or is --watch-extensions entirely unused? It's listed in --help, but not mentioned in _mocha at all.

I think it's this line here, actually: https://github.com/mochajs/mocha/blob/master/bin/_mocha#L353 dash-separator to camelCase converted by Commander, I believe.

Compilers' extensions are added to both the watched extensions and the main files list of extensions here: https://github.com/mochajs/mocha/blob/master/bin/_mocha#L297

I'm not sure I understand the relationship of the files watched for rerunning and the files to actually run well enough to tell if it would make sense to add the extensions from the former to the extension list (or the default extension list?) for the latter (although it looks like it might be easy to do if we do want to, but it might be considered a backwards-incompatible change and have to wait for a "major" version); @boneskull, @dasilvacontin, either of you familiar with this?

Ah, the fact that they (extensions passed to --watch-extensions) are not in the general extensions list probably is why my .jsx files are not picked up. If I add them with --compilers jsx:./empty_file, they do get picked up.

Actually now that --compilers is deprecated, mocha should really have an --extensions flag to add extensions both to the lookup pattern to find tests and to extensions to watch. (With --watch-extensions becoming an alias for it for backward compatibility.)

The important use-case is to put the list of extensions into mocha.opts, so that all tests in a directory may be run by only knowing the directory. The way it is now (without --compilers) is that one has to know which extensions are present in the directory, specify the right number of asterisks and some suitable type of braces (e.g. test/foo/**/*.{js,ts}), and worry about quoting. It's hard and fragile.

Renaming --watch-extensions to --extensions and making them work as this issue requests would be simple, intuitive, and make mocha much friendlier to use.

Since Mocha v6 we have a flag:
--extension: File extension(s) to load and/or watch
--watch-extensions: alias of --extension for backwards compability

With Mocha v7 (not published yet) we will have additionally:
--watch-files: List of paths or globs to watch
--watch-ignore: List of paths or globs to exclude from watching

Was this page helpful?
0 / 5 - 0 ratings