Not working unless used in combination with @angular-builders/jest
See original GitHub issueAnybody else have problems with using this preset without the builder?
If I run ng test
and use the builder it works, but if I run npx jest
it fails to load the html files.
When I run ng test --showConfig
and npx jest --showConfig
they config files that are spit out are identical (except for a prettier setting and an extra moduleNameMapper for image files) so I don’t understand why this is failing.
Here’s my local jest.config.js file, not that it should matter:
module.exports = {
"globals": {
"ts-jest": {
"tsConfig": "<rootDir>/public/tsconfig.spec.json",
"stringifyContentPathRegex": "\\.html$",
"astTransformers": [require.resolve("jest-preset-angular/InlineHtmlStripStylesTransformer.js")]
}
},
"preset": "jest-preset-angular",
"transform": {
'^.+\\.(ts|html)$': 'ts-jest',
"^.+\\.js$": "babel-jest"
},
"setupFilesAfterEnv": ["<rootDir>/public/setupJest.ts"],
"testMatch": [
"**/__tests__/**/*.+(ts|js)?(x)",
"**/(*.)+(spec).+(ts|js)?(x)"
],
"moduleFileExtensions": ["js", "json", "jsx", "node", "ts", "tsx", "html"],
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/src/$1",
"^app/(.*)$": "<rootDir>/public/app/$1",
"^modules/(.*)$": "<rootDir>/public/modules/$1",
"^assets/(.*)$": "<rootDir>/public/assets/$1",
"^environments/(.*)$": "<rootDir>/public/environments/$1"
}
}
Here’s the extra module name mapper:
'\\.(jpg|jpeg|png)$':
'<my root dir>/src/node_modules/@angular-builders/jest/src/jest-config/mock-module.js'
The reason why I am having this issue is because I have a PR into @angular-builders because, currently, it’s not respecting maxWorkers and I used to do this on my CI:
npx jest -w 2
which worked fine until I upgraded to jest-preset-angular 7. Then I had to start using the builder, but I can’t use -w 2, so I have to use -i which slows down my CI.
Not sure whose bug it is that I can’t get jest-preset-angular to work without also using the builder.
Here’s the relevant stuff:
“@angular-builders/jest”: “^7.4.1”, “jest”: “^24.7.1”, “jest-preset-angular”: “^7.0.1”,
EDIT: A little further info, it seems to work fine actually, unless I’m I haven’t mocked components in my tests. It loads the html file for the component I’m testing directly, but if I load other components in my test for a given component, it fails to load the templates for those other components.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
I think it was a problem with the jest cache.
Fix it by using
npx jest --clearCache
I can no longer reproduce this, I think I had some dependencies out of whack or something else. Very sorry for wasting your time.