Skip to content

tsConfig option doesn't work #171

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

Closed
aantipov opened this issue Apr 4, 2019 · 4 comments · Fixed by #471
Closed

tsConfig option doesn't work #171

aantipov opened this issue Apr 4, 2019 · 4 comments · Fixed by #471

Comments

@aantipov
Copy link

aantipov commented Apr 4, 2019

Version: 4.0.0-beta.2

Problem
Documentation says that I can provide typescript configuration options using

jest.globals['vue-jest'].tsConfig

The problem is that tsConfig option doesn't work and application's root tsconfig.json is always being picked up.

I found that the problem is this code:

const getTsJestConfig = function getTsJestConfig(config) {
  const createTransformer = require('ts-jest').createTransformer
  const tr = createTransformer()
  const { typescript } = tr.configsFor(config)
  return { compilerOptions: typescript.options }
}

The code above relies on ts-jest package to get typescript configuration and passes a whole jest config to it.
ts-jest knows nothing about vue-jest, and thus our jest.globals['vue-jest'].tsConfig is just being ignored.

Proposed solution
To fix the problem I suggest to put tsConfig options under jest.globals['ts-jest']:

const getTsJestConfig = function getTsJestConfig(jestConfig) {
  const createTransformer = require('ts-jest').createTransformer
  const tr = createTransformer()
  const tsConfig = getVueJestConfig(jestConfig).tsConfig;
  const config = Object.assign(
                     {}, 
                     jestConfig || {}, 
                     { globals: {'ts-jest': { tsConfig }}}
                 ); 
  const { typescript } = tr.configsFor(config)
  return { compilerOptions: typescript.options }
}

I can prepare a PR if we agree on the solution

@eddyerburgh
Copy link
Member

The documentation is ready yet, but vue-jest 4 uses ts-jest to resolve the ts-config, so you need to use the ts-jest config options.

Let me know how it goes. We're still undecided whether to use ts-jest to resolve, to write and maintain our own, or to rely on babel for compiling TS files.

@aantipov
Copy link
Author

aantipov commented May 2, 2019

vue-jest 4 uses ts-jest to resolve the ts-config, so you need to use the ts-jest config options

Yep, this is exactly what I came to and use this workaround at the moment (specify jest.globals['ts-jest']. tsConfig option).
Still, the documentation is totally misleading and it took me quite a while to figure out what is wrong and how to fix it. I believe it's a bug and we need to fix it ASAP.

To me, the fact that vue-jest relies on ts-jest is an internal thing that we don't need to leak into the documentation. I would rather fix the problem in the code.

In the meantime, we can discuss a question of how to resolve ts configuration and whether we need to rely on babel to compile TS files.

@eddyerburgh
Copy link
Member

I disagree that it's a bug. There's a PR that updates the docs for when v4 leaves beta, but at the moment npm install vue-jest will install v3, which has the tsConfig option.

@aantipov
Copy link
Author

aantipov commented May 3, 2019

OK, didn't know about that PR, thanks for the clarification

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