Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@Andarist

Description

@Andarist
Issue body actions

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, yckimura, distor-sil3nt and linkurzweg

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.