Skip to content

Commit e8955cc

Browse files
authored
[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.
1 parent 6ba7104 commit e8955cc

9 files changed

Lines changed: 46 additions & 73 deletions

File tree

‎test/e2e/api-support/api-support.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('API routes', () => {
1212
dependencies: {
1313
'http-proxy': 'latest',
1414
cors: 'latest',
15-
'node-fetch': '2.6.7',
1615
},
1716
skipDeployment: true,
1817
disableAutoSkewProtection: true,
@@ -602,7 +601,6 @@ describe('API routes output export error', () => {
602601
dependencies: {
603602
'http-proxy': 'latest',
604603
cors: 'latest',
605-
'node-fetch': '2.6.7',
606604
},
607605
skipStart: true,
608606
skipDeployment: true,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import fetch from 'node-fetch'
1+
import { Readable } from 'stream'
22

33
export default async (req, res) => {
44
const dataRes = await fetch(
55
`http://localhost:${req.query.port}/api/query?hello=from-pipe`
66
)
77

88
res.status(dataRes.status)
9-
dataRes.body.pipe(res)
9+
Readable.fromWeb(dataRes.body).pipe(res)
1010
}

‎test/e2e/app-dir/app-routes/app-custom-routes.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ function streamingBody(stream: Readable) {
2121
describe('app-custom-routes', () => {
2222
const { next, isNextDeploy, isNextDev, isNextStart } = nextTestSetup({
2323
files: __dirname,
24-
dependencies: {
25-
// pin with repo's version of node-fetch
26-
'@types/node-fetch': '2.6.1',
27-
},
2824
})
2925

3026
describe('works with api prefix correctly', () => {

‎test/e2e/cancel-request/stream-cancel.test.ts‎

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { sleep } from './sleep'
3-
import { get } from 'http'
42

53
describe('streaming responses cancel inner stream after disconnect', () => {
64
const { next } = nextTestSetup({
75
files: __dirname,
86
})
97

10-
function prime(url: string, noData?: boolean) {
11-
return new Promise<void>((resolve, reject) => {
12-
url = new URL(url, next.url).href
8+
async function prime(url: string, noData?: boolean) {
9+
url = new URL(url, next.url).href
1310

14-
// There's a bug in node-fetch v2 where aborting the fetch will never abort
15-
// the connection, because the body is a transformed stream that doesn't
16-
// close the connection stream.
17-
// https://github.com/node-fetch/node-fetch/pull/670
18-
const req = get(url, async (res) => {
19-
while (true) {
20-
const value = res.read(1)
21-
if (value) break
22-
await sleep(5)
23-
}
11+
const controller = new AbortController()
2412

25-
res.destroy()
26-
resolve()
27-
})
28-
req.on('error', reject)
29-
req.end()
13+
if (noData) {
14+
const promise = fetch(url, { signal: controller.signal })
15+
setTimeout(() => {
16+
controller.abort()
17+
}, 100)
3018

31-
if (noData) {
32-
req.on('error', (e) => {
33-
// Swallow the "socket hang up" message that happens if you abort
34-
// before the a response connection is received.
35-
if ((e as any).code !== 'ECONNRESET') {
36-
throw e
37-
}
38-
})
19+
// Swallow the AbortError that happens if you abort before the
20+
// response connection is received.
21+
await promise.catch((err) => {
22+
if (err.name !== 'AbortError') {
23+
throw err
24+
}
25+
})
26+
return
27+
}
3928

40-
setTimeout(() => {
41-
req.abort()
42-
resolve()
43-
}, 100)
44-
}
45-
})
29+
const res = await fetch(url, { signal: controller.signal })
30+
const reader = res.body!.getReader()
31+
// Wait for the first byte of the response body, then abort the
32+
// connection abruptly so the server observes a client disconnect.
33+
await reader.read()
34+
controller.abort()
4635
}
4736

4837
describe.each([

‎test/e2e/custom-server/custom-server.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,9 @@ describe.each([
285285
serverReadyPattern: /- Local:/,
286286
env: {
287287
USE_HTTPS: useHttps,
288-
POLYFILL_FETCH: 'true',
289288
NODE_ENV: sharedNodeEnv,
290289
},
291-
dependencies: { ...sharedDeps, 'node-fetch': '2.6.7' },
290+
dependencies: sharedDeps,
292291
skipDeployment: true,
293292
disableAutoSkewProtection: true,
294293
})

‎test/e2e/custom-server/server.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
// @ts-check
22

3-
if (process.env.POLYFILL_FETCH) {
4-
// @ts-expect-error
5-
global.fetch = require('node-fetch').default
6-
// @ts-expect-error
7-
global.Request = require('node-fetch').Request
8-
// @ts-expect-error
9-
global.Headers = require('node-fetch').Headers
10-
}
11-
123
const { readFileSync } = require('fs')
134

145
/** @type {import('next').default} */

‎test/e2e/node-fetch-keep-alive/node-fetch-keep-alive.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { nextTestSetup } from 'e2e-utils'
22
import { createServer, Server } from 'http'
33

4-
describe('node-fetch-keep-alive', () => {
4+
describe('fetch-keep-alive', () => {
55
let mockServer: Server
66

77
const { next, skipped } = nextTestSetup({

‎test/rspack-build-tests-manifest.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20157,16 +20157,16 @@
2015720157
"flakey": [],
2015820158
"runtimeError": false
2015920159
},
20160-
"test/integration/node-fetch-keep-alive/test/index.test.ts": {
20161-
"passed": [
20162-
"node-fetch-keep-alive dev should send keep-alive for getServerSideProps",
20163-
"node-fetch-keep-alive dev should send keep-alive for getStaticPaths",
20164-
"node-fetch-keep-alive dev should send keep-alive for getStaticProps",
20165-
"node-fetch-keep-alive dev should send keep-alive for json API",
20166-
"node-fetch-keep-alive production mode should send keep-alive for getServerSideProps",
20167-
"node-fetch-keep-alive production mode should send keep-alive for getStaticPaths",
20168-
"node-fetch-keep-alive production mode should send keep-alive for getStaticProps",
20169-
"node-fetch-keep-alive production mode should send keep-alive for json API"
20160+
"test/integration/fetch-keep-alive/test/index.test.ts": {
20161+
"passed": [
20162+
"fetch-keep-alive dev should send keep-alive for getServerSideProps",
20163+
"fetch-keep-alive dev should send keep-alive for getStaticPaths",
20164+
"fetch-keep-alive dev should send keep-alive for getStaticProps",
20165+
"fetch-keep-alive dev should send keep-alive for json API",
20166+
"fetch-keep-alive production mode should send keep-alive for getServerSideProps",
20167+
"fetch-keep-alive production mode should send keep-alive for getStaticPaths",
20168+
"fetch-keep-alive production mode should send keep-alive for getStaticProps",
20169+
"fetch-keep-alive production mode should send keep-alive for json API"
2017020170
],
2017120171
"failed": [],
2017220172
"pending": [],

‎test/rspack-dev-tests-manifest.json‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22611,19 +22611,19 @@
2261122611
"flakey": [],
2261222612
"runtimeError": false
2261322613
},
22614-
"test/integration/node-fetch-keep-alive/test/index.test.ts": {
22614+
"test/integration/fetch-keep-alive/test/index.test.ts": {
2261522615
"passed": [
22616-
"node-fetch-keep-alive dev should send keep-alive for getServerSideProps",
22617-
"node-fetch-keep-alive dev should send keep-alive for getStaticPaths",
22618-
"node-fetch-keep-alive dev should send keep-alive for getStaticProps",
22619-
"node-fetch-keep-alive dev should send keep-alive for json API"
22616+
"fetch-keep-alive dev should send keep-alive for getServerSideProps",
22617+
"fetch-keep-alive dev should send keep-alive for getStaticPaths",
22618+
"fetch-keep-alive dev should send keep-alive for getStaticProps",
22619+
"fetch-keep-alive dev should send keep-alive for json API"
2262022620
],
2262122621
"failed": [],
2262222622
"pending": [
22623-
"node-fetch-keep-alive production mode should send keep-alive for getServerSideProps",
22624-
"node-fetch-keep-alive production mode should send keep-alive for getStaticPaths",
22625-
"node-fetch-keep-alive production mode should send keep-alive for getStaticProps",
22626-
"node-fetch-keep-alive production mode should send keep-alive for json API"
22623+
"fetch-keep-alive production mode should send keep-alive for getServerSideProps",
22624+
"fetch-keep-alive production mode should send keep-alive for getStaticPaths",
22625+
"fetch-keep-alive production mode should send keep-alive for getStaticProps",
22626+
"fetch-keep-alive production mode should send keep-alive for json API"
2262722627
],
2262822628
"flakey": [],
2262922629
"runtimeError": false

0 commit comments

Comments
 (0)