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

docs: add note about line discrepancies and returning source maps in code transformers #12566

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/CodeTransformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ As can be seen, only `process` or `processAsync` is mandatory to implement, alth

Note that [ECMAScript module](ECMAScriptModules.md) support is indicated by the passed in `supports*` options. Specifically `supportsDynamicImport: true` means the transformer can return `import()` expressions, which is supported by both ESM and CJS. If `supportsStaticESM: true` it means top level `import` statements are supported and the code will be interpreted as ESM and not CJS. See [Node's docs](https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs) for details on the differences.

:::info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we flip this around? maybe as a tip and something like "make sure your transformation returns a source map so it's possible to map back from the transformed code to the source code in code coverage and error information" or some such? Inline sourcemaps also work, doesn't have to be an explicit return value (although separate is preferred for performance reasons)

Copy link
Contributor Author

@mhnaeem mhnaeem Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing @SimenB. How does this sound?

Make sure TransformedSource contains a source map, so it is possible to report line information accurately in code coverage and test errors. Inline source maps also work but are slower.

I actually didn't know about inline source maps so when I was writing my own code transformer I had to separate our maps because I didn't know that option existed so having this kind of tip should be helpful.


Jest might not be able to report the coverage and error information accurately if a source map is not returned by the `process` or `processAsync` function.

:::

### Examples

### TypeScript with type checking
Expand Down