Jest 29 moduleNameMapper CSS mock skipped when CI=true is set
0 reputation · 22 Aug 2022, 20:46 UTC
Configuration transition to Jest 29
After upgrading a project from Jest 28 to Jest 29, imports of CSS modules in test files are handled through an explicit moduleNameMapper entry that points to a mock file, e.g. '\.css$': '<rootDir>/__mocks__/styleMock.js'. This matches the documented recommendation for static assets.
Observed inconsistency
The same jest.config.js resolves the mock correctly in local runs, but in an environment where CI=true is exported, the resolution appears to be skipped and tests fail to import the mocked stylesheet. The goal is a single configuration that resolves the CSS module mock identically in local and CI runs, without maintaining two config files or conditional logic in the mapper.
The Jest 29 documentation does not clearly state whether CI=true changes moduleNameMapper resolution, mock lookup order, or cache behavior, and it is unclear whether jest-environment-jsdom behaves differently under the CI flag. Assume Jest 29.x with jsdom; exact minor version should be confirmed before relying on any answer.
Questions
- Does Jest 29 treat
moduleNameMapperresolution differently whenCI=true, or is the failure caused by something else, such as module cache invalidation or rootDir resolution? - Is there a documented way to force the CSS mock to apply unconditionally across environments?
- Could
jest-environment-jsdomin CI alter how stylesheet imports are resolved compared to local runs?