angular-builders icon indicating copy to clipboard operation
angular-builders copied to clipboard

angular-builders/jest : replace astTransformers

Open mistic100 opened this issue 4 years ago • 4 comments

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);
        };
    };
};

mistic100 avatar Jun 02 '20 16:06 mistic100

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).

just-jeb avatar Jun 03 '20 10:06 just-jeb

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

mistic100 avatar Jun 03 '20 11:06 mistic100

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?

just-jeb avatar Jun 03 '20 13:06 just-jeb

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).

mistic100 avatar Jun 03 '20 19:06 mistic100