Skip to content

Commit

Permalink
Remove unnecessary fetch polyfill from frontend
Browse files Browse the repository at this point in the history
All supported browsers provide a native `fetch` implementation so
remove `isomorphic-fetch` from the polyfills.

Instead of this, we use `node-fetch` directly in the unit tests
and also update `fetch-mock` to the latest version.

These changes, along with the Node.js 14 update, reduce the execution
time for the full suite of unit tests from ~2.5mins to under 1 minute.
  • Loading branch information
AlanGreene authored and tekton-robot committed Oct 3, 2020
1 parent 97b55cf commit 90ca31b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 76 deletions.
5 changes: 5 additions & 0 deletions config_frontend/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ limitations under the License.
*/

import 'react-testing-library/cleanup-after-each';
import fetch from 'node-fetch';
import fetchMock from 'fetch-mock';
import { TextDecoder, TextEncoder } from 'util';
import { ReadableStream } from 'web-streams-polyfill/es6';

if (!global.fetch) {
global.fetch = fetch;
}

fetchMock.catch();
fetchMock.config.overwriteRoutes = true;

Expand Down
122 changes: 51 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"es6-promise": "^4.2.8",
"git-url-parse": "^11.3.0",
"history": "^4.10.1",
"isomorphic-fetch": "^2.2.1",
"js-yaml": "^3.14.0",
"lodash.isequal": "^4.5.0",
"lodash.keyby": "^4.6.0",
Expand Down Expand Up @@ -90,7 +89,7 @@
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.0",
"fetch-mock": "^7.7.3",
"fetch-mock": "^9.10.7",
"fibers": "^5.0.0",
"file-loader": "^6.0.0",
"glob": "^7.1.6",
Expand All @@ -100,6 +99,7 @@
"lodash.difference": "^4.5.0",
"lodash.omit": "^4.5.0",
"mini-css-extract-plugin": "^0.9.0",
"node-fetch": "^2.6.1",
"prettier": "^2.0.5",
"properties-reader": "^2.1.1",
"react-testing-library": "^6.1.2",
Expand Down
5 changes: 4 additions & 1 deletion src/api/extensions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ it('getExtensions', () => {
});

it('getExtensions null', () => {
fetchMock.get(/extensions/, 'null');
fetchMock.get(/extensions/, {
body: 'null',
headers: { 'Content-Type': 'application/json' }
});
return API.getExtensions().then(response => {
expect(response).toEqual([]);
fetchMock.restore();
Expand Down
3 changes: 1 addition & 2 deletions src/utils/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Tekton Authors
Copyright 2019-2020 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -13,7 +13,6 @@ limitations under the License.

import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'isomorphic-fetch';
import 'es6-promise/auto';

import './object-is';
Expand Down

0 comments on commit 90ca31b

Please sign in to comment.