If users use jest-preview with vite, CSS modules with SCSS and import stylesheet with an absolute import like this @import 'src/styles', the following error is thrown:
● Test suite failed to run.
Can't find stylesheet to import.
╷
1 │ @import 'src/styles';
│ ^^^^^^^^^^^^
╵
src\components\Button\Button.module.scss 1:9 root stylesheet
I attempted to utilize the sassLoadPaths configuration option and set up jest moduleNameMappers such as 'src/(.*)': '<rootDir>/src/$1', but it appears that none of these changes are taking effect.
Using a relative import could be a solution to the problem; however, implementing such a change in the existing project is not feasible.
Screenshots
Folder structure:
Import example:
Error:
Reproduce
You can find a minimal reproducible example in this repository, and its code is adapted from the example demonstrated in jest-preview vite-react-example.
Describe the bug
If users use
jest-preview
withvite
,CSS modules
withSCSS
and import stylesheet with an absolute import like this@import 'src/styles'
, the following error is thrown:I attempted to utilize the sassLoadPaths configuration option and set up jest moduleNameMappers such as
'src/(.*)': '<rootDir>/src/$1'
, but it appears that none of these changes are taking effect. Using a relative import could be a solution to the problem; however, implementing such a change in the existing project is not feasible.Screenshots
Folder structure:
Import example:
Error:
Reproduce
You can find a minimal reproducible example in this repository, and its code is adapted from the example demonstrated in jest-preview vite-react-example.
Expected behavior
No errors
Environment
Additional context
Seems that the same issue was already reported in https://github.com/nvh95/jest-preview/issues/224 without further resolution.