Skip to content

Fails on lack of ts-jest even though it's optional #431

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
Andarist opened this issue Dec 21, 2021 · 3 comments · Fixed by #471
Closed

Fails on lack of ts-jest even though it's optional #431

Andarist opened this issue Dec 21, 2021 · 3 comments · Fixed by #471
Assignees
Labels

Comments

@Andarist
Copy link

It's states that ts-jest is an optional peer dep:

"ts-jest": {
"optional": true
},

However, @vue/vue3-jest cannot be used without it because if we have tsconfig.json then ts-jest is being required here:
const { ConfigSet } = require('ts-jest/dist/config/config-set')

Since my whole monorepo is using Babel I don't want to rely on the TypeScript compiler for transpilation purposes at all. It doesn't make sense because it could introduce subtle differences between the transpilation output in tests and in my app bundles.

I'd like to have a way to disable ts-jest completely and just use babel-jest for transpilation. I've already figured out that I can disable this part:

if (/^typescript$|tsx?$/.test(lang)) {
return transformer || typescriptTransformer

with a config such as this:

const { constants } = require('jest-config');

module.exports = {
  transform: {
    [constants.DEFAULT_JS_PATTERN]: 'babel-jest',
    '^.+\\.vue$': '@vue/vue3-jest',
  },
  globals: {
    'vue-jest': {
      // weird way of disabling ts-jest-based transformer
      transform: {
        '^typescript$': 'babel-jest',
        '^tsx?$': 'babel-jest'
      }
    }
  },
};

but then I've found out that ts-jest is still being required through here:

const tsconfig = getTsJestConfig(config)

So my current workaround for this is this:

const { constants } = require('jest-config');
const os = require('os');

module.exports = {
  transform: {
    [constants.DEFAULT_JS_PATTERN]: 'babel-jest',
    '^.+\\.vue$': '@vue/vue3-jest',
  },
  globals: {
    'vue-jest': {
      // weird way of disabling ts-jest-based transformer
      transform: {
        '^typescript$': 'babel-jest',
        '^tsx?$': 'babel-jest'
      },
      // redirect tsconfig lookup elsewhere so vue-jest doesn't attempt to load ts-jest at all
      tsConfig: os.tmpdir()
    }
  },
};
@miyanokomiya
Copy link

Same here.
I tried to switch from ts-jest to @swc/jest, but I failed due to lack of ts-jest.

https://github.com/miyanokomiya/blendic-svg/runs/5268921002?check_suite_focus=true

Although tests on Github Actions env failed, they passed on my local env(wsl2 ubuntu). I don't know why

@distor-sil3nt
Copy link

This issue is haunting me, too. When I try @Andarist solution and replace babel-jest with @swc/jest I get the error:

[vue-jest] Error: transformer must contain at least one process, preprocess, or postprocess method 

Any chance to remove this dependency on ts-jest?

@nogic1008
Copy link
Collaborator

In fact, ts-jest is only used to load TypeScript configs.
I'll create a PR that replace it to tsconfig package.

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

Successfully merging a pull request may close this issue.

4 participants