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

Compatibility for Jest 28 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

EvHaus
Copy link

@EvHaus EvHaus commented Apr 29, 2022

jest-transform-graphql module fails in Jest 28 with this error:

Invalid return value:
      `process()` or/and `processAsync()` method of code transformer found at 
      "/Users/evhaus/Git/zenhub/node_modules/jest-transform-graphql/index.js" 
      should return an object or a Promise resolving to an object. The object 
      must have `code` property with a string of processed code.
      This error may be caused by a breaking change in Jest 28:
      https://jestjs.io/docs/upgrading-to-jest28#transformer
      Code Transformation Documentation:
      https://jestjs.io/docs/code-transformation

This is due to the change here: https://jestjs.io/docs/upgrading-to-jest28#transformer

Unfortunately this PR will make jest-transform-graphql no longer compatible with Jest <=27, so it would need to be published a new major version change.

You can test this PR by installing it your project via this npm dependency definition:

"devDependencies": {
    "jest-transform-graphql": "remind101/jest-transform-graphql#pull/11/head",
}

`jest-transform-graphql` module fails in Jest 18 with this error:

```
Invalid return value:
      `process()` or/and `processAsync()` method of code transformer found at 
      "/Users/evhaus/Git/zenhub/node_modules/jest-transform-graphql/index.js" 
      should return an object or a Promise resolving to an object. The object 
      must have `code` property with a string of processed code.
      This error may be caused by a breaking change in Jest 28:
      https://jestjs.io/docs/upgrading-to-jest28#transformer
      Code Transformation Documentation:
      https://jestjs.io/docs/code-transformation
```

This is due to the change here: https://jestjs.io/docs/upgrading-to-jest28#transformer

Unfortunately this PR will make `jest-transform-graphql` no longer compatible with Jest <=27, so it would need to be published a new major version change.
@benrowe-chuffed
Copy link

I think you mean Jest 28, but im having the same issue.

@EvHaus EvHaus changed the title Compatibility for Jest 18 Compatibility for Jest 2 Apr 30, 2022
@EvHaus EvHaus changed the title Compatibility for Jest 2 Compatibility for Jest 28 Apr 30, 2022
@JiaboHou JiaboHou mentioned this pull request May 13, 2022
@JiaboHou
Copy link

JiaboHou commented May 13, 2022

Unfortunately this PR will make jest-transform-graphql no longer compatible with Jest <=27, so it would need to be published a new major version change.

Are you sure? I've tried installing this version to a private repo of mine still on jest 27.5.1, and the tests are still working for me. Could I be doing something wrong?

@EvHaus
Copy link
Author

EvHaus commented May 13, 2022

Are you sure?

Not at all. I assumed that because of the API syntax change older versions might not support it, but I'm happy to be wrong here. I do suspect though that not all older versions of Jest will support it. It's good that 27 does but what about 26, 25, 24? I haven't tested to see where it falls apart.

@JiaboHou
Copy link

That's fair. Better safe than sorry to mention that for sure. I did some quick digging and it looks like according to the types definition file at least, strings and TransformedSource types have been supported for quite some time.

Looks like support for returning a TransformedSource type was introduced here, in version... v20?: Aftabnack/jest@c6d2b08#diff-0edc0d624e256a618a4b6ca7fe68e9a198c70b4a7c20144b0ca2e4410c7efb94R45

@gerisztein
Copy link

any update on this?

@chrisbruford
Copy link

for anyone waiting for this to be merged - you can just put the contents of index.js into a file in your own repo and then refer to that file in your jest config e.g.

transform: {
    '\\.(gql|graphql)$': './src/utils/gqlTransformer',
    '\\.[jt]sx?$': 'babel-jest'
}

@dobesv
Copy link

dobesv commented Jul 13, 2022

This change should be good, but I guess the project is no longer maintained.

@neatcoding
Copy link

It would be great if the maintainer released this.

Solves issue #13

@andypearson
Copy link

andypearson commented Oct 28, 2023

Has anyone managed to get this fix working with TypeScript, Apollo, and Jest 29?

I've implemented this change to the process function, but now I seem to be getting:

TypeError: Cannot convert object to primitive value
    at String.concat (<anonymous>)

At the point that the GraphQL is used in my client code, for example:

const { ... } = useQuery(getViewerQuery)

Any thoughts would be appreciated, I've already lost 4 hours :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.