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

Transform to inherit default transformer if no match #8574

Closed
danm opened this issue Jun 17, 2019 · 6 comments
Closed

Transform to inherit default transformer if no match #8574

danm opened this issue Jun 17, 2019 · 6 comments

Comments

@danm
Copy link
Contributor

danm commented Jun 17, 2019

Pre question

Am I right in thinking that if no transform property is provided in the Jest config, Jest will use its default compiler (babel-jest)?

If so, should the docs be updated that if a transformer isn't defined, instead of being undefined, it should use babel-jest?

🚀 Feature Proposal

Entries in the transform property use the provided compiler, but if no file is matched, then it uses the default compiler.

Motivation

It isn't clear what the default transformer is, so if adding your own to transformer, for example, an SVG, it is not obvious imo that you have to re clarify other files should use babel-jest.

Additionally, recently Jest has changed babel-jest from an external dependancy to an internal one. This means, if I am using a transformer for just SVGs, I also have to tell the transformer to specifically use babel-jest. But what if Jest changes its mind and prefers to use a different compiler in the future, I'd have to change all transformers to make use of the new compiler.

Example

No transformer selected, uses default (babel-jest), compiles without issue

// package.json
{
  "jest": {
     "clearMocks": true
  }
}

Transformer selected to deal with SVGs, but everything else fails.

// package.json
{
  "jest": {
     "clearMocks": true,
     "transformer": {
        "^.+\\.svg$": "jest-svg-transformer"
     }
  }
}

Transformer selected to deal with SVGs and babel-jest defined - compiles without issue.

// package.json
{
  "jest": {
     "clearMocks": true,
     "transformer": {
        "^.+\\.(ts|tsx|js|jsx)$": "babel-jest",
        "^.+\\.svg$": "jest-svg-transformer"
     }
  }
}

Proposed Example

Transformer selected to deal with SVGs and any files that do not match the transformer pattern, use default compiler. This also means that if Jest moves away from using babel-jest, it doesn't need to be re clarified.

// package.json
{
  "jest": {
     "clearMocks": true,
     "transformer": {
        "^.+\\.svg$": "jest-svg-transformer"
     }
  }
}

I could be missing something somewhere - it might just be an update to the docs. Thoughts?

@danm
Copy link
Contributor Author

danm commented Jun 17, 2019

somewhat related #2076

@jeysal
Copy link
Contributor

jeysal commented Jun 18, 2019

Hey @danm, thanks for the suggestion!
Your understanding of transform is right as far as I can tell, and I agree that the docs saying undefined are confusing - happy to accept a PR changing this :)
With regards to the feature request:

  • The transform docs have a section with the information that you'd need to specify babel-jest manually, if you can think of a way to make that clearer that would be awesome too
  • I'm not sure the default changing is such a big deal - that would probably already be a big breaking change without some more people having to update the config when upgrading
  • If setting transform does not suffice, we'd need a way to nullify the default transform instead

@thernstig
Copy link
Contributor

@danm I also found this confusing, great if you can submit a PR :)

@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

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 Apr 30, 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

3 participants