-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
909caae
commit f559f98
Showing
14 changed files
with
316 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
'use strict' | ||
|
||
const EchoServer = require('aegir/utils/echo-server') | ||
const { format } =require('iso-url') | ||
const { format } = require('iso-url') | ||
|
||
let echo = new EchoServer() | ||
|
||
module.exports = { | ||
hooks: { | ||
pre: async () => { | ||
const server = await echo.start() | ||
const { address, port } = server.server.address() | ||
return { | ||
env: { ECHO_SERVER : format({ protocol: 'http:', hostname: address, port })} | ||
} | ||
}, | ||
post: async () => { | ||
await echo.stop() | ||
} | ||
} | ||
} | ||
// module.exports = { | ||
// hooks: { | ||
// pre: async () => { | ||
// const server = await echo.start() | ||
// const { address, port } = server.server.address() | ||
// return { | ||
// env: { ECHO_SERVER : format({ protocol: 'http:', hostname: address, port })} | ||
// } | ||
// }, | ||
// post: async () => { | ||
// await echo.stop() | ||
// } | ||
// } | ||
// } | ||
|
||
echo.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
require: require.resolve('./rn-test.require.js'), | ||
runner: 'mocha', | ||
modules: [ | ||
'react-native-url-polyfill', | ||
'web-streams-polyfill' | ||
], | ||
patches: [{ | ||
path: require.resolve('react-native-polyfill-globals/patches/react-native+0.63.3.patch') | ||
}, { | ||
path: require.resolve('react-native-polyfill-globals/patches/react-native-url-polyfill+1.2.0.patch') | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const { polyfill: polyfillReadableStream } = require('react-native-polyfill-globals/src/readable-stream') | ||
const { polyfill: polyfillURL } = require('react-native-polyfill-globals/src/url') | ||
|
||
polyfillURL() | ||
polyfillReadableStream() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
'use strict' | ||
|
||
const { TimeoutError, AbortError } = require('./error') | ||
const { Response, Request, Headers, fetch } = require('../fetch') | ||
|
||
/** | ||
* @typedef {import('../types').FetchOptions} FetchOptions | ||
* @typedef {import('../types').ProgressFn} ProgressFn | ||
*/ | ||
|
||
/** | ||
* Fetch with progress | ||
* | ||
* @param {string | Request} url | ||
* @param {FetchOptions} [options] | ||
* @returns {Promise<ResponseWithURL>} | ||
*/ | ||
const fetchWithProgress = (url, options = {}) => { | ||
const request = new XMLHttpRequest() | ||
request.open(options.method || 'GET', url.toString(), true) | ||
|
||
const { timeout, headers } = options | ||
|
||
if (timeout && timeout > 0 && timeout < Infinity) { | ||
request.timeout = timeout | ||
} | ||
|
||
if (options.overrideMimeType != null) { | ||
request.overrideMimeType(options.overrideMimeType) | ||
} | ||
|
||
if (headers) { | ||
for (const [name, value] of new Headers(headers)) { | ||
request.setRequestHeader(name, value) | ||
} | ||
} | ||
|
||
if (options.signal) { | ||
options.signal.onabort = () => request.abort() | ||
} | ||
|
||
if (options.onUploadProgress) { | ||
request.upload.onprogress = options.onUploadProgress | ||
} | ||
|
||
request.responseType = 'blob' | ||
|
||
return new Promise((resolve, reject) => { | ||
/** | ||
* @param {Event} event | ||
*/ | ||
const handleEvent = (event) => { | ||
switch (event.type) { | ||
case 'error': { | ||
resolve(Response.error()) | ||
break | ||
} | ||
case 'load': { | ||
resolve( | ||
new ResponseWithURL(request.responseURL, request.response, { | ||
status: request.status, | ||
statusText: request.statusText, | ||
headers: parseHeaders(request.getAllResponseHeaders()) | ||
}) | ||
) | ||
break | ||
} | ||
case 'timeout': { | ||
reject(new TimeoutError()) | ||
break | ||
} | ||
case 'abort': { | ||
reject(new AbortError()) | ||
break | ||
} | ||
default: { | ||
break | ||
} | ||
} | ||
} | ||
request.onerror = handleEvent | ||
request.onload = handleEvent | ||
request.ontimeout = handleEvent | ||
request.onabort = handleEvent | ||
|
||
request.send(/** @type {BodyInit} */(options.body)) | ||
}) | ||
} | ||
|
||
const fetchWithStreaming = fetch | ||
|
||
/** | ||
* @param {string | Request} url | ||
* @param {FetchOptions} options | ||
*/ | ||
const fetchWith = (url, options = {}) => | ||
(options.onUploadProgress != null) | ||
? fetchWithProgress(url, options) | ||
: fetchWithStreaming(url, options) | ||
|
||
/** | ||
* Parse Headers from a XMLHttpRequest | ||
* | ||
* @param {string} input | ||
* @returns {Headers} | ||
*/ | ||
const parseHeaders = (input) => { | ||
const headers = new Headers() | ||
for (const line of input.trim().split(/[\r\n]+/)) { | ||
const index = line.indexOf(': ') | ||
if (index > 0) { | ||
headers.set(line.slice(0, index), line.slice(index + 1)) | ||
} | ||
} | ||
|
||
return headers | ||
} | ||
|
||
class ResponseWithURL extends Response { | ||
/** | ||
* @param {string} url | ||
* @param {BodyInit} body | ||
* @param {ResponseInit} options | ||
*/ | ||
constructor (url, body, options) { | ||
super(body, options) | ||
Object.defineProperty(this, 'url', { value: url }) | ||
} | ||
} | ||
|
||
module.exports = { | ||
fetch: fetchWith, | ||
Request, | ||
Headers, | ||
ResponseWithURL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict' | ||
|
||
const { TextEncoder } = require('web-encoding') | ||
|
||
module.exports = TextEncoder | ||
module.exports = require('web-encoding').TextEncoder |
Oops, something went wrong.