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

Custom transform options return jest options #10987

Closed
tiagoporto opened this issue Dec 30, 2020 · 3 comments
Closed

Custom transform options return jest options #10987

tiagoporto opened this issue Dec 30, 2020 · 3 comments

Comments

@tiagoporto
Copy link

🐛 Bug Report

To Reproduce

Steps to reproduce the behavior:

jest.config.js

module.exports = {
  roots: ['<rootDir>/src'],
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
  transform: {
    '\\.[jt]sx?$': 'babel-jest',
+    '\\.json$': ['<rootDir>/custom-transformer.js', { prefix: 'app' }],
  },
}

custom-transformer.js

module.exports = {
  process(sourceText, sourcePath, transformOptions) {
    console.log(transformOptions)

    return sourceText
  },
}

The parameter transformOptions returns the entire jest config

{
  automock: false,
  cache: false,
  cacheDirectory: '/private/var/folders/g0/c7ddp8415wv43nw2r2jbys7h0000gn/T/jest_dx',
  clearMocks: false,
  coveragePathIgnorePatterns: [ '/node_modules/' ],
  cwd: '/Volumes/Data/Development/gerador-validador-cpf',
  detectLeaks: false,
  detectOpenHandles: false,
  errorOnDeprecated: false,
  extraGlobals: [],
  forceCoverageMatch: [],
  globals: {},
  haste: { computeSha1: false, throwOnModuleCollision: false },
  injectGlobals: true,
  moduleDirectories: [ 'node_modules' ],
  moduleFileExtensions: [ 'ts', 'tsx', 'js', 'jsx' ],
  moduleNameMapper: []
  modulePathIgnorePatterns: [],
  name: 'cb79043c053af8ccc4b659f65a7e5758',
  prettierPath: 'prettier',
  resetMocks: false,
  resetModules: false,
  restoreMocks: false,
  rootDir: '/Volumes/Data/Development/gerador-validador-cpf',
  roots: [ '/Volumes/Data/Development/gerador-validador-cpf/src' ],
  runner: 'jest-runner',
  setupFiles: [],
  setupFilesAfterEnv: [],
  skipFilter: false,
  slowTestThreshold: 5,
  snapshotSerializers: [],
  testEnvironment: '/Volumes/Data/Development/gerador-validador-cpf/node_modules/jest-environment-jsdom/build/index.js',
  testEnvironmentOptions: {},
  testLocationInResults: false,
  testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ],
  testPathIgnorePatterns: [ '/node_modules/' ],
  testRegex: [],
  testRunner: '/Volumes/Data/Development/gerador-validador-cpf/node_modules/jest-jasmine2/build/index.js',
  testURL: 'http://localhost',
  timers: 'real',
  transform: [
    [
      '\\.[jt]sx?$',
      '/Volumes/Data/Development/gerador-validador-cpf/node_modules/babel-jest/build/index.js',
      {}
    ],
    [
      '\\.json$',
      '/Volumes/Data/Development/gerador-validador-cpf/custom-transformer.js',
      [Object]
    ]
  ],
  transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
  watchPathIgnorePatterns: []
}

Expected behavior

Is expected only the options for the custom transform

{ prefix: 'app' }

envinfo

 System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-2435M CPU @ 2.40GHz
  Binaries:
    Node: 14.15.3 - /usr/local/bin/node
    npm: 6.14.9 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3 

@SimenB
Copy link
Member

SimenB commented Dec 30, 2020

That's expected in Jest 26 (https://github.com/facebook/jest/blob/v26.6.3/packages/jest-transform/src/ScriptTransformer.ts#L308-L312). However, in Jest 27 (jest@next) the API is changed via #10926

https://github.com/facebook/jest/blob/e3d5491642c336ba76bbc08708345f45ed8d13c6/packages/jest-transform/src/ScriptTransformer.ts#L304-L310

As mentioned in the linked PR you can export a createTransformer function that will receive the options in Jest 26

@SimenB SimenB closed this as completed Dec 30, 2020
@tiagoporto
Copy link
Author

Thank you @SimenB

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants