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

[Enhancement] - Provide better long-term support for vue-jest by using existing solutions to piggy-back on further grokked design #114

Closed
justinhelmer opened this issue Oct 5, 2018 · 1 comment · Fixed by #139

Comments

@justinhelmer
Copy link
Contributor

justinhelmer commented Oct 5, 2018

I reached out to ts-jest through their Slack Channel, and one of the main contributors / owner @huafu responded almost immediately. I originally reached out to attempt to understand their lookup logic for the ts/babel config files. I mentioned our interests in normalizing the behavior

@huafu suggested a different overall approach, which I agree will be in the best interest of the long-term growth of vue-jest. Instead of trying to parallel the behavior, piggy-back off the existing babel-jest and ts-jest libraries to create the transformers.

It would obviously be a larger change (probably more of a partial rewrite), but the interface to consumers could potentially be the same given the other changes we are making (i.e. #111).

I was going to take a screenshot of the conversation and attach it, but for the sake of indexing I will copy over the good bits. The formatting may not be perfect:

[--START QUOTE--]
huafu [9:27 PM]
You should not bother to find tsconfig, neither you should bother to find babel config. Instead (short dirty version for explanation):

to compile js:

require('babel-jest').createTransformer().process(...)

to compile ts:

require('ts-jest').createTransformer(...optionsIfYouNeed).process(...)

If you really need to find the tsconfig and babel config, I’d suggest you use ts-jest for this to not re-invent the wheel, especially since jest is not calling any initialize method of transformers.

All the config is loaded, parsed, normalized and cached automatically in the config-set. You can access it like that:

import { createTransformer } from 'ts-jest'

const tr = createTransformer(); // will be your own transformer instance
const cs = tr.configsFor(jestConfig /* stringified as coming from getCacheKey() or the object as coming from process() */)
// the cs is a config set which will resolve all your config (babel or ts) and get you a ts compiler with memory cache and disc cache, as well as the babel transformer
cs.jest // jest config as object, resolved, normalized and cached
cs.tsJest // same for ts-jest optons
cs.babel // same for babel config
cs.typescript // same for tsconfig <== this is actually what you asked for
cs.tsCompiler // the configured typescript compiler (as defined by ts-jest there https://github.com/kulshekhar/ts-jest/blob/645558b289076dd8d4bd22aedafa32bd1ab1a751/src/types.ts#L169-L176)
cs.babelJestTransformer // the configured babel transformer (ie you can call process() on it then as jest would do on a transformer

You have also other utils there that might be useful as cs.resolvePath,
you also might be interested in https://kulshekhar.github.io/ts-jest/tech/process/
[--/ENDQUOTE--]

huge shoutout to @huafu for the direction.

@justinhelmer
Copy link
Contributor Author

Since @eddyerburgh has expressed interest in deliver this, I thought it worthwhile to mention @huafu again as a potential conduit for implementation.

I also reached out on the Slack channel to see if anyone in the community has interest with helping implement this change.

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

Successfully merging a pull request may close this issue.

2 participants