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

[Bug]: Code transformation regression in jest 28 #12750

Closed
hbenl opened this issue Apr 26, 2022 · 8 comments
Closed

[Bug]: Code transformation regression in jest 28 #12750

hbenl opened this issue Apr 26, 2022 · 8 comments

Comments

@hbenl
Copy link

hbenl commented Apr 26, 2022

Version

28.0.1

Steps to reproduce

  1. Clone https://github.com/RecordReplay/devtools
  2. Upgrade jest and babel-jest to 28.0.1 and add jest-environment-jsdom
  3. npm run test

Expected behavior

The tests pass as they did with jest 27.

Actual behavior

I get several failures like this one:

    ● Invalid return value:
      Code transformer's `process` method must return an object containing `code` key 
      with processed string. If `processAsync` method is implemented it must return 
      a Promise resolving to an object containing `code` key with processed string.
      Code Transformation Documentation:
      https://jestjs.io/docs/code-transformation
    

       8 | const bundles = {
       9 |   "devtools/client/locales/toolbox.properties": parse(
    > 10 |     require("devtools/client/locales/en-us/toolbox.properties").default
         |     ^
      11 |   ),
      12 |   "devtools/client/locales/debugger.properties": parse(
      13 |     require("devtools/client/locales/en-us/debugger.properties").default

      at ScriptTransformer._buildTransformResult (node_modules/@jest/transform/build/ScriptTransformer.js:504:15)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:623:17)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:760:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:817:19)
      at Object.require (src/shims/l10n.js:10:5)

Additional context

No response

Environment

System:
    OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
  Binaries:
    Node: 16.14.2 - /usr/bin/node
    Yarn: 1.22.18 - ~/replay/devtools/node_modules/.bin/yarn
    npm: 8.5.0 - /usr/bin/npm
  npmPackages:
    jest: ^28.0.1 => 28.0.1
@mrazauskas
Copy link
Contributor

On surface it looks like your transformer’s process method is returning a string instead of an object. See Migration Guide.

Hard to say more without a minimal reproduction. The link repo does not install for me. Cloning it and running npm i throws a bunch of: "Conflicting peer dependency", "Could not resolve dependency", "Fix the upstream dependency conflict, or retry".

@mrazauskas
Copy link
Contributor

Might be enough to change one line inside /test/jest/jest-text-transformer.js:

  process(src) {
    // console.log("Processing file: ", src);
    const escapedSrc = src.replace(/`/g, "\\`").replace(/\$(?=\{.*?\})/g, "\\$");


-   return `module.exports.default = \`${escapedSrc}\``;
+   return { code: `module.exports.default = \`${escapedSrc}\`` };
  },

@SimenB
Copy link
Member

SimenB commented Apr 26, 2022

That's correct 🙂 It also works in older versions of jest, so safe to land that change while still remaining on whatever jest version you have already

@SimenB SimenB closed this as completed Apr 26, 2022
@SimenB
Copy link
Member

SimenB commented Apr 26, 2022

@mrazauskas perhaps we could include the path to the transformer that returns the wrong structure?

We could also link to the upgrade guide in the error message

@mrazauskas
Copy link
Contributor

Right. There are few more places where the link would be useful. I will do this.

@hbenl
Copy link
Author

hbenl commented Apr 27, 2022

Might be enough to change one line [...]

Yes, it works now. Thanks a lot for the help!

perhaps we could include the path to the transformer that returns the wrong structure?

That sounds like a good idea - obviously I had not realized that it was our own transformer (as opposed to some jest internals) that needed to be changed.

@SimenB
Copy link
Member

SimenB commented Apr 29, 2022

https://github.com/facebook/jest/releases/tag/v28.0.3

@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 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