Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate classes/transformer-plugin with ts-jest #528

Closed
GwendalBroudin-Emoko opened this issue Jan 18, 2023 · 0 comments
Closed

Integrate classes/transformer-plugin with ts-jest #528

GwendalBroudin-Emoko opened this issue Jan 18, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@GwendalBroudin-Emoko
Copy link

Is your feature request related to a problem? Please describe.

Currently, transformer-plugin can't be used with jest, this create a big difference in behaviour with the runtime environment.

Describe the solution you'd like

The perfect solution would be to have the transformer-plugin as an astTransformers in ts-jest like this

import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
  moduleFileExtensions: ['js', 'json', 'ts'],
  rootDir: '..',
  moduleDirectories: ['node_modules', '<rootDir>'],
  testRegex: '.*\\.spec\\.ts$',
  transform: {
    '^.+\\.(t|j)s$': [
      'ts-jest',
      {
        astTransformers: {
          before: ['@automapper/classes/transformer-plugin'],
        },
      },
    ],
  },
  collectCoverageFrom: ['**/*.(t|j)s'],
  coverageDirectory: '../coverage',
  testEnvironment: 'node',
};

export default jestConfig;

Describe alternatives you've considered

No response

Additional context

As is, this config produce the following error:

ts-jest[config] (WARN) The AST transformer {{file}} must have an `export const version = <your_transformer_version>` {
  file: '.../node_modules/@automapper/classes/transformer-plugin/index.cjs'
}

...

 FAIL  src/modules/jobs/crud/job.mapping.spec.ts
  ● Test suite failed to run

    TypeError: beforeTransformer.factory is not a function

      at node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:222:42
          at Array.map (<anonymous>)
      at TsCompiler._makeTransformers (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:221:47)
      at Object.getCustomTransformers (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:294:63)
      at Object.getEmitOutput (node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:168067:73)
      at TsCompiler.getCompiledOutput (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js:142:48)
      at TsJestCompiler.getCompiledOutput (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js:14:39)
      at TsJestTransformer.processWithTs (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:265:37)
      at TsJestTransformer.process (node_modules/.pnpm/[email protected]_r24ewcothphvclnu77pxb4u4se/node_modules/ts-jest/dist/legacy/ts-jest-transformer.js:188:24)
      at ScriptTransformer.transformSource (node_modules/.pnpm/@[email protected]/node_modules/@jest/transform/build/ScriptTransformer.js:519:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/.pnpm/@[email protected]/node_modules/@jest/transform/build/ScriptTransformer.js:648:40)
      at ScriptTransformer.transform (node_modules/.pnpm/@[email protected]/node_modules/@jest/transform/build/ScriptTransformer.js:700:19)
@GwendalBroudin-Emoko GwendalBroudin-Emoko added the enhancement New feature or request label Jan 18, 2023
@nartc nartc closed this as completed in 018c666 Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant