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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Object transformer for transform and moduleNameMapper configs #7135

Closed
yordis opened this issue Oct 10, 2018 · 8 comments
Closed

Support Object transformer for transform and moduleNameMapper configs #7135

yordis opened this issue Oct 10, 2018 · 8 comments

Comments

@yordis
Copy link
Contributor

yordis commented Oct 10, 2018

馃殌 Feature Proposal

Allow specifying a JavaScript object that represents the transformer on transform and moduleNameMapper configuration.

Motivation

I created a factory function that creates some Jest configurations. In the JavaScript section, I have something like this

transform: {
  '\\.(js|jsx|ts|tsx)$': require.resolve('./transforms/babelTransform.js'),
}

Because the transforms are set up by specifying a file I lose the factory configuration when I call the function.

const createJestConfigFactory = (opts)=> {
  return {
    transforms: {
       // this is not a function call so I lose the scope for `opts`
       '\\.(js|jsx|ts|tsx)$': require.resolve('./transforms/babelTransform.js')
    }
  }
};

Example

An example of how this could be fixed:

const transformCreator = (opts)=> {
  return {
    // this object is a transformer
    process: ()=> {
      // ...
    }
  };
};

const createJestConfigFactory = (opts)=> {
  return {
    transforms: {
       // this is not a function call so I lose the scope for `opts`
       '\\.(js|jsx|ts|tsx)$': transformCreator(opts)
    }
  }
};

Pitch

Adding features like this one give more flexibility and power to advanced configurations.

@yordis
Copy link
Contributor Author

yordis commented Oct 21, 2018

Worth to mention, I need this feature for this transformer https://github.com/straw-hat-team/jest-config/blob/a8a02da278df3169273345546fb669beb405f6c2/transforms/fileTransform.js#L8-L22

I want to be able to specify if I am in React ecosystem or not so I could ignore that transform.

@SimenB
Copy link
Member

SimenB commented Oct 21, 2018

Specifying a transform directly instead of pointing to a module Jest requires seems like a great idea! We need to make sure it's not an issue when serializing the config to and from workers, though

@yordis
Copy link
Contributor Author

yordis commented Oct 21, 2018

@SimenB for my personal knowledge, what do you mean by this?

We need to make sure it's not an issue when serializing the config to and from workers, though

I don't understand the underline architecture and I would like to if you don't mind to point me to some documentation about it or elaborate a little bit more about it, please.

@yordis
Copy link
Contributor Author

yordis commented Oct 26, 2018

Definitely, the workers are an issue right now. 馃槩

@jharris4
Copy link

Hi, I just made a PR with a similar feature to what was discussed here: #7398

I was able to get the config to support transforms as functions, and added unit tests to show that it works.

That said, I'm not sure what this issue with workers is, and whether I need to address anything related to that... ?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 2, 2022

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 2, 2022
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

4 participants