chore: move .mocharc.js to root and delete library copies#8069
chore: move .mocharc.js to root and delete library copies#8069GautamSharda wants to merge 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request centralizes Mocha configuration by removing local .mocharc files across the monorepo and updating the root configuration. Feedback highlights that switching to ESM exports in the root .mocharc.js could cause runtime errors in CommonJS environments. Furthermore, the reviewer pointed out that the omission of the recursive flag in the centralized config might lead to silent test skips, as several deleted local configurations previously relied on it for test discovery.
| config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; | ||
| } | ||
| module.exports = config | ||
| export default config |
There was a problem hiding this comment.
Changing the export to export default in a .js file will cause a SyntaxError at runtime if the root package.json does not contain "type": "module". Since this configuration is being centralized to replace local versions that were using CommonJS (module.exports), it is safer to maintain CommonJS compatibility to ensure it works across all packages in the monorepo.
Additionally, please ensure that the config object (defined in the lines above) includes "recursive": true. Several of the deleted local configurations (e.g., in gapic-node-processing, grafeas, and google-cloud-monitoring) specifically enabled this flag. If it is missing from this centralized root configuration, Mocha will fail to discover tests in subdirectories for those packages, leading to silent test skips in CI.
| export default config | |
| module.exports = config |
quirogas
left a comment
There was a problem hiding this comment.
LGTM, please add a PR description before merging the PR.
This PR centralizes the Mocha configuration across the monorepo for googleapis/librarian#4583.
It does so by creating a unified .mocharc.cjs file at the repository root with common settings and deleting all library-level .mocharc.js and .mocharc.json files within the packages/ directory.
I verified the changes by running tests in a representative package (packages/google-cloud-aiplatform) using the internal CI script (ci/run_single_test.sh). The tests passed successfully, confirming that the root-level configuration was correctly picked up. Also, the full suite of CI checks (Kokoro system tests) ran on this PR and all checks have passed successfully.