8000 [Enhancement] - Provide better long-term support for vue-jest by using existing solutions to piggy-back on further grokked design · Issue #114 · vuejs/vue-jest · GitHub
[go: up one dir, main page]

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

Description

@justinhelmer

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0