Ts-jest: Using ts-jest together with ts-transformer-keys

Created on 28 Aug 2017  路  3Comments  路  Source: kulshekhar/ts-jest

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?

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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artola picture artola  路  3Comments

mikeyakymenko picture mikeyakymenko  路  3Comments

jbreckmckye picture jbreckmckye  路  3Comments

ozum picture ozum  路  4Comments

GeeWee picture GeeWee  路  4Comments