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

Expo constants are undefined when executing tests #96

Open
2 tasks
sayo96 opened this issue Jan 16, 2023 · 4 comments
Open
2 tasks

Expo constants are undefined when executing tests #96

sayo96 opened this issue Jan 16, 2023 · 4 comments
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature

Comments

@sayo96
Copy link

sayo96 commented Jan 16, 2023

Describe the bug

A clear and concise description of what the bug is.
I'm running into an error which says "Can't read manifest of undefined" when running tests. I do have a mock in place but i guess the issue lies within bugsnag-expo

For some weird reason, Constants appear as undefined here

if (Constants.manifest) {

Please do note that i have a mock function which mocks the expo constants as well

Steps to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Environment

  • Bugsnag version: 47.1.0
  • Expo SDK version (e.g. SDK 44): SDK 47 EAS Build
  • Device (e.g. iphonex):

Example Repo

  • Create a minimal repository that can reproduce the issue
  • Link to it here:

Example code snippet

# (Insert code sample to reproduce the problem)
Error messages: ● Test suite failed to run
TypeError: Cannot read property 'manifest' of undefined

  at Object.<anonymous> (node_modules/@bugsnag/expo/src/config.js:12:15)
  at Object.<anonymous> (node_modules/@bugsnag/expo/src/notifier.js:17:64)

This might be the possible fix :
expo/eas-cli#1265 (comment)

If yes, please implement it and publish it in a next release so i could use it

@johnkiely1
Copy link
Member

Hi @sayo96,

I'm not sure the suggested fix is the same issue, as it appears to be catering for the scenario where Constants.manifest returns null. For some modern expo apps we would expect Constants.manifest to return null in which case we check Constants.manifest2. In your case it's Constants that is returning undefined so never checks for either manifest.

At what point are you seeing this error?

Would you mind sharing some details on how you are mocking the various packages? Especially the expo-constants one.

Thanks

@johnkiely1 johnkiely1 added the awaiting feedback Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks. label Jan 17, 2023
@sayo96
Copy link
Author

sayo96 commented Jan 19, 2023

Hey @johnkiely1 . I apologise for the delayed reply. I was caught up with other expo bugs.

Here is what we did :

  • We upgraded to SDK 47 (EAS Build)
  • We had a dedicated mock for mocking expo constants which was present within the mocks directory adjacent to the node_modules
  • Due to some weird reason, it was not getting detected. I had to manually add the mock in the jest setup file to fix this bug
jest.mock('expo-constants', () => {
  return {  
    default:{
      expoConfig: {
        ios: { buildNumber: '1.0' },
        version: '2.0.0', 
        releaseChannel: 'staging-v1', 
       
      getWebViewUserAgentAsync: jest.fn().mockResolvedValue({
        _id: 'userAgent'
      })
    },
    expoConfig: {
      ios: { buildNumber: '1.0' },
      version: '2.0.0', 
      releaseChannel: 'staging-v1', 
    getWebViewUserAgentAsync: jest.fn().mockResolvedValue({
      _id: 'userAgent'
    })
  }; 
});

I had to add stuff in default to prevent the manifest bug which is kinda hack tbh.. Can you also let me know why the mock file was not considered?

@johnkiely1 johnkiely1 removed the awaiting feedback Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks. label Feb 1, 2023
@johnkiely1
Copy link
Member

Thanks @sayo96,

I'm glad you've found a fix. It looks like any code uses require then default needs to be defined as that’s how expo-constants is exported, so what you've done is actually the correct way to resolve this and not so much of a hack.

Having said that we are looking into the possibly at replacing our usage of require with import which would be another way for this to be resolved. This has been added to the backlog, I don't have an ETA for this but we will post updates here as soon as we get them.

@johnkiely1 johnkiely1 added feature request Request for a new feature backlog We hope to fix this feature/bug in the future labels Feb 2, 2023
@sayo96
Copy link
Author

sayo96 commented Feb 5, 2023

@johnkiely1 Sounds good thanks a ton :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants