From 08e74e617ba8b2c533e47fbca9f3671a9f12ca6c Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Wed, 6 Feb 2019 16:10:40 -0800 Subject: [PATCH] Polyfill fetch() for tests Summary: Per title. Required as Scribe is now being used for device tests. Reviewed By: jknoxville, danielbuechele Differential Revision: D13971892 fbshipit-source-id: 2df36d44d4e45a579cc9cca0d4cad9105ba8a383 --- package.json | 1 + static/globalTestSetup.js | 2 ++ yarn.lock | 28 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4aaa26e5e..e84751a1d 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "flow-bin": "^0.91.0", "glob": "^7.1.2", "jest": "^23.6.0", + "jest-fetch-mock": "^2.1.0", "prettier": "1.13.6", "redux-mock-store": "^1.5.3" }, diff --git a/static/globalTestSetup.js b/static/globalTestSetup.js index ae8a72c84..363d55d89 100644 --- a/static/globalTestSetup.js +++ b/static/globalTestSetup.js @@ -12,3 +12,5 @@ console.error = function(message) { ); defaultConsoleError.apply(console, arguments); }; + +global.fetch = require('jest-fetch-mock'); diff --git a/yarn.lock b/yarn.lock index ba42ba330..de01d9427 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1890,6 +1890,14 @@ cross-env@^5.2.0: cross-spawn "^6.0.5" is-windows "^1.0.0" +cross-fetch@^2.2.2: + version "2.2.3" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.3.tgz#e8a0b3c54598136e037f8650f8e823ccdfac198e" + integrity sha512-PrWWNH3yL2NYIb/7WF/5vFG3DCQiXDOVf8k3ijatbrtnwNuhMWLC7YF7uqf53tbTFDzHIUD8oITw4Bxt8ST3Nw== + dependencies: + node-fetch "2.1.2" + whatwg-fetch "2.0.4" + cross-spawn@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" @@ -4038,6 +4046,14 @@ jest-environment-node@^23.4.0: jest-mock "^23.2.0" jest-util "^23.4.0" +jest-fetch-mock@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-2.1.0.tgz#49c16451b82f311158ec897e467d704e0cb118f9" + integrity sha512-jrTNlxDsZZCq6tMhdyH7gIbt4iDUHRr6C4Jp+kXItLaaaladOm9/wJjIwU3tCAEohbuW/7/naOSfg2A8H6/35g== + dependencies: + cross-fetch "^2.2.2" + promise-polyfill "^7.1.1" + jest-get-type@^22.1.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" @@ -4901,6 +4917,11 @@ node-dir@0.1.8: resolved "https://registry.yarnpkg.com/node-dir/-/node-dir-0.1.8.tgz#55fb8deb699070707fb67f91a460f0448294c77d" integrity sha1-VfuN62mQcHB/tn+RpGDwRIKUx30= +node-fetch@2.1.2: + version "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: version "1.7.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" @@ -5524,6 +5545,11 @@ progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" +promise-polyfill@^7.1.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-7.1.2.tgz#ab05301d8c28536301622d69227632269a70ca3b" + integrity sha512-FuEc12/eKqqoRYIGBrUptCBRhobL19PS2U31vMNTfyck1FxPyMfgsXyW4Mav85y/ZN1hop3hOwRlUDok23oYfQ== + promise-retry@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d" @@ -7166,7 +7192,7 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3: dependencies: iconv-lite "0.4.23" -whatwg-fetch@>=0.10.0: +whatwg-fetch@2.0.4, whatwg-fetch@>=0.10.0: version "2.0.4" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"