fetch-mock
Advanced tools
Comparing version 1.0.0 to 1.0.1
'use strict'; | ||
var Response = window.Response; | ||
var Headers = window.Headers; | ||
function mockResponse (url, config) { | ||
// allow just body to be passed in as this is the commonest use case | ||
if (typeof config === 'string' || !(config.body || config.headers || config.throws || config.status)) { | ||
config = { | ||
body: config | ||
}; | ||
} | ||
if (config.throws) { | ||
return Promise.reject(config.throws); | ||
} | ||
var opts = config.opts || {}; | ||
opts.url = url; | ||
opts.status = config.status || 200; | ||
opts.headers = config.headers ? new Headers(config.headers) : new Headers(); | ||
if (config.body != null) { | ||
var body = config.body; | ||
if (typeof body === 'object') { | ||
body = JSON.stringify(body); | ||
} | ||
} | ||
return Promise.resolve(new Response(body, opts)); | ||
} | ||
var FetchMock = require('./src/fetch-mock'); | ||
module.exports = new FetchMock({ | ||
mockResponse: mockResponse, | ||
theGlobal: window | ||
theGlobal: window, | ||
Response: window.Response, | ||
Headers: window.Headers, | ||
Blob: window.Blob | ||
}); |
'use strict'; | ||
module.exports = function(karma) { | ||
karma.set({ | ||
var configuration = { | ||
@@ -18,4 +18,18 @@ frameworks: [ 'mocha', 'chai', 'browserify'], | ||
}, | ||
browsers: ['PhantomJS'], | ||
}); | ||
}; | ||
browsers: ['PhantomJS', 'Chrome'], | ||
customLaunchers: { | ||
Chrome_travis_ci: { | ||
base: 'Chrome', | ||
flags: ['--no-sandbox'] | ||
} | ||
} | ||
}; | ||
if(process.env.TRAVIS){ | ||
configuration.browsers = ['PhantomJS', 'Chrome_travis_ci']; | ||
} | ||
karma.set(configuration); | ||
}; | ||
{ | ||
"name": "fetch-mock", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Mock http requests made using fetch (or isomorphic-fetch)", | ||
@@ -38,2 +38,3 @@ "main": "server.js", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.1.8", | ||
"karma-mocha": "^0.1.10", | ||
@@ -40,0 +41,0 @@ "karma-phantomjs-launcher": "^0.1.4", |
@@ -6,36 +6,9 @@ 'use strict'; | ||
var stream = require('stream'); | ||
function mockResponse (url, config) { | ||
// allow just body to be passed in as this is the commonest use case | ||
if (typeof config === 'string' || !(config.body || config.headers || config.throws || config.status)) { | ||
config = { | ||
body: config | ||
}; | ||
} | ||
if (config.throws) { | ||
return Promise.reject(config.throws); | ||
} | ||
var opts = config.opts || {}; | ||
opts.url = url; | ||
opts.status = config.status || 200; | ||
opts.headers = config.headers ? new Headers(config.headers) : new Headers(); | ||
var s = new stream.Readable(); | ||
if (config.body != null) { | ||
var body = config.body; | ||
if (typeof body === 'object') { | ||
body = JSON.stringify(body); | ||
} | ||
s.push(body, 'utf-8'); | ||
} | ||
s.push(null); | ||
return Promise.resolve(new Response(s, opts)); | ||
} | ||
var FetchMock = require('./src/fetch-mock'); | ||
module.exports = new FetchMock({ | ||
mockResponse: mockResponse, | ||
theGlobal: GLOBAL | ||
theGlobal: GLOBAL, | ||
Response: Response, | ||
Headers: Headers, | ||
stream: stream | ||
}); |
'use strict'; | ||
var sinon = require('sinon'); | ||
var mockResponse; | ||
var Headers; | ||
var Response; | ||
var stream; | ||
var Blob; | ||
var theGlobal; | ||
function mockResponse (url, config) { | ||
// allow just body to be passed in as this is the commonest use case | ||
if (typeof config === 'string' || !(config.body || config.headers || config.throws || config.status)) { | ||
config = { | ||
body: config | ||
}; | ||
} | ||
if (config.throws) { | ||
return Promise.reject(config.throws); | ||
} | ||
var opts = config.opts || {}; | ||
opts.url = url; | ||
opts.status = config.status || 200; | ||
opts.headers = config.headers ? new Headers(config.headers) : new Headers(); | ||
var body = config.body; | ||
if (config.body != null && typeof body === 'object') { | ||
body = JSON.stringify(body); | ||
} | ||
if (stream) { | ||
var s = new stream.Readable(); | ||
if (body != null) { | ||
s.push(body, 'utf-8'); | ||
} | ||
s.push(null); | ||
body = s; | ||
} | ||
return Promise.resolve(new Response(body, opts)); | ||
} | ||
function compileRoute (route) { | ||
@@ -42,3 +78,6 @@ if (!route.name) { | ||
var FetchMock = function (opts) { | ||
mockResponse = opts.mockResponse; | ||
Headers = opts.Headers; | ||
Response = opts.Response; | ||
stream = opts.stream; | ||
Blob = opts.Blob; | ||
theGlobal = opts.theGlobal; | ||
@@ -45,0 +84,0 @@ this.routes = []; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31218
12