I would like to match absolute paths with regex in my jest.config.js same way as it is done in jsconfig.json.
// jest.config.js
{
...
moduleNameMapper: {
'^\+\/(.*)$': '<rootDir>/src/styles/'
'^\~\/(.*)$': '<rootDir>/src/'
},
}
'^\+\/(.*)$' should match +/theme/theme and find file located in Project/src/styles/theme/theme
'^\~\/(.*)$' should match '~/components/Account' and find file located in Project/src/components/Account
Regex work: https://regex101.com/r/yXpeAu/1, https://regex101.com/r/jH6ajA/1
Unfortunately something is wrong because I got 2 errors during test run.
SyntaxError: Invalid regular expression: /^+/(.*)$/: Nothing to repeatCannot find module './src/components/Account' from 'src/components/AccountThis is how jsconfig.json resolve absolute paths:
// jsconfig.json
{
"baseUrl": ".",
"paths": {
"+/*": ["./src/styles/*"],
"~/*": ["./src/*"],
}
}