Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into strict-linting
- Loading branch information
Showing
6 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* globals self */ | ||
exports.Headers = self.Headers | ||
exports.Request = self.Request | ||
exports.Response = self.Response | ||
exports.fetch = self.fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState, useEffect } from 'react' | ||
import unfetchImp from 'unfetch' | ||
import isomorphicUnfetchImp from 'isomorphic-unfetch' | ||
|
||
const testWhatwgFetchMethods = whatWgFetch => { | ||
return ( | ||
whatWgFetch.Headers.name === 'Headers' && | ||
whatWgFetch.Request.name === 'Request' && | ||
whatWgFetch.Response.name === 'Response' | ||
) | ||
} | ||
|
||
const testFetchImports = async () => { | ||
const whatwgFetchImp = await import('whatwg-fetch') | ||
const whatwgFetchReq = require('whatwg-fetch') | ||
const unfetchReq = require('unfetch') | ||
const isomorphicUnfetchReq = require('isomorphic-unfetch') | ||
|
||
let areImportsMatching = | ||
[whatwgFetchImp.fetch, whatwgFetchReq.fetch].every( | ||
lib => lib.name === 'fetch' | ||
) && | ||
[unfetchImp, unfetchReq, isomorphicUnfetchImp, isomorphicUnfetchReq].every( | ||
lib => lib.name === 'bound fetch' | ||
) | ||
|
||
return areImportsMatching && | ||
testWhatwgFetchMethods(whatwgFetchReq) && | ||
testWhatwgFetchMethods(whatwgFetchImp) | ||
? 'pass' | ||
: 'fail' | ||
} | ||
|
||
const Page = () => { | ||
const [testStatus, setTestStatus] = useState('computing') | ||
|
||
useEffect(() => { | ||
testFetchImports().then(status => { | ||
console.log(status) | ||
setTestStatus(status) | ||
}) | ||
}, []) | ||
|
||
return <div id="test-status">{testStatus}</div> | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Link from 'next/link' | ||
|
||
export default () => ( | ||
<div> | ||
<Link href="/fetch">Fetch</Link> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { | ||
nextBuild, | ||
findPort, | ||
waitFor, | ||
nextStart, | ||
killApp, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
|
||
describe('Polyfills', () => { | ||
beforeAll(async () => { | ||
const { stdout, stderr } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
stderr: true, | ||
}) | ||
console.log(stdout) | ||
console.error(stderr) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(async () => { | ||
await killApp(app) | ||
}) | ||
|
||
it('should alias fetch', async () => { | ||
const browser = await webdriver(appPort, '/fetch') | ||
await waitFor(1000) | ||
const text = await browser.elementByCss('#test-status').text() | ||
|
||
expect(text).toBe('pass') | ||
|
||
await browser.close() | ||
}) | ||
}) |