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

Local package imports not resolved in jest tests #71

Open
qroac opened this issue Nov 25, 2019 · 2 comments
Open

Local package imports not resolved in jest tests #71

qroac opened this issue Nov 25, 2019 · 2 comments

Comments

@qroac
Copy link

qroac commented Nov 25, 2019

In several gql files, I use imports from local packages, holding the files for the different modules of my application.
The statements look like this:
#import "@gqlapp/my-package/someFolder/File.graphql"

Is there any trick to get this path resolved correctly for jest?
Building and running the app with babel and webpack works great, but as soon as I run my jest tests, I get the following error:

server: FAIL ../../modules/moduel-A/server-ts/__tests__/A.test.ts
server:   ● Test suite failed to run
server:     ENOENT: no such file or directory, open '/builds/repo/project-app/modules/module-A/common/graphql/@gqlapp/module-B-common/graphql/MyDefinition.graphql'
server:       at Object.getSources (node_modules/babel-plugin-import-graphql/build/customImport.js:33:40)
server:       at node_modules/babel-plugin-import-graphql/build/requireGql.js:108:37
server:           at Array.forEach (<anonymous>)
server:       at Object.processFragments (node_modules/babel-plugin-import-graphql/build/requireGql.js:107:60)
server:       at processDoc (node_modules/babel-plugin-import-graphql/build/requireGql.js:157:7)
server:       at requireGql (node_modules/babel-plugin-import-graphql/build/requireGql.js:57:13)
server:       at PluginPass.exit (node_modules/babel-plugin-import-graphql/build/index.js:78:53)
server:       at newFn (node_modules/@babel/traverse/lib/visitors.js:193:21)
server:       at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:53:20)
server:       at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:40:17)
server:       at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:97:8)
server:       at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:118:16)
server:       at TraversalContext.visitMultiple (node_modules/@babel/traverse/lib/context.js:85:17)
server:       at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:144:19)
server:       at Function.traverse.node (node_modules/@babel/traverse/lib/index.js:94:17)
server:       at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:95:18)
server:       at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:118:16)
server:       at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:90:19)
server:       at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:146:19)
server:       at Function.traverse.node (node_modules/@babel/traverse/lib/index.js:94:17)
@MLKiiwy
Copy link

MLKiiwy commented Jun 16, 2020

I confirm this issue, the moduleNameMapper configuration of jest is not applied to #import commands.

@MLKiiwy
Copy link

MLKiiwy commented Jun 16, 2020

A workaround is to add another plugin to babel: https://www.npmjs.com/package/babel-plugin-module-name-mapper

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