I have "jest": "^29.2.1"
. My unit tests output errors like this:
ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
<transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
ts-jest[backports] (WARN) "[jest-config].globals.ts-jest.tsConfig" is deprecated, use "[jest-config].globals.ts-jest.tsconfig" instead.
ts-jest[backports] (WARN) Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.
My jest.config.ts
is the following:
const config = {
roots: ['<rootDir>/src'],
verbose: true,
globalSetup: './globalSetup.ts',
testEnvironmentOptions: {
url: 'http://localhost/',
},
setupFilesAfterEnv: [],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
preset: 'ts-jest',
transform: {
'^.+\\.tsx?$': ['ts-jest', {}],
'^.+\\.ts?$': ['ts-jest', {}],
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
testMatch: [
'<rootDir>/**/(*.)test.(js|jsx|ts|tsx)',
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
globals: {
'ts-jest': {
babel: true,
tsConfig: 'tsconfig.json',
},
},
}
module.exports = config
I've had a similar warning and the solution was already in the warning message (but I hadn't understood it the first time) You have to move the content of globals
into the transform
keys.
The file must look like this:
const config = {
roots: ['<rootDir>/src'],
verbose: true,
globalSetup: './globalSetup.ts',
testEnvironmentOptions: {
url: 'http://localhost/',
},
setupFilesAfterEnv: [],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
preset: 'ts-jest',
transform: {
'^.+\\.tsx?$': ['ts-jest', {//the content originally placed at "global"
babel: true,
tsConfig: 'tsconfig.json',
}]
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
testMatch: [
'<rootDir>/**/(*.)test.(js|jsx|ts|tsx)',
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
]
}
module.exports = config
Also, it seems you can skip the second transform (the regex expression looks the same) the first one applies both to .ts
and .tsx
files and the second to .t
and .ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With