angular-builders
angular-builders copied to clipboard
angular-builders/jest : replace astTransformers
Is your feature request related to a problem? Please describe.
In order to solve https://github.com/thymikee/jest-preset-angular/issues/389 I wrote a custom AST transformer which inherits from jest-preset-angular/build/InlineFilesTransformer
and declared in my jest congifuration.
module.exports = {
globals: {
'ts-jest': {
astTransformers: [
resolve(__dirname, 'includes/jest.inline-transformer.js'),
'jest-preset-angular/build/StripStylesTransformer',
],
},
},
// other config
};
The problem is because this option is concatened instead of replaced, the default InlineFilesTransformer
is still loaded.
Describe the solution you'd like
A way to replace astTransformers
instead of concatenate. I don't really have a good proposition, the current behavior cannot be changed, obviously.
Describe alternatives you've considered
Dropping angular-builders/jest
, duplicate the necessary config and running jest manually.
Additional context
My transformer overload is very simple, it just excludes all the packages from a specific group
const baseFactory = require('jest-preset-angular/build/InlineFilesTransformer').factory;
exports.factory = (cs) => {
const baseTransformer = baseFactory(cs);
return (ctx) => {
const baseVisitor = baseTransformer(ctx);
return (sf) => {
if (sf.fileName.indexOf('@sglk/') !== -1) {
return sf;
}
return baseVisitor(sf);
};
};
};
From what I understand you try to compile VE application against Ivy libs? If so, I'm not sure it's a good idea, since Angular official guidelines recommend compiling libraries with VE for now. This way the lib will be compatible with VE applications out of the box and with Ivy applications via compatibility layer (created by ngcc
).
No my applications are Ivy too. That's why I try to not compile for VE at all.
Sent from MailDroid
-----Original Message----- From: JeB [email protected] To: just-jeb/angular-builders [email protected] Cc: Damien Sorel [email protected], Author [email protected] Sent: mer., 03 juin 2020 12:38 Subject: Re: [just-jeb/angular-builders] angular-builders/jest : replace astTransformers (#754)
From what I understand you try to compile VE application against Ivy libs? If so, I'm not sure it's a good idea, since Angular official guidelines recommend compiling libraries with VE for now.
-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/just-jeb/angular-builders/issues/754#issuecomment-638111670
Ok, in this case I think an acceptable solution is to make the list of properties to concut configurable (while keeping the default value as it is now).
This will give you the option to override the astTransformers
while keeping the builder backward compatible.
Do you feel like creating a PR for this?
Actually I still don't know if it's the right solution, you can read the discusion on jest-preset-angular but I didn't had much luck with my custom transformers for now. I'll keep you updated (or close the issue).