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

Ensure Pretender is importable in node #269

Closed
wants to merge 8 commits into from
Closed

Conversation

samselikoff
Copy link
Contributor

@samselikoff samselikoff commented Sep 13, 2019

Fixes #268

@samselikoff
Copy link
Contributor Author

@stefanpenner think this is ready for review!

LMK if someone else I should @

@samselikoff
Copy link
Contributor Author

This works for Pretender's iife build but not it's ES module build, which we found out when trying to use it in a Gatsby app.

The problem is whatwg-fetch is not importable in node.

We're kinda struggling about what to do here. One option would be to vendor whatwg-fetch into a local module and wrap it in a if (typeof window !== undefined). That way that local module (and thus the ES build of Pretender) can be imported in any environment.

What do you think? Any tips on how to solve this in another way?

@samselikoff
Copy link
Contributor Author

Think we're in a good spot! Gonna test it on some of my projects now

@coveralls
Copy link

coveralls commented Sep 14, 2019

Coverage Status

Coverage increased (+0.04%) to 95.833% when pulling a0a6585 on importable-in-node into 49fdd8a on master.

@samselikoff
Copy link
Contributor Author

Seems to be working everywhere \o/

@samselikoff
Copy link
Contributor Author

There's one more thing...

Need more tests to cover ES build case in non-browser environment.

@samselikoff
Copy link
Contributor Author

To clarify, we need to actually run the real functionality tests against the ES build in a browser-like (jsdom) environment. Need to see what cross-fetch imports there and ensure it lets Pretender work against fetch.

@samselikoff
Copy link
Contributor Author

Closing for now as stale

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.

Make Pretender importable in node
2 participants