Skip to content

Commit e277d9e

Browse files
authored
chore: test deprecation cleanup (fastify#5510)
1 parent dda5699 commit e277d9e

17 files changed

+21
-145
lines changed

lib/request.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const proxyAddr = require('proxy-addr')
4-
const semver = require('semver')
54
const {
65
FSTDEP005,
76
FSTDEP012,
@@ -239,10 +238,7 @@ Object.defineProperties(Request.prototype, {
239238
},
240239
connection: {
241240
get () {
242-
/* istanbul ignore next */
243-
if (semver.gte(process.versions.node, '13.0.0')) {
244-
FSTDEP005()
245-
}
241+
FSTDEP005()
246242
return this.raw.connection
247243
}
248244
},

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
"fast-json-body": "^1.1.0",
179179
"fastify-plugin": "^4.5.1",
180180
"fluent-json-schema": "^4.2.1",
181-
"form-data": "^4.0.0",
182181
"h2url": "^0.2.0",
183182
"http-errors": "^2.0.0",
184183
"joi": "^17.12.3",

test/404s.test.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const fp = require('fastify-plugin')
66
const sget = require('simple-get').concat
77
const errors = require('http-errors')
88
const split = require('split2')
9-
const FormData = require('form-data')
109
const Fastify = require('..')
1110
const { getServerUrl } = require('./helper')
1211

@@ -68,21 +67,18 @@ test('default 404', t => {
6867
})
6968
})
7069

71-
test('using post method and multipart/formdata', t => {
70+
test('using post method and multipart/formdata', async t => {
7271
t.plan(3)
73-
const form = FormData()
74-
form.append('test-field', 'just some field')
72+
const form = new FormData()
73+
form.set('test-field', 'just some field')
7574

76-
sget({
75+
const response = await fetch(getServerUrl(fastify) + '/notSupported', {
7776
method: 'POST',
78-
url: getServerUrl(fastify) + '/notSupported',
79-
body: form,
80-
json: false
81-
}, (err, response, body) => {
82-
t.error(err)
83-
t.equal(response.statusCode, 404)
84-
t.equal(response.headers['content-type'], 'application/json; charset=utf-8')
77+
body: form
8578
})
79+
t.equal(response.status, 404)
80+
t.equal(response.statusText, 'Not Found')
81+
t.equal(response.headers.get('content-type'), 'application/json; charset=utf-8')
8682
})
8783
})
8884
})

test/close.test.js

+1-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const http = require('node:http')
55
const { test } = require('tap')
66
const Fastify = require('..')
77
const { Client } = require('undici')
8-
const semver = require('semver')
98
const split = require('split2')
109
const { sleep } = require('./helper')
1110

@@ -204,46 +203,7 @@ test('Should return error while closing (callback) - injection', t => {
204203
})
205204
})
206205

