Unverified Commit e8955cce authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Move fixtures off `node-fetch` (#98346)

I don't believe they tested `node-fetch` specifically and rather used it
because Node.js didn't have a built-in `fetch` implementation.
parent 6ba71046
...@@ -12,7 +12,6 @@ describe('API routes', () => { ...@@ -12,7 +12,6 @@ describe('API routes', () => {
dependencies: { dependencies: {
'http-proxy': 'latest', 'http-proxy': 'latest',
cors: 'latest', cors: 'latest',
'node-fetch': '2.6.7',
}, },
skipDeployment: true, skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
...@@ -602,7 +601,6 @@ describe('API routes output export error', () => { ...@@ -602,7 +601,6 @@ describe('API routes output export error', () => {
dependencies: { dependencies: {
'http-proxy': 'latest', 'http-proxy': 'latest',
cors: 'latest', cors: 'latest',
'node-fetch': '2.6.7',
}, },
skipStart: true, skipStart: true,
skipDeployment: true, skipDeployment: true,
......
import fetch from 'node-fetch' import { Readable } from 'stream'
export default async (req, res) => { export default async (req, res) => {
const dataRes = await fetch( const dataRes = await fetch(
...@@ -6,5 +6,5 @@ export default async (req, res) => { ...@@ -6,5 +6,5 @@ export default async (req, res) => {
) )
res.status(dataRes.status) res.status(dataRes.status)
dataRes.body.pipe(res) Readable.fromWeb(dataRes.body).pipe(res)
} }
...@@ -21,10 +21,6 @@ function streamingBody(stream: Readable) { ...@@ -21,10 +21,6 @@ function streamingBody(stream: Readable) {
describe('app-custom-routes', () => { describe('app-custom-routes', () => {
const { next, isNextDeploy, isNextDev, isNextStart } = nextTestSetup({ const { next, isNextDeploy, isNextDev, isNextStart } = nextTestSetup({
files: __dirname, files: __dirname,
dependencies: {
// pin with repo's version of node-fetch
'@types/node-fetch': '2.6.1',
},
}) })
describe('works with api prefix correctly', () => { describe('works with api prefix correctly', () => {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { sleep } from './sleep'
import { get } from 'http'
describe('streaming responses cancel inner stream after disconnect', () => { describe('streaming responses cancel inner stream after disconnect', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
function prime(url: string, noData?: boolean) { async function prime(url: string, noData?: boolean) {
return new Promise<void>((resolve, reject) => { url = new URL(url, next.url).href
url = new URL(url, next.url).href
// There's a bug in node-fetch v2 where aborting the fetch will never abort const controller = new AbortController()
// the connection, because the body is a transformed stream that doesn't
// close the connection stream.
// https://github.com/node-fetch/node-fetch/pull/670
const req = get(url, async (res) => {
while (true) {
const value = res.read(1)
if (value) break
await sleep(5)
}
res.destroy() if (noData) {
resolve() const promise = fetch(url, { signal: controller.signal })
}) setTimeout(() => {
req.on('error', reject) controller.abort()
req.end() }, 100)
if (noData) { // Swallow the AbortError that happens if you abort before the
req.on('error', (e) => { // response connection is received.
// Swallow the "socket hang up" message that happens if you abort await promise.catch((err) => {
// before the a response connection is received. if (err.name !== 'AbortError') {
if ((e as any).code !== 'ECONNRESET') { throw err
throw e }
} })
}) return
}
setTimeout(() => { const res = await fetch(url, { signal: controller.signal })
req.abort() const reader = res.body!.getReader()
resolve() // Wait for the first byte of the response body, then abort the
}, 100) // connection abruptly so the server observes a client disconnect.
} await reader.read()
}) controller.abort()
} }
describe.each([ describe.each([
......
...@@ -285,10 +285,9 @@ describe.each([ ...@@ -285,10 +285,9 @@ describe.each([
serverReadyPattern: /- Local:/, serverReadyPattern: /- Local:/,
env: { env: {
USE_HTTPS: useHttps, USE_HTTPS: useHttps,
POLYFILL_FETCH: 'true',
NODE_ENV: sharedNodeEnv, NODE_ENV: sharedNodeEnv,
}, },
dependencies: { ...sharedDeps, 'node-fetch': '2.6.7' }, dependencies: sharedDeps,
skipDeployment: true, skipDeployment: true,
disableAutoSkewProtection: true, disableAutoSkewProtection: true,
}) })
......
// @ts-check // @ts-check
if (process.env.POLYFILL_FETCH) {
// @ts-expect-error
global.fetch = require('node-fetch').default
// @ts-expect-error
global.Request = require('node-fetch').Request
// @ts-expect-error
global.Headers = require('node-fetch').Headers
}
const { readFileSync } = require('fs') const { readFileSync } = require('fs')
/** @type {import('next').default} */ /** @type {import('next').default} */
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { createServer, Server } from 'http' import { createServer, Server } from 'http'
describe('node-fetch-keep-alive', () => { describe('fetch-keep-alive', () => {
let mockServer: Server let mockServer: Server
const { next, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
......
...@@ -20157,16 +20157,16 @@ ...@@ -20157,16 +20157,16 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/integration/node-fetch-keep-alive/test/index.test.ts": { "test/integration/fetch-keep-alive/test/index.test.ts": {
"passed": [ "passed": [
"node-fetch-keep-alive dev should send keep-alive for getServerSideProps", "fetch-keep-alive dev should send keep-alive for getServerSideProps",
"node-fetch-keep-alive dev should send keep-alive for getStaticPaths", "fetch-keep-alive dev should send keep-alive for getStaticPaths",
"node-fetch-keep-alive dev should send keep-alive for getStaticProps", "fetch-keep-alive dev should send keep-alive for getStaticProps",
"node-fetch-keep-alive dev should send keep-alive for json API", "fetch-keep-alive dev should send keep-alive for json API",
"node-fetch-keep-alive production mode should send keep-alive for getServerSideProps", "fetch-keep-alive production mode should send keep-alive for getServerSideProps",
"node-fetch-keep-alive production mode should send keep-alive for getStaticPaths", "fetch-keep-alive production mode should send keep-alive for getStaticPaths",
"node-fetch-keep-alive production mode should send keep-alive for getStaticProps", "fetch-keep-alive production mode should send keep-alive for getStaticProps",
"node-fetch-keep-alive production mode should send keep-alive for json API" "fetch-keep-alive production mode should send keep-alive for json API"
], ],
"failed": [], "failed": [],
"pending": [], "pending": [],
...@@ -22611,19 +22611,19 @@ ...@@ -22611,19 +22611,19 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/integration/node-fetch-keep-alive/test/index.test.ts": { "test/integration/fetch-keep-alive/test/index.test.ts": {
"passed": [ "passed": [
"node-fetch-keep-alive dev should send keep-alive for getServerSideProps", "fetch-keep-alive dev should send keep-alive for getServerSideProps",
"node-fetch-keep-alive dev should send keep-alive for getStaticPaths", "fetch-keep-alive dev should send keep-alive for getStaticPaths",
"node-fetch-keep-alive dev should send keep-alive for getStaticProps", "fetch-keep-alive dev should send keep-alive for getStaticProps",
"node-fetch-keep-alive dev should send keep-alive for json API" "fetch-keep-alive dev should send keep-alive for json API"
], ],
"failed": [], "failed": [],
"pending": [ "pending": [
"node-fetch-keep-alive production mode should send keep-alive for getServerSideProps", "fetch-keep-alive production mode should send keep-alive for getServerSideProps",
"node-fetch-keep-alive production mode should send keep-alive for getStaticPaths", "fetch-keep-alive production mode should send keep-alive for getStaticPaths",
"node-fetch-keep-alive production mode should send keep-alive for getStaticProps", "fetch-keep-alive production mode should send keep-alive for getStaticProps",
"node-fetch-keep-alive production mode should send keep-alive for json API" "fetch-keep-alive production mode should send keep-alive for json API"
], ],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
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