Unverified Commit d11a3aa3 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add tests for isomorphic-unfetch bundling issue (#5805)

* Add tests for isomorphic-unfetch bundling issue

* Remove unneeded extra option

* Remove isomorphic-fetch
parent 01b34bb7
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
"fkill": "5.1.0", "fkill": "5.1.0",
"flatten": "1.0.2", "flatten": "1.0.2",
"get-port": "3.2.0", "get-port": "3.2.0",
"isomorphic-unfetch": "3.0.0",
"jest-cli": "23.6.0", "jest-cli": "23.6.0",
"jest-junit": "^5.0.0", "jest-junit": "^5.0.0",
"lerna": "^3.4.0", "lerna": "^3.4.0",
......
...@@ -213,7 +213,8 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer ...@@ -213,7 +213,8 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer
], ],
alias: { alias: {
next: NEXT_PROJECT_ROOT next: NEXT_PROJECT_ROOT
} },
mainFields: [!isServer && 'browser', !isServer && 'module', 'main'].filter(Boolean)
} }
const webpackMode = dev ? 'development' : 'production' const webpackMode = dev ? 'development' : 'production'
......
import fetch from 'isomorphic-unfetch'
import React from 'react'
export default class extends React.Component {
static async getInitialProps () {
try {
const res = await fetch('')
const text = await res.text()
console.log(text)
return {text}
} catch (err) {
if (err.message.includes('is not a function')) {
return {failed: true, error: err.toString()}
}
return {error: err.toString()}
}
}
render () {
const {failed, error, text} = this.props
return <div className='fetch-page'>
{failed ? 'failed' : ''}
{error}
<div id='text'>
{text}
</div>
</div>
}
}
export default () => 'Hello World' import Link from 'next/link'
export default () => {
return <div>
Hello World
<Link href='/fetch'>
<a id='fetchlink'>fetch page</a>
</Link>
</div>
}
...@@ -8,6 +8,8 @@ import { ...@@ -8,6 +8,8 @@ import {
stopApp, stopApp,
renderViaHTTP renderViaHTTP
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver'
import fetch from 'node-fetch'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
let appPort let appPort
...@@ -35,4 +37,26 @@ describe('Lambdas', () => { ...@@ -35,4 +37,26 @@ describe('Lambdas', () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/) expect(html).toMatch(/Hello World/)
}) })
it('should render correctly when importing isomorphic-unfetch', async () => {
const url = `http://localhost:${appPort}/fetch`
const res = await fetch(url)
expect(res.status).toBe(200)
const text = await res.text()
expect(text.includes('failed')).toBe(false)
})
it('should render correctly when importing isomorphic-unfetch on the client side', async () => {
const browser = await webdriver(appPort, '/')
try {
const text = await browser
.elementByCss('a').click()
.waitForElementByCss('.fetch-page')
.elementByCss('#text').text()
expect(text).toMatch(/fetch page/)
} finally {
browser.close()
}
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment