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

Documentation is not clear about how to use source maps in custom transformers #10305

Closed
fcostarodrigo opened this issue Jul 23, 2020 · 6 comments

Comments

@fcostarodrigo
Copy link

🐛 Bug Report

Documentation is not clear about how to use source maps in custom transformers.
Additionally, if you don't pass any source maps, jest will report a failed assertion in a random position in the original not transformed source code.

To Reproduce

Steps to reproduce the behavior:

  1. Visit Custom transformers documentation page.
  2. Create a custom transform following the documentation.
  3. Create a test that fails.
  4. See the jest output pointing at a random position in the original source code.

Expected behavior

Inform how the source map should be returned by a custom transformer.
If the code was transformed and the source map was not provided, don't just assume the lines and columns will match.

Link to repl or repo (highly encouraged)

https://repl.it/@fcostarodrigo/JestCustomTransformIssue

Screenshot 2020-07-23 at 09 03 06

I am using CoffeeScript just as an example.

envinfo

  System:
    OS: Linux 5.4 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (4) x64 Intel(R) Xeon(R) CPU @ 2.30GHz
  Binaries:
    Node: 12.18.2 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0 
@Mskat
Copy link

Mskat commented Apr 3, 2021

Can I grab it?

@thymikee
Copy link
Collaborator

thymikee commented Apr 3, 2021

@Mskat sure! :)

@fcostarodrigo
Copy link
Author

There is a code snippet in https://jestjs.io/docs/next/code-transformation#writing-custom-transformers (next version doc), reading the types you can see the structure expected by the source map. But maybe if the code is transformed and no source map is provided, maybe jest shouldn't try to display the position in the file where the error occurs.

@SimenB
Copy link
Member

SimenB commented Apr 22, 2021

A note about the shape of the return value of transformer in the docs (without going via "how to write") is probably still a good idea even if we've added some details to that page.


I don't think we should try to detect if source maps are used - code might be transformed in a way that does not change line/column position etc.. If you transform the code, you should return sourcemaps, and us assuming that code running is either original or provide source maps seems like a fine assumption to make

@SimenB
Copy link
Member

SimenB commented Apr 4, 2022

#12566 (hopefully clearer now, also #12407)

@SimenB SimenB closed this as completed Apr 4, 2022
@github-actions
Copy link

github-actions bot commented May 5, 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 5, 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