Is it possible to use ts-jest together with custom transformers such as ts-transformer-keys? I'd like to do assertions of my data types in my tests to ensure that they are up to date with some backend data types. That's why I'd like to use ts-transformer-keys together with Jest. Is there any reasonable way to do it?
A quick look tells me that ts-transformer-keys can be imported and used like any other javascript package. If this understanding is correct then there's no reason for this to not work. It will be treated and processed like any other javascript package.
Does that answer the question?
@golddranks is talking about custom transformers, which (currently) can only be used when accessing the compiler API directly. The docs of this one illustrate this:
https://github.com/kimamula/ts-transformer-keys#how-to-use-the-custom-transformer
In case of the transpileModule function ts-jest utilizes, custom transformers would have to be provided to the second argument transpileOptions on the key transformers, which gets forwarded to program.emit:
https://github.com/Microsoft/TypeScript/blob/ceae613e4c0ba36829a2381687883ecdc6b169c3/src/services/transpile.ts#L107
Unfortunately, this transformer requires access to the program instance, which is inaccessible from the outside when using transpileModule. Thus, supporting this feature - in its current state - is not possible without quite a large change on how modules are processed by ts-jest (i.e. replicating a lot of transpileModule's implementation).
I'm closing this due to inactivity - it doesn't seem like something we'd support in the near future.
Most helpful comment
@golddranks is talking about custom transformers, which (currently) can only be used when accessing the compiler API directly. The docs of this one illustrate this:
https://github.com/kimamula/ts-transformer-keys#how-to-use-the-custom-transformer
In case of the
transpileModulefunctionts-jestutilizes, custom transformers would have to be provided to the second argumenttranspileOptionson the keytransformers, which gets forwarded toprogram.emit:https://github.com/Microsoft/TypeScript/blob/ceae613e4c0ba36829a2381687883ecdc6b169c3/src/services/transpile.ts#L107
Unfortunately, this transformer requires access to the
programinstance, which is inaccessible from the outside when usingtranspileModule. Thus, supporting this feature - in its current state - is not possible without quite a large change on how modules are processed byts-jest(i.e. replicating a lot oftranspileModule's implementation).