-
Notifications
You must be signed in to change notification settings - Fork 157
Description
It's states that ts-jest is an optional peer dep:
vue-jest/packages/vue3-jest/package.json
Lines 47 to 49 in 6edfa9c
| "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:vue-jest/packages/vue3-jest/lib/utils.js
Line 81 in 6edfa9c
| 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:
vue-jest/packages/vue3-jest/lib/process.js
Lines 21 to 22 in 6edfa9c
| 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:
vue-jest/packages/vue3-jest/lib/process.js
Line 121 in 5741877
| 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()
}
},
};