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

Transforms are not ran on snapshotSerializers #3284

Closed
Daniel15 opened this issue Apr 11, 2017 · 7 comments · Fixed by #3399
Closed

Transforms are not ran on snapshotSerializers #3284

Daniel15 opened this issue Apr 11, 2017 · 7 comments · Fixed by #3399
Labels
Milestone

Comments

@Daniel15
Copy link
Contributor

Daniel15 commented Apr 11, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Snapshot serializers can be configured in the Jest config as follows:

  "snapshotSerializers": [
    "<rootDir>/FooSerializer.js"
  ]

However, Jest does not appear to run the file through the transform script. This is blocking me from using Flow in my snapshot serializers, as it throws "SyntaxError: Unexpected identifier" when it tries to execute the file (since it's not being transformed)

It looks like isInternalModule is true in transformAndBuildScript so it's not running the transforms.

What is the expected behavior?
Transforms should be ran on these files.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Internal Facebook www

@rogeliog
Copy link
Contributor

Thanks for reporting!
You can try using expect.addSnapshotSerializer() in the mean time

@Daniel15
Copy link
Contributor Author

Thanks for the suggestion! Could I call addSnapshotSerializer from one of the setupFiles? The issue with adding it in the test itself is that everyone that uses a particular file would need to know to add its serializer. That's why I wanted to configure it in the Jest config 😃

@rogeliog
Copy link
Contributor

I don't think that you can call from the setupFiles... I think that passing it in the config would be the only way

@cpojer
Copy link
Member

cpojer commented Apr 13, 2017

This is definitely a bug!

@thymikee thymikee modified the milestone: Jest 20 Apr 21, 2017
@thymikee
Copy link
Collaborator

@Daniel15 you can use setupTestFrameworkScriptFile just for that, but I guess you probably already solved that 😄.

@Daniel15
Copy link
Contributor Author

@thymikee Good idea! The way I worked around this was simply by avoiding any code that needed to be transformed (ie. no Flow typing), but using setupTestFrameworkScriptFile sounds like a better approach. Thanks for the suggestion :)

@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants