Comments (14)
Hello,
You can still use version 1.x.x of fetch-mock in node 0.12, but I recommend upgrading to node 4.2 (which is deemed stable and supported) to use fetchMock 2. There are some nice new shorthand features available as of v2.2.2, so there are benefits to using the latest code.
In node 0.12 It may be possible to create a wrapper module something like
require('babel/register');
module.exports = require('fetch-mock');
And then require this in your tests. Let me know how you get on
from fetch-mock.
I’m already using Babel in my project but by default Babel ignores anything in node_modules
.
Right now I’m using fetch-mock 1.x. I think I’ll just update Node to 4.x when I have more time at work.
from fetch-mock.
@wheresrhys would upgrading to node 4.2 solve this issue when running in a Karma/Babel/PhantomJS test running scenario?
from fetch-mock.
Is this PhantomJs 2? Phantomjs 1.9.x has really out of date support for a lot of browser APIs so I wouldn't expect it to work there, but I haven't tried in Phantom2. I'll add Phantom2 and firefox to CI to see if it unearths any specific problems.
from fetch-mock.
PhantomJS 2 dies because it doesn't understand ES6 syntax (the exact error is related to not understanding const
).
from fetch-mock.
weird, babel should take care of that. Does your karma.conf contain a line like this https://github.com/wheresrhys/fetch-mock/blob/master/karma.conf.js#L15 and do you have babelify installed as a dev dependency?
On a different project I had a very similar problem a few days ago (unrelated to fetch-mock and running in karma-firefox), which suggests it was a babelify/karma-browserify bug. It seemed to have fixed itself spontaneously yesterday, so maybe try (if you haven't already) rm -Rf node_modules
and reinstall all your dependencies too. This is the project that was broken and fixed itself https://github.com/Financial-Times/next-feature-flags-client/tree/mvt
from fetch-mock.
Yep, just added phantom and firefox to ci and all runs fine, so I reckon it's some glitchy version of something in the karma-babel-browserify setup you're running
from fetch-mock.
I'm in the same situation as @sapegin, where I'm using Babel but by default Babel ignores anything in node_modules
.
from fetch-mock.
I'll consider adding a babelified build to future npm releases, but have
you tried passing {ignore:false} in to babel-core/register. Does that not
work?
On Sat, 7 Nov 2015 at 5:16 p.m., Liam Morley [email protected]
wrote:
I'm in the same situation as @sapegin https://github.com/sapegin, where
I'm using Babel but by default Babel ignores anything in node_modules.—
Reply to this email directly or view it on GitHub
#21 (comment)
.
from fetch-mock.
That would make Babel muuuch slower.
from fetch-mock.
I think this comes out of a general desire not to export library code in ES6. I think there are some tools to help with the translation, so that anyone with any setup can plop it into their node_modules without having to track down a SyntaxError. Maybe something like this? http://www.hammerlab.org/2015/07/09/bundling-and-distributing-complex-es6-libraries-in-an-es5-world/
from fetch-mock.
For Node (not browser) it’s just Babel, like this.
from fetch-mock.
v2 of fetch-mock does explicitly drop support for non es6 environments https://github.com/wheresrhys/fetch-mock/releases/tag/v2.0.0, so I'm not too concerned about node<4 (but will document better).
Probably gonna have to include a pre-babelified version for the browser though, which is a pain. npm & babel should solve this problem
from fetch-mock.
Fixed with the PR above.
from fetch-mock.
Related Issues (20)
- regexp matchers cannot always be overwritten HOT 2
- fetch-mock does not forward requests correctly when jsdom-global is in effect
- fetch-mock Response.body is not always a stream in Node.js HOT 3
- Is there a reason for partial package.json in dist directory?
- Jest v27 requires syntax that docs state is not needed for `reset()` method. HOT 1
- Provide RequestInit object to native fetch on Safari HOT 1
- Problem with fetch-mock and HMR HOT 3
- Update node-fetch dependency to v3.x.x HOT 5
- Querystring is deprecated
- Unable to use fetch-mock as ES6 import HOT 10
- fetch-mock: No fallback response defined for GET to https://jsonmock.hackerrank.com/api/stocks/?date=1-January-2002
- [Bug] Using fetch-mock with the decorator function results in internal error HOT 5
- When a matcher fails because a header matches the key but not the value, other matchers aren't considered
- Returning different values for different requests on the same URL HOT 3
- Response always undefined in .calls? HOT 1
- regenerator global Function call throws CSP unsafe-eval error HOT 2
- Typescript: FetchMockSandbox and native fetch have incompatible types HOT 1
- [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" HOT 1
- Response.error() is not being treated as a response HOT 1
- Allow access to `express`-style path parameters in mocked endpoints
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch-mock.