Upgrading ts-jest 27 to 28
Breaking27.1.5 → 28.0.8Breaking3Security1Platform5Deprecated3New1Changed1Fixed5
BreakingUpgrade verdict
3 breaking changes and 5 platform requirement changes and a security fix.
In plain terms
- The built-in path-mapping transformer is gone; use an alternative package instead.
- Imports from ts-jest/utils must be replaced with imports from ts-jest.
- The mocked helper is removed since Jest now provides it.
- The Jest types package is no longer required to be installed alongside ts-jest.
Must act Top 5 of 12 that need code or config changes
Node.js requirement changed in 28.0.1: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0 → ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0.
Installs 27 packages in all (was 25).
What you must change
Breaking3
Removes the path-mapping AST transformer.
path-mappingRemoves the ts-jest/utils sub path export.
ts-jest/utilsRemoves the mocked testing util.
mockedSecurity1
Updates the version of json5 to address a security concern.
json5Platform5
Updates
@jest/types to be an optional peer dependency.@jest/typesSets
@jest/types as a peer dependency.@jest/typesLowers the required Node version to ^16.10.
Sets Jest peer dependencies to v28.
Drops support for Node.js 10.
Deprecations to plan for
Deprecated3
Marks ConfigSet as legacy.
ConfigSetMarks TsCompiler and TsJestCompiler as legacy.
TsCompilerTsJestCompilerMarks TsJestTransformer as legacy.
TsJestTransformerAPI changes
Generated by DepDelta from published .d.ts files. Not mixed with prose notes.
- added:
const afterAll: typeof import('@jest/globals').afterAll - added:
const afterEach: typeof import('@jest/globals').afterEach - added:
const beforeAll: typeof import('@jest/globals').beforeAll - added:
const beforeEach: typeof import('@jest/globals').beforeEach - added:
const describe: typeof import('@jest/globals').describe - added:
const expect: typeof import('@jest/globals').expect - added:
const fdescribe: typeof import('@jest/globals').fdescribe - added:
const fit: typeof import('@jest/globals').fit - added:
const it: typeof import('@jest/globals').it - added:
const jest: typeof import('@jest/globals').jest - added:
const test: typeof import('@jest/globals').test - added:
const xdescribe: typeof import('@jest/globals').xdescribe - added:
const xit: typeof import('@jest/globals').xit - added:
const xtest: typeof import('@jest/globals').xtest
- removed:
const SOURCE_MAPPING_PREFIX = 'sourceMappingURL=' - removed:
function updateOutput(outputText: string, normalizedFileName: string, sourceMap: string | undefined): string
- removed:
export * from './compiler-utils' - removed:
export * from './ts-compiler' - removed:
export * from './ts-jest-compiler'
- removed:
class TsCompiler implements TsCompilerInstance - removed:
constructor TsCompiler(configSet: ConfigSet, runtimeCacheFS: StringMap) - removed:
method TsCompiler.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string - removed:
method TsCompiler.getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[] - removed:
property TsCompiler.program: Program | undefined - removed:
protected method TsCompiler._makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers - removed:
protected method TsCompiler._transpileOutput(fileContent: string, fileName: string): TranspileOutput - removed:
protected property TsCompiler._compilerOptions: CompilerOptions - removed:
protected readonly property TsCompiler._initialCompilerOptions: CompilerOptions - removed:
protected readonly property TsCompiler._logger: Logger - removed:
protected readonly property TsCompiler._ts: TTypeScript - removed:
readonly property TsCompiler.configSet: ConfigSet - removed:
readonly property TsCompiler.runtimeCacheFS: StringMap
- removed:
class TsJestCompiler implements CompilerInstance - removed:
constructor TsJestCompiler(configSet: ConfigSet, runtimeCacheFS: StringMap) - removed:
method TsJestCompiler.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string - removed:
method TsJestCompiler.getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[]
- removed:
class ConfigSet - removed:
constructor ConfigSet(jestConfig: ProjectConfigTsJest | undefined, parentLogger?: Logger | undefined) - removed:
method ConfigSet.isTestFile(fileName: string): boolean - removed:
method ConfigSet.raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void - removed:
method ConfigSet.resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: { throwIfMissing?: boolean; nodeResolve?: boolean }): string - removed:
method ConfigSet.shouldReportDiagnostics(filePath: string): boolean - removed:
method ConfigSet.shouldStringifyContent(filePath: string): boolean - removed:
property ConfigSet.cacheSuffix: string - removed:
property ConfigSet.parsedTsConfig: ts.ParsedCommandLine | Record<string, any> - removed:
property ConfigSet.resolvedTransformers: TsJestAstTransformer - removed:
property ConfigSet.tsCacheDir: string | undefined - removed:
property ConfigSet.useESM: boolean - removed:
protected method ConfigSet._resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any> - removed:
readonly property ConfigSet.compilerModule: TTypeScript - removed:
readonly property ConfigSet.cwd: string - removed:
readonly property ConfigSet.isolatedModules: boolean - removed:
readonly property ConfigSet.logger: Logger - removed:
readonly property ConfigSet.parentLogger?: Logger | undefined - removed:
readonly property ConfigSet.rootDir: string - removed:
readonly property ConfigSet.tsJestDigest: string
- removed:
export * from './config-set'
- removed:
export * from './compiler' - removed:
export * from './ts-jest-transformer' - changed:
const _default: { createTransformer: () => TsJestTransformer } → const _default: { createTransformer(): TsJestTransformer } - added:
export * from './legacy/compiler' - added:
export * from './legacy/config/config-set' - added:
export * from './legacy/ts-jest-transformer'
- added:
const SOURCE_MAPPING_PREFIX = 'sourceMappingURL=' - added:
function updateOutput(outputText: string, normalizedFileName: string, sourceMap?: string): string
- added:
export * from './ts-compiler' - added:
export * from './ts-jest-compiler'
- added:
class TsCompiler implements TsCompilerInstance - added:
constructor TsCompiler(configSet: ConfigSet, runtimeCacheFS: StringMap) - added:
method TsCompiler.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput - added:
method TsCompiler.getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[] - added:
property TsCompiler.program: Program | undefined - added:
protected method TsCompiler._makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers - added:
protected method TsCompiler._transpileOutput(fileContent: string, fileName: string): TranspileOutput - added:
protected property TsCompiler._compilerOptions: CompilerOptions - added:
protected readonly property TsCompiler._initialCompilerOptions: CompilerOptions - added:
protected readonly property TsCompiler._logger: Logger - added:
protected readonly property TsCompiler._ts: TTypeScript - added:
readonly property TsCompiler.configSet: ConfigSet - added:
readonly property TsCompiler.runtimeCacheFS: StringMap
- added:
class TsJestCompiler implements CompilerInstance - added:
constructor TsJestCompiler(configSet: ConfigSet, runtimeCacheFS: StringMap) - added:
method TsJestCompiler.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput - added:
method TsJestCompiler.getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[]
- added:
class ConfigSet - added:
constructor ConfigSet(jestConfig: ProjectConfigTsJest | undefined, parentLogger?: Logger | undefined) - added:
method ConfigSet.isTestFile(fileName: string): boolean - added:
method ConfigSet.raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void - added:
method ConfigSet.resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: { throwIfMissing?: boolean; nodeResolve?: boolean }): string - added:
method ConfigSet.shouldReportDiagnostics(filePath: string): boolean - added:
method ConfigSet.shouldStringifyContent(filePath: string): boolean - added:
property ConfigSet.cacheSuffix: string - added:
property ConfigSet.parsedTsConfig: ts.ParsedCommandLine | Record<string, any> - added:
property ConfigSet.resolvedTransformers: TsJestAstTransformer - added:
property ConfigSet.tsCacheDir: string | undefined - added:
property ConfigSet.useESM: boolean - added:
protected method ConfigSet._resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any> - added:
readonly property ConfigSet.compilerModule: TTypeScript - added:
readonly property ConfigSet.cwd: string - added:
readonly property ConfigSet.isolatedModules: boolean - added:
readonly property ConfigSet.logger: Logger - added:
readonly property ConfigSet.parentLogger?: Logger | undefined - added:
readonly property ConfigSet.rootDir: string - added:
readonly property ConfigSet.tsJestDigest: string
- added:
const _default: { createTransformer: () => TsJestTransformer } - added:
default _default
- added:
class TsJestTransformer implements SyncTransformer - added:
constructor TsJestTransformer() - added:
method TsJestTransformer.getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string - added:
method TsJestTransformer.getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<string> - added:
method TsJestTransformer.process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource - added:
method TsJestTransformer.processAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<TransformedSource> - added:
protected method TsJestTransformer._createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void - added:
protected method TsJestTransformer._createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet - added:
protected property TsJestTransformer._compiler: CompilerInstance
- changed:
function createJestPreset(allowJs?: boolean, extraOptions?: Config.InitialOptions): TsJestPresets → function createJestPreset(legacy?: boolean, allowJs?: boolean, extraOptions?: Config.InitialOptions): TsJestPresets
- removed:
const name = 'path-mapping' - removed:
const version = 2 - removed:
function factory({ configSet }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>
- removed:
class TsJestTransformer implements SyncTransformer - removed:
constructor TsJestTransformer() - removed:
method TsJestTransformer.getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string - removed:
method TsJestTransformer.getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<string> - removed:
method TsJestTransformer.process(fileContent: string, filePath: Config.Path, transformOptions: TransformOptionsTsJest): TransformedSource | string - removed:
method TsJestTransformer.processAsync(sourceText: string, sourcePath: Config.Path, transformOptions: TransformOptionsTsJest): Promise<TransformedSource | string> - removed:
protected method TsJestTransformer._createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void - removed:
protected method TsJestTransformer._createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet - removed:
protected property TsJestTransformer._compiler: CompilerInstance
- changed:
method CompilerInstance.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): string → method CompilerInstance.getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput - changed:
property TsJestDiagnosticsCfg.exclude: Config.Glob[] → property TsJestDiagnosticsCfg.exclude: string[] - changed:
property TsJestGlobalOptions.diagnostics?: boolean | { pretty?: boolean; ignoreCodes?: number | string | Array<number | string>; exclude?: Config.Glob[]; warnOnly?: boolean } → property TsJestGlobalOptions.diagnostics?: boolean | { pretty?: boolean; ignoreCodes?: number | string | Array<number | string>; exclude?: string[]; warnOnly?: boolean } - added:
interface CompiledOutput extends TransformedSource - added:
property CompiledOutput.diagnostics?: _ts.Diagnostic[] - added:
type TBabelJest = typeof babelJest
- removed:
export { ArgumentsOf } from './testing' - removed:
export { ConstructorArgumentsOf } from './testing' - removed:
export { MaybeMocked } from './testing' - removed:
export { MaybeMockedConstructor } from './testing' - removed:
export { MaybeMockedDeep } from './testing' - removed:
export { MethodKeysOf } from './testing' - removed:
export { MockWithArgs } from './testing' - removed:
export { MockableFunction } from './testing' - removed:
export { MockedFunction } from './testing' - removed:
export { MockedFunctionDeep } from './testing' - removed:
export { MockedObject } from './testing' - removed:
export { MockedObjectDeep } from './testing' - removed:
export { PropertyKeysOf } from './testing'
- removed:
call MockWithArgs(...args: ArgumentsOf<T>): ReturnType<T> - removed:
function mocked<T>(item: T, deep: true): MaybeMockedDeep<T> - removed:
function mocked<T>(item: T, deep?: false): MaybeMocked<T> - removed:
interface MockWithArgs<T extends MockableFunction> extends jest.MockInstance<ReturnType<T>, ArgumentsOf<T>> - removed:
new MockWithArgs(...args: ConstructorArgumentsOf<T>): T - removed:
type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never - removed:
type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never - removed:
type MaybeMocked<T> = T extends MockableFunction ? MockedFunction<T> : T extends object ? MockedObject<T> : T - removed:
type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R ? jest.MockInstance<R, ConstructorArgumentsOf<T>> : T - removed:
type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T - removed:
type MethodKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? K : never }[keyof T] - removed:
type MockableFunction = (...args: any[]) => any - removed:
type MockedFunction<T extends MockableFunction> = MockWithArgs<T> & { [K in keyof T]: T[K] } - removed:
type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T> - removed:
type MockedObject<T> = MaybeMockedConstructor<T> & { [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunction<T[K]> : T[K] } & { [K in PropertyKeysOf<T>]: T[K] } - removed:
type MockedObjectDeep<T> = MaybeMockedConstructor<T> & { [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K] } & { [K in PropertyKeysOf<T>]: MaybeMock… - removed:
type PropertyKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? never : K }[keyof T]
- added:
declare global
- changed:
const _default: { defaults: TsJestPresets; defaultsESM: TsJestPresets; jsWithTs: TsJestPresets; jsWithTsESM: TsJestPresets; jsWithBabel: TsJestPresets; jsWithBabelESM: TsJestP… → const _default: { defaults: TsJestPresets; defaultsLegacy: TsJestPresets; defaultsESM: TsJestPresets; defaultsESMLegacy: TsJestPresets; jsWithTs: TsJestPresets; jsWithTsLegacy…
- removed:
export { createJestPreset } from '../dist/presets/create-jest-preset' - removed:
export { mocked } from '../dist/utils/testing' - removed:
export { pathsToModuleNameMapper } from '../dist/config/paths-to-module-name-mapper'