Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Compatibility with jest-preset-angular #51

Open
lonix1 opened this issue Mar 29, 2019 · 5 comments
Open

[Question] Compatibility with jest-preset-angular #51

lonix1 opened this issue Mar 29, 2019 · 5 comments

Comments

@lonix1
Copy link

lonix1 commented Mar 29, 2019

Has anyone used this library in a monorepo project with the jest-preset-angular preset, which configures ts-jest in a way that conflicts with this library.

I tried this which doesn't work (nameof is detected, but then the preset fails and so the tests don't run):

  globals: {
    "ts-jest": {
      tsConfig: '<rootDir>/tsconfig.spec.json',
      stringifyContentPathRegex: '\\.html$',
      astTransformers: [
        "ts-nameof",
        require.resolve("jest-preset-angular/InlineHtmlStripStylesTransformer"),
      ],
    }
  },

In fact is it even possible to use multiple presets or transformers?

@lonix1 lonix1 changed the title [Question] Compatibility with nx and jest-preset-angular [Question] Compatibility with jest-preset-angular Apr 1, 2019
@lonix1
Copy link
Author

lonix1 commented Apr 2, 2019

Hey @dsherret, it appears I'm the only one using this combination of libraries, so I'd like to ask a quick "theoretical" question before I close this.

This library adds to the astTransformers array, and I assume it plays nice with other transformers. So I thought the problem was with the jest-preset-angular library, and asked about it there, though I've confirmed that library works in a multi-transformer setup without problem.

So there's a limitation in ts-jest or ts-nameof that prevents multiple transformers at the same time, or, a config problem (and ts+jest+angular config is notoriously brittle, so I'm guessing it's that).

So in summary: have you ever managed to get your library working together with other ast transformers, at the same time?

@dsherret
Copy link
Owner

dsherret commented Apr 2, 2019

Based on briefly looking at this, it seems that ts-jest will actually provide its own compiler to the factory function. I didn't find this documentation until now and previously I was looking through the source code to try to figure this out:

https://github.com/kulshekhar/ts-jest/blob/2852078d83cc58eed3986aa2e3e210cd5d306b23/src/transformers/README.md

So it's possible that ts-nameof for jest is using a different version of the compiler. If it were, then the syntax kind values would be different and there would be unexpected errors.

I'll have to make some changes to this in order to use that compilerModule property.

@dsherret dsherret added the bug label Apr 2, 2019
@dsherret
Copy link
Owner

dsherret commented Apr 2, 2019

@lonix1 Actually, this might not be the issue in this case if it works on its own. I'll open up a separate bug for that later. Have you tried changing the order of the transforms? Does using require.resolve for ts-nameof work?

FWIW, I don't see anything wrong in InlineHtmlStripStylesTransformer. Perhaps it's an issue with ts-jest.

@dsherret dsherret removed the bug label Apr 2, 2019
@lonix1
Copy link
Author

lonix1 commented Apr 2, 2019

I tried many things, like:

  • changing the order of the transformers
  • using require.resolve
  • using clone and merge routines to merge configs together (idea from the preset repo linked above)
  • swear at, cajole with and pray to the compiler

In all cases the jest-angular stuffs works, but nameof fails. But if I use nameof alone it works brilliantly.

I think you're right it's a problem with ts-jest. Please don't do anything about this as because you don't use angular, so I don't want you to waste your time. I see there are quite a few angular users besides me, so hopefully one of them will join this issue with some ideas!

Should I go ahead and close?

@dsherret
Copy link
Owner

dsherret commented Apr 8, 2019

The compiler never listens to my prayers either 😞

No, it's fine—keep it open. I'll look into it eventually.

Also, opened #52.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants