Goal: run mocha tests for all enabled extensions
Approach: create a MediaWiki maintenance script that uses ExtensionRegistry to obtain a list of all enabled extensions (and skins) and generates a mocharc.json that can then be used to run tests for all enabled extensions.
Implementation:
Create a MediaWiki extension that defines a maintenance script called generateMochaConfig.php. As a template for how maintenance scripts can be defined by MediaWiki extensions, look at maintenance/cleanup.php in the SpamBlacklist extension. Note that the extension doesn't actually need to hook into MediaWiki to work. It should still have an extension.json for meta-data and completeness.
generateMochaConfig.php calls ExtensionRegistry::getInstance()->getAllThings() to get a list of extensions. This returns an assoc array that maps extension (and skin) names to info structures. The info structure has field calls path which contains the path of the extensions's extension.json file. The directory that contains that file is the extensions's base directory.
For each extension's base directory, generateMochaConfig.php checks if tests/mocha exists. If it does, that path is part of the result set. The path probably needs to be expanded to be absolute to work correctly in the Mocha config file.
generateMochaConfig.php generates JSON to stdout, following the mocharc.json format. The relevant configuration key seems to be spec (or file), which would receive a list of directories.
generateMochaConfig.php should offer an option called --config, from which to load an existing mocharc.json file, which would be amended by merging the extension tests into the spec (or file) fields, and outputting the result.