When using a Git submodule for an npm package, Jest may not pick up the Jest configuration from the root project by default. Jest typically looks for a jest.config.js or jest.config.json file in the same directory where Jest is run. However, in a submodule scenario, the Jest configuration may be located in the root project, and Jest might not automatically discover it.

To make sure Jest uses the correct configuration from the root project, you can specify the --config option when running Jest within the submodule. Here's how you can do it:

  1. In the root project (main project), create a jest.config.js file with your desired Jest configuration options.

  2. In the submodule (npm package) directory, create a script in package.json that runs Jest and specifies the configuration from the root project. Open the package.json file in the submodule, and add the following script:

json
"scripts": { "test": "jest --config /path/to/root/project/jest.config.js" }

Replace /path/to/root/project with the actual path to your root project where the jest.config.js file is located.

  1. When running tests in the submodule, use the npm script you defined:
bash
# From the submodule directory npm run test

By providing the --config option with the path to the Jest configuration in the root project, Jest will use the specified configuration and apply it to the tests in the submodule. This way, the submodule will use the correct Jest configuration from the root project.

Have questions or queries?
Get in Touch