Skip to content

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

Closed
@Andarist

Description

@Andarist

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()
    }
  },
};

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions