ipfs / js-ipfs-utils

IPFS utils
Other
23 stars 30 forks source link

NodeJS and Electron conflict #82

Open xmaysonnave opened 3 years ago

xmaysonnave commented 3 years ago

Env:

I try to use js-ipfs while testing with NodeJS. As a dependency of ipfs-core, ipfs-utils is installed (dev dependency) https://github.com/ipfs/js-ipfs-utils/blob/master/src/http/fetch.js

This code check whether or not XMLHttpRequest is available in node and redirect to fetch.browser when available. However my environment is node and ipfs-utils crashes as fetch.browser requires the global browser fetch. I could suggest to enhance the initial statement with the following to redirect to fetch.node

if (typeof XMLHttpRequest === 'function' && typeof fetch === 'function') {
  module.exports = require('./fetch.browser')

Thanks

welcome[bot] commented 3 years ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

xmaysonnave commented 3 years ago

jest is responsible of this behaviour. migrated jest tests to chai, mocha and sinon. no more issues

achingbrain commented 3 years ago

Thanks for following up. I think it'd still be a good idea to expand the feature detection as suggested and issues with Jest do come up from time to time.

xmaysonnave commented 3 years ago

Thanks for your feedback. ipfs-provider is using Jest. This is the reason I started to use it a while back. Probably an input in a knowledge base could be interesting as known issues. I enjoy spawning javascript Ipfs server in my tests, great feature. Feel free to close this issue.