Jest code coverage not picking up JS files from parent directory even if within rootDir

I have a specific project setup where the Jest tests live in a folder but are testing code from two different source folders located in a parent directory. When trying to setup code coverage, I read on other posts that setting the rootDir to the common parent and adding the other folders as roots should solve it. However, my JS files in the source folders are still not being picked up. I’ve tried moving a JS file around to test and sure enough only files located within the same folder of the Jest config are being picked up for coverage.

Here’s my jest config file:

{
  "testEnvironment": "jsdom",
  "testMatch": [
    "**/jest/**/*.test.js"
  ],
  "rootDir": "../../",
  "transform": {
    "^.+\.[t|j]sx?$": [
      "babel-jest",
      {
        "configFile": "./babel.config.json"
      }
    ]
  },
  "transformIgnorePatterns": [
    "node_modules/(?!(parsel-js|cheerio|uuid)/)"
  ],
  "roots": [
    "<rootDir>/mu-plugins/tests",
    "<rootDir>/mu-plugins/core/assets/src/js",
    "<rootDir>/themes/theme/assets/ts"
  ],
  "setupFilesAfterEnv": [
    "<rootDir>/mu-plugins/tests/jest.setup.js"
  ],
  "moduleDirectories": [
    "<rootDir>/mu-plugins/tests/node_modules"
  ],
  "globals": {
    "CSS": {}
  },
  "collectCoverageFrom": [
    "**/*.js"
  ],
  "coveragePathIgnorePatterns": [
    "/node_modules/",
    "/coverage/"
  ],
  "coverageDirectory": "<rootDir>/mu-plugins/tests/coverage"
}

I am using Jest 29.7 in case it matters.

My rootDir used to be on the same level as the Jest config so I changed it to the common parent, and added all relevant directories to the roots array. This didn’t solve the issue. I’m certain the paths are right though as when putting a wrong folder on purpose, Jest would throw an error.

I’ve tried clearing the Jest cache, but it didn’t solve it either.

I’ve tried various formatting for collectCoverageFrom but none worked.

I’ve also tried changing the value of forceCoverageMatch, no luck there too.

When running jest --coverage I then see:

> jest --coverage

 PASS  jest/theme/components/shared/info.test.js
 PASS  jest/core/variant/variant.test.js
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------

Test Suites: 2 passed, 2 total
Tests:       5 passed, 5 total
Snapshots:   0 total
Time:        5.112 s
Ran all test suites.