diff --git a/e2e/__tests__/__snapshots__/logger.test.ts.snap b/e2e/__tests__/__snapshots__/logger.test.ts.snap index c4060d043f..0f10b2138a 100644 --- a/e2e/__tests__/__snapshots__/logger.test.ts.snap +++ b/e2e/__tests__/__snapshots__/logger.test.ts.snap @@ -127,63 +127,6 @@ Array [ ] `; -exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "default" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7-string-config" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - exports[`ts-jest logging deprecation warning with packageJson config should pass using template "default" 1`] = ` √ jest ↳ exit code: 0 diff --git a/e2e/__tests__/logger.test.ts b/e2e/__tests__/logger.test.ts index aa3219f7db..de56f30177 100644 --- a/e2e/__tests__/logger.test.ts +++ b/e2e/__tests__/logger.test.ts @@ -92,22 +92,6 @@ describe('ts-jest logging', () => { } describe('deprecation warning', () => { - describe('with astTransformers config as string array', () => { - const testCase = configureTestCase('simple', { - tsJestConfig: { - astTransformers: [] - } - }) - - testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => { - it(testLabel, () => { - const result = runTest() - expect(result.status).toBe(0) - expect(result).toMatchSnapshot() - }) - }) - }) - describe('with packageJson config', () => { const testCase = configureTestCase('simple', { tsJestConfig: { diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index be1aa55eea..5d61f765e0 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -154,8 +154,6 @@ describe('compilerModule', () => { }) // compilerModule describe('customTransformers', () => { - const logger = testing.createLoggerMock() - it.each([ {}, { @@ -189,29 +187,6 @@ describe('customTransformers', () => { expect(cs.customTransformers).toMatchSnapshot() }) - - it('should return an object containing all resolved transformers when astTransformers config is an array', () => { - expect( - createConfigSet({ - jestConfig: { - rootDir: 'src', - cwd: 'src', - } as any, - logger, - tsJestConfig: { - astTransformers: ['/__mocks__/dummy-transformer'], - }, - resolve: null, - }).customTransformers, - ).toMatchInlineSnapshot(` - Object { - "before": Array [ - [Function], - [Function], - ], - } - `) - }) }) describe('tsCompiler', () => { diff --git a/src/config/config-set.ts b/src/config/config-set.ts index b1d6ef9308..4c4a7e64e7 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -291,49 +291,34 @@ export class ConfigSet { before: [hoisting(this)], } if (astTransformers) { - if (Array.isArray(astTransformers)) { - this.logger.warn(Deprecations.AstTransformerArrayConfig) + const resolveTransformers = (transformers: (string | AstTransformer)[]) => + transformers.map((transformer) => { + let transformerPath: string + if (typeof transformer === 'string') { + transformerPath = this.resolvePath(transformer, { nodeResolve: true }) - this.customTransformers = { - before: [ - ...this.customTransformers.before, - ...astTransformers.map((transformer) => { - const transformerPath = this.resolvePath(transformer, { nodeResolve: true }) - - return require(transformerPath).factory(this) - }), - ], - } - } else { - const resolveTransformers = (transformers: (string | AstTransformer)[]) => - transformers.map((transformer) => { - let transformerPath: string - if (typeof transformer === 'string') { - transformerPath = this.resolvePath(transformer, { nodeResolve: true }) - - return require(transformerPath).factory(this) - } else { - transformerPath = this.resolvePath(transformer.path, { nodeResolve: true }) + return require(transformerPath).factory(this) + } else { + transformerPath = this.resolvePath(transformer.path, { nodeResolve: true }) - return require(transformerPath).factory(this, transformer.options) - } - }) - if (astTransformers.before) { - this.customTransformers = { - before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)], + return require(transformerPath).factory(this, transformer.options) } + }) + if (astTransformers.before) { + this.customTransformers = { + before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)], } - if (astTransformers.after) { - this.customTransformers = { - ...this.customTransformers, - after: resolveTransformers(astTransformers.after), - } + } + if (astTransformers.after) { + this.customTransformers = { + ...this.customTransformers, + after: resolveTransformers(astTransformers.after), } - if (astTransformers.afterDeclarations) { - this.customTransformers = { - ...this.customTransformers, - afterDeclarations: resolveTransformers(astTransformers.afterDeclarations), - } + } + if (astTransformers.afterDeclarations) { + this.customTransformers = { + ...this.customTransformers, + afterDeclarations: resolveTransformers(astTransformers.afterDeclarations), } } } diff --git a/src/types.ts b/src/types.ts index 82c67133d7..6a5552ebf1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -83,7 +83,7 @@ export interface TsJestGlobalOptions { /** * Custom transformers (mostly used by jest presets) */ - astTransformers?: string[] | ConfigCustomTransformer + astTransformers?: ConfigCustomTransformer /** * TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be: diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 36dae04c9d..d740530d45 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -35,7 +35,6 @@ export const enum Deprecations { ConfigOption = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.', ConfigOptionWithNote = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.\n ↳ {{note}}', ConfigOptionUseBabelRcNote = 'See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845', - AstTransformerArrayConfig = 'The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers', PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`', }