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

Running relay tests #410

Closed
sepans opened this issue Aug 8, 2019 · 3 comments
Closed

Running relay tests #410

sepans opened this issue Aug 8, 2019 · 3 comments

Comments

@sepans
Copy link

sepans commented Aug 8, 2019

I have a relay app that was created with CRA and it is working just fine with the config-overrides:

module.exports = override(
  addBabelPlugins(
    "relay",
  ),
);

But when running tests I get the error:

Invariant Violation: graphql: Unexpected invocation at runtime. Either the Babel transform was not set up, or it failed to identify this call site. Make sure it is being used verbatim as 'graphql'

which should be an indication that the relay babel plugin is not loaded. I read through #240 and #241 and as I understood it those overrides are not applied to jest test settings but I am a bit confused how exactly it needs to be setup (sorry the great tools you developed made me lazy and never learned those settings in depth ❤️ ).

A will greatly appreciate your help figuring this out.

Thank you.

PS: the code I am working on is here

@dawnmist
Copy link
Collaborator

dawnmist commented Aug 8, 2019

Thank you for the repo link - it was very helpful, because it meant I could test what I was about to suggest.

React-app-rewired turns on processing of your .babelrc or babel section of your package.json file when running tests.

Try adding the following to your package.json file (note that it is limiting the configuration to being used in the test environment):

  "babel": {
    "env": {
      "test": {
        "plugins": [
          "relay"
        ]
      }
    }
  }

After adding that bit, your tests ran but the sequelize ones complained about having the wrong password/wrong number of assertions. The graphql tests passed. The graphql error you quoted is gone, so I believe that the relay plugin is being used properly.

@sepans
Copy link
Author

sepans commented Aug 8, 2019

Thank you very much for you quick response. It worked. I guess that is equivalent of adding

{
  "env": {
    "test": {
      "plugins": [
        "relay"
      ]
    }
  }
}

in the .babelrc file. Thank you I can take it from here and will post a link to the working test here just for the reference.

sepans added a commit to sepans/ctzen that referenced this issue Aug 8, 2019
The settings that are in config-overrides.js are not applied to tests.
context: timarney/react-app-rewired#410
@sepans
Copy link
Author

sepans commented Aug 8, 2019

It all worked out: sepans/ctzen#19

Taking the liberty and closing the issue. Thanks for your help.

@sepans sepans closed this as completed Aug 8, 2019
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

No branches or pull requests

2 participants