Remove isomorphic-fetch (#27878) (#27935)

This commit is contained in:
Søren Louv-Jansen 2019-01-03 01:04:42 +01:00 committed by GitHub
parent e874b404da
commit 8ac9387dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 188 additions and 172 deletions

View file

@ -256,7 +256,7 @@
"vision": "^5.3.3",
"webpack": "4.23.1",
"webpack-merge": "4.1.4",
"whatwg-fetch": "^2.0.3",
"whatwg-fetch": "^3.0.0",
"wreck": "^14.0.2",
"x-pack": "6.7.0",
"yauzl": "2.7.0"
@ -287,7 +287,7 @@
"@types/enzyme": "^3.1.12",
"@types/eslint": "^4.16.2",
"@types/execa": "^0.9.0",
"@types/fetch-mock": "^5.12.2",
"@types/fetch-mock": "7.2.1",
"@types/getopts": "^2.0.0",
"@types/glob": "^5.0.35",
"@types/globby": "^8.0.0",
@ -354,7 +354,7 @@
"eslint-plugin-react": "^7.11.1",
"expect.js": "0.3.1",
"faker": "1.1.0",
"fetch-mock": "^5.13.1",
"fetch-mock": "7.3.0",
"geckodriver": "1.12.2",
"getopts": "2.0.0",
"grunt": "1.0.1",

View file

@ -1,126 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#batchSet Buffers are always clear of previously buffered changes: two requests, second only sends bar, not foo 1`] = `
Object {
"matched": Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
],
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"bar\\":\\"box\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
"method": "POST",
},
],
"unmatched": Array [],
}
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"bar\\":\\"box\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
]
`;
exports[`#batchSet Overwrites previously buffered values with new values for the same key: two requests, foo=d in final 1`] = `
Object {
"matched": Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"a\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"a\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
],
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"d\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
"method": "POST",
},
],
"unmatched": Array [],
}
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"d\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
]
`;
exports[`#batchSet buffers changes while first request is in progress, sends buffered changes after first request completes: final, includes both requests 1`] = `
Object {
"matched": Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
],
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"box\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
"method": "POST",
},
],
"unmatched": Array [],
}
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"box\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
},
],
]
`;
exports[`#batchSet buffers changes while first request is in progress, sends buffered changes after first request completes: initial, only one request 1`] = `
Object {
"matched": Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
],
"method": "POST",
},
],
"unmatched": Array [],
}
]
`;
exports[`#batchSet rejects all promises for batched requests that fail: promise rejections 1`] = `
@ -147,22 +135,19 @@ exports[`#batchSet rejects on 404 response 1`] = `"Request failed with status co
exports[`#batchSet rejects on 500 1`] = `"Request failed with status code: 500"`;
exports[`#batchSet sends a single change immediately: synchronous fetch 1`] = `
Object {
"matched": Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
"method": "POST",
Array [
Array [
"/foo/bar/api/kibana/settings",
Object {
"body": "{\\"changes\\":{\\"foo\\":\\"bar\\"}}",
"credentials": "same-origin",
"headers": Object {
"accept": "application/json",
"content-type": "application/json",
"kbn-version": "v9.9.9",
},
],
"method": "POST",
},
],
"unmatched": Array [],
}
]
`;

View file

