Skip to content

Commit

Permalink
Merge pull request #77 from gladly-team/kevin/fetch-polyfill
Browse files Browse the repository at this point in the history
Use Next.js' fetch polyfill
  • Loading branch information
kmjennison authored Jul 21, 2020
2 parents 398897e + a728016 commit c29c782
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 28 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ module.exports = {
'react/jsx-one-expression-per-line': 0,
// The jsx-wrap-multilines rule conflicts with Prettier.
// https://github.com/prettier/prettier/issues/1009#issuecomment-286993938
"react/jsx-wrap-multilines": ["error", {"declaration": false, "assignment": false}],
'react/jsx-wrap-multilines': [
'error',
{
declaration: false,
assignment: false
}],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error'
},
Expand All @@ -18,7 +23,7 @@ module.exports = {
// https://stackoverflow.com/a/49211283
{
files: ['**/*.test.js', '**/__mocks__/**/*.js'],
'extends': ['plugin:jest/recommended'],
extends: ['plugin:jest/recommended'],
env: {
jest: true
},
Expand All @@ -36,6 +41,10 @@ module.exports = {
env: {
es6: true
},
globals: {
// Polyfilled in Next.js 9.4.
fetch: 'writable',
},
settings: {
'import/resolver': {
alias: [
Expand Down
2 changes: 2 additions & 0 deletions jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ console.error = function (message, ...args) {
error.apply(console, args) // keep default behaviour
throw message instanceof Error ? message : new Error(message)
}

global.fetch = jest.fn(() => Promise.resolve())
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"dotenv": "^8.2.0",
"firebase": "^7.14.2",
"firebase-admin": "^8.11.0",
"isomorphic-unfetch": "^3.0.0",
"lodash": "^4.17.15",
"moment": "^2.26.0",
"next": "^9.4.4",
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/pages/account.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { shallow } from 'enzyme'
import fetch from 'isomorphic-unfetch'
import { unregister } from 'next-offline/runtime'
import Button from '@material-ui/core/Button'
import Divider from '@material-ui/core/Divider'
Expand All @@ -15,7 +14,6 @@ import { clearAllServiceWorkerCaches } from 'src/utils/caching'
import { setWindowLocation } from 'src/utils/navigation'
import SetV4BetaMutation from 'src/utils/mutations/SetV4BetaMutation'

jest.mock('isomorphic-unfetch')
jest.mock('next-offline/runtime')
jest.mock('src/components/SettingsPage')
jest.mock('src/utils/pageWrappers/withAuthAndData')
Expand Down
1 change: 0 additions & 1 deletion src/pages/account.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import fetch from 'isomorphic-unfetch'
import { unregister } from 'next-offline/runtime'
import { graphql } from 'react-relay'
import { makeStyles } from '@material-ui/core/styles'
Expand Down
1 change: 0 additions & 1 deletion src/pages/beta-opt-in.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
// import PropTypes from 'prop-types'
import { unregister } from 'next-offline/runtime'
import fetch from 'isomorphic-unfetch'
import Link from 'src/components/Link'
import { apiBetaOptIn, dashboardURL } from 'src/utils/urls'
import { clearAllServiceWorkerCaches } from 'src/utils/caching'
Expand Down
6 changes: 0 additions & 6 deletions src/utils/__tests__/createRelayEnvironment.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import getMockFetchResponse from 'src/utils/testHelpers/getMockFetchResponse'

jest.mock('relay-runtime')
jest.mock('isomorphic-unfetch')
jest.mock('src/utils/ssr')

beforeEach(() => {
Expand All @@ -28,8 +27,6 @@ beforeEach(() => {
})

process.env.RELAY_ENDPOINT = '/mock-relay-endpoint/here/'

const fetch = require('isomorphic-unfetch').default
fetch.mockResolvedValue(getMockFetchResponse())
})

Expand Down Expand Up @@ -171,7 +168,6 @@ describe('createRelayEnvironment', () => {
expect.assertions(1)
const createRelayEnvironment = require('src/utils/createRelayEnvironment')
.default
const fetch = require('isomorphic-unfetch').default
fetch.mockResolvedValue(getMockFetchResponse())
createRelayEnvironment({ token: 'some-fake-token' })
const { Network } = require('relay-runtime')
Expand All @@ -192,7 +188,6 @@ describe('createRelayEnvironment', () => {
expect.assertions(1)
const createRelayEnvironment = require('src/utils/createRelayEnvironment')
.default
const fetch = require('isomorphic-unfetch').default
fetch.mockResolvedValue(getMockFetchResponse())
createRelayEnvironment() // no token provided
const { Network } = require('relay-runtime')
Expand All @@ -213,7 +208,6 @@ describe('createRelayEnvironment', () => {
expect.assertions(1)
const createRelayEnvironment = require('src/utils/createRelayEnvironment')
.default
const fetch = require('isomorphic-unfetch').default
fetch.mockResolvedValue({
...getMockFetchResponse(),
json: () => Promise.resolve({ my: 'data' }),
Expand Down
1 change: 0 additions & 1 deletion src/utils/auth/firebaseSessionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// From:
// https://github.com/zeit/next.js/blob/canary/examples/with-firebase-authentication/pages/index.js

import fetch from 'isomorphic-unfetch'
import { apiLogin, apiLogout } from 'src/utils/urls'

export const setSession = async (user) => {
Expand Down
1 change: 0 additions & 1 deletion src/utils/createRelayEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://github.com/zeit/next.js/blob/canary/examples/with-relay-modern/lib/createRelayEnvironment.js

import { Environment, Network, RecordSource, Store } from 'relay-runtime'
import fetch from 'isomorphic-unfetch'
import { isServerSide } from 'src/utils/ssr'
import logger from 'src/utils/logger'

Expand Down
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7398,14 +7398,6 @@ [email protected], isomorphic-fetch@^2.1.1:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isomorphic-unfetch@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-3.0.0.tgz#de6d80abde487b17de2c400a7ef9e5ecc2efb362"
integrity sha512-V0tmJSYfkKokZ5mgl0cmfQMTb7MLHsBMngTkbLY0eXvKqiVRRoZP04Ly+KhKrJfKtzC9E6Pp15Jo+bwh7Vi2XQ==
dependencies:
node-fetch "^2.2.0"
unfetch "^4.0.0"

isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
Expand Down Expand Up @@ -11994,11 +11986,6 @@ ua-parser-js@^0.7.18:
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.20.tgz#7527178b82f6a62a0f243d1f94fd30e3e3c21098"
integrity sha512-8OaIKfzL5cpx8eCMAhhvTlft8GYF8b2eQr6JkCyVdrgjcytyOmPCXrqXFcUnhonRpLlh5yxEZVohm6mzaowUOw==

unfetch@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"
integrity sha512-crP/n3eAPUJxZXM9T80/yv0YhkTEx2K1D3h7D1AJM6fzsWZrxdyRuLN0JH/dkZh1LNH8LxCnBzoPFCPbb2iGpg==

unicode-canonical-property-names-ecmascript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"
Expand Down

1 comment on commit c29c782

@vercel
Copy link

@vercel vercel bot commented on c29c782 Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.