207-
const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0')
208-
test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, t => {
209-
const fastify = Fastify({
210-
return503OnClosing: false,
211-
forceCloseConnections: false
212-
})
213-
214-
fastify.get('/', (req, reply) => {
215-
fastify.close()
216-
reply.send({ hello: 'world' })
217-
})
218-
219-
fastify.listen({ port: 0 }, err => {
220-
t.error(err)
221-
222-
const port = fastify.server.address().port
223-
const client = net.createConnection({ port }, () => {
224-
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
225-
226-
client.once('data', data => {
227-
t.match(data.toString(), /Connection:\s*keep-alive/i)
228-
t.match(data.toString(), /200 OK/i)
229-
230-
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
231-
232-
client.once('data', data => {
233-
t.match(data.toString(), /Connection:\s*close/i)
234-
t.match(data.toString(), /200 OK/i)
235-
236-
// Test that fastify closes the TCP connection
237-
client.once('close', () => {
238-
t.end()
239-
})
240-
})
241-
})
242-
})
243-
})
244-
})
245-
246-
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, t => {
206+
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false', t => {
247207
t.plan(4)
248208
const fastify = Fastify({
249209
return503OnClosing: false,

test/decorator.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const Fastify = require('..')

test/esm/index.test.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
'use strict'
22

3-
const t = require('tap')
4-
const semver = require('semver')
5-
6-
if (semver.lt(process.versions.node, '14.13.0')) {
7-
t.skip('Skip named exports because Node version < 14.13.0')
8-
} else {
9-
// Node v8 throw a `SyntaxError: Unexpected token import`
10-
// even if this branch is never touch in the code,
11-
// by using `eval` we can avoid this issue.
12-
// eslint-disable-next-line
13-
new Function('module', 'return import(module)')('./named-exports.mjs').catch((err) => {
3+
import('./named-exports.mjs')
4+
.catch(err => {
145
process.nextTick(() => {
156
throw err
167
})
178
})
18-
}

test/inject.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const test = t.test
55
const Stream = require('node:stream')
66
const util = require('node:util')
77
const Fastify = require('..')
8-
const FormData = require('form-data')
98
const { Readable } = require('node:stream')
109

1110
test('inject should exist', t => {
@@ -343,7 +342,7 @@ test('inject a multipart request using form-body', t => {
343342
})
344343

345344
const form = new FormData()
346-
form.append('my_field', 'my value')
345+
form.set('my_field', 'my value')
347346

348347
fastify.inject({
349348
method: 'POST',

test/maxRequestsPerSocket.test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
const net = require('node:net')
44
const { test } = require('tap')
5-
const semver = require('semver')
65
const Fastify = require('../fastify')
76

8-
const skip = semver.lt(process.versions.node, '16.10.0')
9-
10-
test('maxRequestsPerSocket on node version >= 16.10.0', { skip }, t => {
7+
test('maxRequestsPerSocket', t => {
118
t.plan(8)
129

1310
const fastify = Fastify({ maxRequestsPerSocket: 2 })
@@ -48,7 +45,7 @@ test('maxRequestsPerSocket on node version >= 16.10.0', { skip }, t => {
4845
})
4946
})
5047

51-
test('maxRequestsPerSocket zero should behave same as null', { skip }, t => {
48+
test('maxRequestsPerSocket zero should behave same as null', t => {
5249
t.plan(10)
5350

5451
const fastify = Fastify({ maxRequestsPerSocket: 0 })

test/plugin.1.test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const Fastify = require('../fastify')
@@ -117,8 +115,8 @@ test('fastify.register with fastify-plugin should provide access to external fas
117115

118116
instance.register((i, o, n) => n(), p => {
119117
t.notOk(p === instance || p === fastify)
120-
t.ok(instance.isPrototypeOf(p))
121-
t.ok(fastify.isPrototypeOf(p))
118+
t.ok(Object.prototype.isPrototypeOf.call(instance, p))
119+
t.ok(Object.prototype.isPrototypeOf.call(fastify, p))
122120
t.ok(p.global)
123121
})
124122

test/plugin.2.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const Fastify = require('../fastify')

test/plugin.3.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const Fastify = require('../fastify')

test/plugin.4.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const Fastify = require('../fastify')

test/register.test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint no-prototype-builtins: 0 */
4-
53
const t = require('tap')
64
const test = t.test
75
const sget = require('simple-get').concat
@@ -14,7 +12,7 @@ test('register', t => {
1412

1513
fastify.register(function (instance, opts, done) {
1614
t.not(instance, fastify)
17-
t.ok(fastify.isPrototypeOf(instance))
15+
t.ok(Object.prototype.isPrototypeOf.call(fastify, instance))
1816

1917
t.equal(typeof opts, 'object')
2018
t.equal(typeof done, 'function')
@@ -27,7 +25,7 @@ test('register', t => {
2725

2826
fastify.register(function (instance, opts, done) {
2927
t.not(instance, fastify)
30-
t.ok(fastify.isPrototypeOf(instance))
28+
t.ok(Object.prototype.isPrototypeOf.call(fastify, instance))
3129

3230
t.equal(typeof opts, 'object')
3331
t.equal(typeof done, 'function')

test/schema-special-usage.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ test('Custom schema object should not trigger FST_ERR_SCH_DUPLICATE', async t =>
704704
})
705705

706706
test('The default schema compilers should not be called when overwritten by the user', async t => {
707-
const Fastify = t.mock('../', {
707+
const Fastify = t.mockRequire('../', {
708708
'@fastify/ajv-compiler': () => {
709709
t.fail('The default validator compiler should not be called')
710710
},

test/server.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const t = require('tap')
44
const test = t.test
55
const Fastify = require('..')
66
const sget = require('simple-get').concat
7-
const semver = require('semver')
87
const undici = require('undici')
98

109
test('listen should accept null port', t => {
@@ -88,7 +87,7 @@ test('Test for hostname and port', t => {
8887
})
8988
})
9089

91-
test('abort signal', { skip: semver.lt(process.version, '16.0.0') }, t => {
90+
test('abort signal', t => {
9291
t.test('listen should not start server', t => {
9392
t.plan(2)
9493
function onClose (instance, done) {

test/stream.4.test.js

-42
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
const t = require('tap')
44
const test = t.test
55
const sget = require('simple-get').concat
6-
const fs = require('node:fs')
76
const errors = require('http-errors')
87
const JSONStream = require('JSONStream')
9-
const send = require('send')
108
const Readable = require('node:stream').Readable
119
const split = require('split2')
12-
const semver = require('semver')
1310
const Fastify = require('..')
1411
const { kDisableRequestLogging } = require('../lib/symbols.js')
15-
const { getServerUrl } = require('./helper')
1612

1713
test('Destroying streams prematurely should call abort method', t => {
1814
t.plan(7)
@@ -183,41 +179,3 @@ test('return a 404 if the stream emits a 404 error', t => {
183179
})
184180
})
185181
})
186-
187-
test('should support send module 200 and 404', { skip: semver.gte(process.versions.node, '17.0.0') }, t => {
188-
t.plan(8)
189-
const fastify = Fastify()
190-
191-
fastify.get('/', function (req, reply) {
192-
const stream = send(req.raw, __filename)
193-
reply.code(200).send(stream)
194-
})
195-
196-
fastify.get('/error', function (req, reply) {
197-
const stream = send(req.raw, 'non-existing-file')
198-
reply.code(200).send(stream)
199-
})
200-
201-
fastify.listen({ port: 0 }, err => {
202-
t.error(err)
203-
t.teardown(() => { fastify.close() })
204-
205-
const url = getServerUrl(fastify)
206-
207-
sget(url, function (err, response, data) {
208-
t.error(err)
209-
t.equal(response.headers['content-type'], 'application/javascript; charset=UTF-8')
210-
t.equal(response.statusCode, 200)
211-
212-
fs.readFile(__filename, (err, expected) => {
213-
t.error(err)
214-
t.equal(expected.toString(), data.toString())
215-
})
216-
})
217-
218-
sget(url + '/error', function (err, response) {
219-
t.error(err)
220-
t.equal(response.statusCode, 404)
221-
})
222-
})
223-
})

test/web-api.test.js

-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ const t = require('tap')
44
const test = t.test
55
const Fastify = require('../fastify')
66
const fs = require('node:fs')
7-
const semver = require('semver')
87
const { Readable } = require('node:stream')
98
const { fetch: undiciFetch } = require('undici')
109

11-
if (semver.lt(process.versions.node, '18.0.0')) {
12-
t.skip('Response or ReadableStream not available, skipping test')
13-
process.exit(0)
14-
}
15-
1610
test('should response with a ReadableStream', async (t) => {
1711
t.plan(2)
1812

0 commit comments

Comments
 (0)