@ -17,7 +17,8 @@
* under the License.
*/
import fetchMock from 'fetch-mock';
// @ts-ignore
import fetchMock from 'fetch-mock/es5/client';
import * as Rx from 'rxjs';
import { takeUntil, toArray } from 'rxjs/operators';
@ -142,10 +143,16 @@ describe('#batchSet', () => {
fetchMock.once('*', {
body: { settings: {} },
});
fetchMock.once('*', {
status: 400,
body: 'invalid',
});
fetchMock.once(
'*',
{
status: 400,
body: 'invalid',
},
{
overwriteRoutes: false,
}
);
const { uiSettingsApi } = setup();
// trigger the initial sync request, which enabled buffering
@ -161,7 +168,7 @@ describe('#batchSet', () => {
).resolves.toMatchSnapshot('promise rejections');
// ensure only two requests were sent
expect(fetchMock.calls().matched).toHaveLength(2);
expect(fetchMock.calls()).toHaveLength(2);
});
});
@ -191,10 +198,16 @@ describe('#getLoadingCount$()', () => {
fetchMock.once('*', {
body: { settings: {} },
});
fetchMock.once('*', {
status: 400,
body: 'invalid',
});
fetchMock.once(
'*',
{
status: 400,
body: 'invalid',
},
{
overwriteRoutes: false,
}
);
const { uiSettingsApi } = setup();
const done$ = new Rx.Subject();

View file

@ -24,3 +24,5 @@ bluebird.Promise.setScheduler(function (fn) { global.setImmediate.call(global, f
const MutationObserver = require('mutation-observer');
Object.defineProperty(window, 'MutationObserver', { value: MutationObserver });
require('whatwg-fetch');

View file

@ -26,7 +26,7 @@ jest.mock('../metadata', () => ({
},
}));
import fetchMock from 'fetch-mock';
import fetchMock from 'fetch-mock/es5/client';
import { kfetch } from 'ui/kfetch';
import { isAutoCreateIndexError } from './error_auto_create_index';

View file

@ -27,7 +27,8 @@ jest.mock('../metadata', () => ({
},
}));
import fetchMock from 'fetch-mock';
// @ts-ignore
import fetchMock from 'fetch-mock/es5/client';
import {
addInterceptor,
Interceptor,
@ -46,13 +47,13 @@ describe('kfetch', () => {
it('should use supplied request method', async () => {
fetchMock.post('*', {});
await kfetch({ pathname: 'my/path', method: 'POST' });
expect(fetchMock.lastOptions('*').method).toBe('POST');
expect(fetchMock.lastOptions()!.method).toBe('POST');
});
it('should use supplied Content-Type', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: 'my/path', headers: { 'Content-Type': 'CustomContentType' } });
expect(fetchMock.lastOptions('*').headers).toMatchObject({
expect(fetchMock.lastOptions()!.headers).toMatchObject({
'Content-Type': 'CustomContentType',
});
});
@ -60,7 +61,7 @@ describe('kfetch', () => {
it('should use supplied pathname and querystring', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: 'my/path', query: { a: 'b' } });
expect(fetchMock.lastUrl('*')).toBe('http://localhost.com/myBase/my/path?a=b');
expect(fetchMock.lastUrl()).toBe('http://localhost.com/myBase/my/path?a=b');
});
it('should use supplied headers', async () => {
@ -70,7 +71,7 @@ describe('kfetch', () => {
headers: { myHeader: 'foo' },
});
expect(fetchMock.lastOptions('*').headers).toEqual({
expect(fetchMock.lastOptions()!.headers).toEqual({
'Content-Type': 'application/json',
'kbn-version': 'my-version',
myHeader: 'foo',
@ -79,28 +80,27 @@ describe('kfetch', () => {
it('should return response', async () => {
fetchMock.get('*', { foo: 'bar' });
expect(await kfetch({ pathname: 'my/path' })).toEqual({
foo: 'bar',
});
const res = await kfetch({ pathname: 'my/path' });
expect(res).toEqual({ foo: 'bar' });
});
it('should prepend url with basepath by default', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: 'my/path' });
expect(fetchMock.lastUrl('*')).toBe('http://localhost.com/myBase/my/path');
expect(fetchMock.lastUrl()).toBe('http://localhost.com/myBase/my/path');
});
it('should not prepend url with basepath when disabled', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: 'my/path' }, { prependBasePath: false });
expect(fetchMock.lastUrl('*')).toBe('my/path');
expect(fetchMock.lastUrl()).toBe('/my/path');
});
it('should make request with defaults', async () => {
fetchMock.get('*', {});
await kfetch({ pathname: 'my/path' });
expect(fetchMock.lastOptions('*')).toEqual({
expect(fetchMock.lastOptions()!).toEqual({
method: 'GET',
credentials: 'same-origin',
headers: {
@ -169,7 +169,7 @@ describe('kfetch', () => {
});
it('should make request', () => {
expect(fetchMock.called('*')).toBe(true);
expect(fetchMock.called()).toBe(true);
});
it('should return response', () => {
@ -205,7 +205,7 @@ describe('kfetch', () => {
});
it('should make request', () => {
expect(fetchMock.called('*')).toBe(true);
expect(fetchMock.called()).toBe(true);
});
it('should return response', () => {
@ -245,7 +245,7 @@ describe('kfetch', () => {
});
it('should not make request', () => {
expect(fetchMock.called('*')).toBe(false);
expect(fetchMock.called()).toBe(false);
});
it('should throw error', () => {
@ -285,7 +285,7 @@ describe('kfetch', () => {
});
it('should make request', () => {
expect(fetchMock.called('*')).toBe(true);
expect(fetchMock.called()).toBe(true);
});
it('should throw error', () => {
@ -328,7 +328,7 @@ describe('kfetch', () => {
});
it('should not make request', () => {
expect(fetchMock.called('*')).toBe(false);
expect(fetchMock.called()).toBe(false);
});
it('should resolve', () => {
@ -355,7 +355,7 @@ describe('kfetch', () => {
});
it('should modify request', () => {
expect(fetchMock.lastOptions('*')).toMatchObject({
expect(fetchMock.lastOptions()!).toMatchObject({
addedByRequestInterceptor: true,
method: 'GET',
});
@ -390,7 +390,7 @@ describe('kfetch', () => {
});
it('should modify request', () => {
expect(fetchMock.lastOptions('*')).toMatchObject({
expect(fetchMock.lastOptions()!).toMatchObject({
addedByRequestInterceptor: true,
method: 'GET',
});

View file

@ -17,7 +17,6 @@
* under the License.
*/
import 'isomorphic-fetch';
import { merge } from 'lodash';
// @ts-ignore not really worth typing
import { metadata } from 'ui/metadata';
@ -61,7 +60,7 @@ export async function kfetch(
query,
});
return fetch(fullUrl, restOptions).then(async res => {
return window.fetch(fullUrl, restOptions).then(async res => {
const body = await getBodyAsJson(res);
if (res.ok) {
return body;

View file

@ -76,7 +76,7 @@
"enzyme-to-json": "3.3.1",
"expect.js": "0.3.1",
"fancy-log": "^1.3.2",
"fetch-mock": "^5.13.1",
"fetch-mock": "7.3.0",
"graphql-code-generator": "^0.13.0",
"graphql-codegen-introspection-template": "^0.13.0",
"graphql-codegen-typescript-resolvers-template": "^0.13.0",
@ -182,7 +182,6 @@
"inline-style": "^2.0.0",
"intl": "^1.2.5",
"io-ts": "^1.4.2",
"isomorphic-fetch": "2.2.1",
"joi": "^13.5.2",
"jquery": "^3.3.1",
"jsonwebtoken": "^8.3.0",

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import 'isomorphic-fetch';
import { flatten, memoize } from 'lodash';
import { escapeQuotes } from './escape_kuery';
import { kfetch } from 'ui/kfetch';

View file

@ -9,7 +9,6 @@
// service for interacting with the server
import chrome from 'ui/chrome';
import 'isomorphic-fetch';
import { addSystemApiHeader } from 'ui/system_api';

View file

@ -1342,10 +1342,10 @@
resolved "https://registry.yarnpkg.com/@types/expect.js/-/expect.js-0.3.29.tgz#28dd359155b84b8ecb094afc3f4b74c3222dca3b"
integrity sha1-KN01kVW4S47LCUr8P0t0wyItyjs=
"@types/fetch-mock@^5.12.2":
version "5.12.2"
resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-5.12.2.tgz#8c96517ff74303031c65c5da2d99858e34c844d2"
integrity sha512-5YopFLn3TCnzQ1Z49xeKuOOcNGLlSNiWnEhcGA7uI6aSpZvb7vZHnpP0bbf2RNQ0P9sSgiHvr6IKj9nsTQR3sA==
"@types/fetch-mock@7.2.1":
version "7.2.1"
resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-7.2.1.tgz#5630999aa75532e00af42a54cbe05e1651f4a080"
integrity sha512-zuLhLEK4gOPxhkiUhqbG4p0lKY2ePEE//5NHTTn/vjYl0XWpfk2x0Fw7EWKtCjlggEsuc1GvpasD46X9PSZFaA==
"@types/form-data@^2.2.1":
version "2.2.1"
@ -8716,14 +8716,15 @@ fecha@^2.3.3:
resolved "https://registry.yarnpkg.com/fecha/-/fecha-2.3.3.tgz#948e74157df1a32fd1b12c3a3c3cdcb6ec9d96cd"
integrity sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg==
fetch-mock@^5.13.1:
version "5.13.1"
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-5.13.1.tgz#955794a77f3d972f1644b9ace65a0fdfd60f1df7"
integrity sha512-eWUo2KI4sRGnRu8tKELCBfasALM5BfvrCxdI7J02j3eUM9mf+uYzJkURA0PSn/29JVapVrYFm+z+9XijXu1PdA==
fetch-mock@7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-7.3.0.tgz#4bf41190c19477c4c86ce1739972035bb02b3add"
integrity sha512-KxBeS8vsADFbWPVomuwxYqOJ2obZo6CidgkypjDPeu6zl+tAJvh2GfLDmJ8u//xgBGM9iOGwOxafeqAclilH2A==
dependencies:
glob-to-regexp "^0.3.0"
node-fetch "^1.3.3"
path-to-regexp "^1.7.0"
babel-polyfill "^6.26.0"
glob-to-regexp "^0.4.0"
path-to-regexp "^2.2.1"
whatwg-url "^6.5.0"
figgy-pudding@^3.1.0, figgy-pudding@^3.5.1:
version "3.5.1"
@ -9564,6 +9565,11 @@ glob-to-regexp@^0.3.0:
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=
glob-to-regexp@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.0.tgz#49bd677b1671022bd10921c3788f23cdebf9c7e6"
integrity sha512-fyPCII4vn9Gvjq2U/oDAfP433aiE64cyP/CJjRJcpVGjqqNdioUYn9+r0cSzT1XPwmGAHuTT7iv+rQT8u/YHKQ==
glob-watcher@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/glob-watcher/-/glob-watcher-0.0.6.tgz#b95b4a8df74b39c83298b0c05c978b4d9a3b710b"
@ -11987,7 +11993,7 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
isomorphic-fetch@2.2.1, isomorphic-fetch@^2.1.1:
isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=
@ -15026,7 +15032,7 @@ node-fetch@2.1.2:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
node-fetch@^1.0.1, node-fetch@^1.3.3:
node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==
@ -16179,6 +16185,11 @@ path-to-regexp@^1.7.0:
dependencies:
isarray "0.0.1"
path-to-regexp@^2.2.1:
version "2.4.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.4.0.tgz#35ce7f333d5616f1c1e1bfe266c3aba2e5b2e704"
integrity sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==
path-type@3.0.0, path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
@ -22835,12 +22846,12 @@ whatwg-encoding@^1.0.4:
dependencies:
iconv-lite "0.4.23"
whatwg-fetch@2.0.4, whatwg-fetch@^2.0.3:
whatwg-fetch@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==
whatwg-fetch@>=0.10.0:
whatwg-fetch@>=0.10.0, whatwg-fetch@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==
@ -22859,6 +22870,15 @@ whatwg-url@^6.3.0:
tr46 "^1.0.0"
webidl-conversions "^4.0.1"
whatwg-url@^6.5.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8"
integrity sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==
dependencies:
lodash.sortby "^4.7.0"
tr46 "^1.0.1"
webidl-conversions "^4.0.2"
whatwg-url@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.0.0.tgz#fde926fa54a599f3adf82dff25a9f7be02dc6edd"