jest-preset-angular
jest-preset-angular copied to clipboard
[Bug]: It is not work After config useESM: true
Version
12.2.3
Steps to reproduce
`transform: { '^.+\.(ts|js|mjs|html|svg)$': [ 'jest-preset-angular', { useESM: true, }, ], },
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!(.*\\.mjs$|tslib|@elf|lit-elemen|lit-html|tr-grid-util|tr-grid-titlewrap|d3-color|uuid))',
],`
another try
jest.mock('./miscellaneous/uuid', () => { return { v4: jest.fn(() => 1) }; });
Expected behavior
I expect the uuid on transformIgnorePatterns will be compile successfully
Actual behavior
Test suite failed to run
RangeError: Maximum call stack size exceeded.
Additional context
it is a internal project, so it's not allowed to post repo here, the transform and transformIgnorePatterns config work for other es module package, but not work for all esm.
Environment
System :
Windows64
Env:
"jest-preset-angular": "^12.2.3",
"jest": "^28.1.3",
"@angular/core": "^14.2.12"
You can try to use https://github.com/thymikee/jest-preset-angular/tree/main/examples to create a small reproduce case, that would help a lot
try moduleMapper
'^uuid$': require.resolve('uuid'),
instead of adding to transformignore
thanks @Delagen , @zhouyali besides, you can also put the configuration like this in your Jest config
{
//....
moduleNameMapper: {
uuid: '<rootDir>/node_modules/uuid/dist/index.js',
}
}
The error you got which was caused by default Jest module resolution which looks for the default
field inside exports
of package.json
However, because Jest runs with JSDOM, which is entirely in NodeJs environment therefore the file under esm-browser
can't be used. We need to tell Jest to load the file from node
export instead.