Skip to content

Commit

Permalink
Merge pull request #24 from wheresrhys/babelify-hackery
Browse files Browse the repository at this point in the history
Babelify hackery
  • Loading branch information
wheresrhys committed Nov 8, 2015
2 parents bfdf9c0 + 28bb937 commit 93212c2
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bower_components/
/node_modules/
npm-debug.log
npm-debug.log
/es5/
Empty file added .npmignore
Empty file.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm install -g bower
- bower install
before_deploy:
- npm-prepublish --verbose
deploy:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# fetch-mock [![Build Status](https://travis-ci.org/wheresrhys/fetch-mock.svg?branch=master)](https://travis-ci.org/wheresrhys/fetch-mock) [![Coverage Status](https://coveralls.io/repos/wheresrhys/fetch-mock/badge.svg)](https://coveralls.io/r/wheresrhys/fetch-mock)
Mock http requests made using fetch (or [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch)). As well as shorthand methods for the simplest use cases, it offers a flexible API for customising mocking behaviour, and can also be persisted (with resettable state) over a series of tests.

## API
## Which version to require
- Browser tests: `require('fetch-mock)`
- Server side tests running in nodejs 4 or higher: `require('fetch-mock/server')`
- Server side tests running in nodejs 0.12 or lower: `require('fetch-mock/es5/server)`

You will need to ensure `fetch` and `Promise` are already available as globals in your environment

- *ES6 is used extensively, so either upgrade to nodejs >=4.x.x or use babel ([example karma config](https://github.com/wheresrhys/fetch-mock/blob/master/karma.conf.js))*
- *You need to ensure `fetch` and `Promise` are already available as globals in your environment*
- *To output useful messages for debugging `export DEBUG=fetch-mock`*

## API
*To output useful messages for debugging `export DEBUG=fetch-mock`*

**`require('fetch-mock')`** exports a singleton with the following methods

Expand Down
25 changes: 0 additions & 25 deletions bower.json

This file was deleted.

11 changes: 0 additions & 11 deletions client.js

This file was deleted.

2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(karma) {
'test/client.js': ['browserify']
},
browserify: {
transform: ['babelify', 'debowerify'],
transform: [['babelify', { presets: ['es2015'] }]],
debug: true
},
browsers: ['Chrome'],
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"name": "fetch-mock",
"version": "0.0.0",
"description": "Mock http requests made using fetch (or isomorphic-fetch)",
"main": "server.js",
"main": "es5/client.js",
"scripts": {
"test": "make test"
"test": "make test",
"prepublish": "babel src --out-dir es5"
},
"repository": {
"type": "git",
Expand All @@ -24,16 +25,16 @@
},
"homepage": "https://github.com/wheresrhys/fetch-mock",
"dependencies": {
"node-fetch": "^1.2.0",
"node-fetch": "^1.3.3",
"debug": "^2.2.0"
},
"devDependencies": {
"babelify": "^6.3.0",
"browserify": "^10.0.0",
"babel": "^6.0.15",
"babel-cli": "^6.1.2",
"babel-preset-es2015": "^6.1.2",
"babelify": "^7.2.0",
"browserify": "^12.0.0",
"chai": "^2.3.0",
"coveralls": "^2.11.2",
"debowerify": "^1.2.1",
"es6-promise": "^2.1.1",
"karma": "^0.12.31",
"karma-browserify": "^4.1.2",
"karma-chai": "^0.1.0",
Expand All @@ -42,9 +43,8 @@
"karma-mocha": "^0.1.10",
"karma-phantomjs-launcher": "^0.2.1",
"mocha": "^2.2.4",
"mocha-lcov-reporter": "0.0.2",
"npm-prepublish": "^1.2.0",
"phantomjs": "^1.9.18",
"sinon": "^1.17.0"
"sinon": "^1.17.0",
"whatwg-fetch": "^0.10.1"
}
}
15 changes: 15 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

if (!window) {
throw 'Incorrect fetch-mock: require(\'fetch-mock/server\') in nodejs >= 4, or require(\'fetch-mock/es5/server\' in nodejs 0.12.x';
}

const FetchMock = require('./fetch-mock');

module.exports = new FetchMock({
theGlobal: window,
Response: window.Response,
Headers: window.Headers,
Blob: window.Blob,
debug: function () {}
});
2 changes: 1 addition & 1 deletion server.js → src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Response = require('node-fetch').Response;
const Headers = require('node-fetch').Headers;
const stream = require('stream');
const FetchMock = require('./src/fetch-mock');
const FetchMock = require('./fetch-mock');

module.exports = new FetchMock({
theGlobal: GLOBAL,
Expand Down
4 changes: 2 additions & 2 deletions test/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

require('fetch');
require('whatwg-fetch');

var fetchMock = require('../client.js');
var fetchMock = require('../src/client.js');

require('./spec')(fetchMock, window);
4 changes: 1 addition & 3 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strit';

require('es6-promise').polyfill();

var fetchMock = require('../server.js');
var fetchMock = require('../src/server.js');
var fetchCalls = [];
var expect = require('chai').expect;
var sinon = require('sinon');
Expand Down

0 comments on commit 93212c2

Please sign in to comment.