Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add node 17 #3456

Merged
merged 6 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
node-version: [10, 12, 14, 16]
node-version: [10, 12, 14, 16, 17]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
cd test/bundler/webpack && npm install
- name: Test bundle
run: |
cd test/bundler/webpack && npm run test
cd test/bundler/webpack && npm run test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"snazzy": "^9.0.0",
"split2": "^4.1.0",
"standard": "^16.0.1",
"tap": "^15.0.5",
"tap": "^15.1.1",
"tap-mocha-reporter": "^5.0.1",
"then-sleep": "^1.0.1",
"tsd": "^0.18.0",
Expand Down
13 changes: 11 additions & 2 deletions test/custom-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ function plainTextParser (request, callback) {
}
}

function getUrl (app) {
const { address, port } = app.server.address()
if (address === '::1') {
return `http://[${address}]:${port}`
} else {
return `http://${address}:${port}`
}
}

process.removeAllListeners('warning')

test('contentTypeParser method should exist', t => {
Expand Down Expand Up @@ -61,7 +70,7 @@ test('contentTypeParser should add a custom parser', t => {

sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: '{"hello":"world"}',
headers: {
'Content-Type': 'application/jsoff'
Expand All @@ -78,7 +87,7 @@ test('contentTypeParser should add a custom parser', t => {

sget({
method: 'OPTIONS',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: '{"hello":"world"}',
headers: {
'Content-Type': 'application/jsoff'
Expand Down
15 changes: 11 additions & 4 deletions test/handler-context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const http = require('http')
const test = require('tap').test
const fastify = require('../')

function getUrl (app) {
const { address, port } = app.server.address()
if (address === '::1') {
return `http://[${address}]:${port}`
} else {
return `http://${address}:${port}`
}
}

test('handlers receive correct `this` context', (t) => {
t.plan(4)

Expand All @@ -29,8 +38,7 @@ test('handlers receive correct `this` context', (t) => {
t.ok(instance.foo)
t.equal(instance.foo, 'foo')

const address = `http://127.0.0.1:${instance.server.address().port}/`
http.get(address, () => {}).on('error', t.threw)
http.get(getUrl(instance), () => {}).on('error', t.threw)
})
})

Expand All @@ -50,7 +58,6 @@ test('handlers have access to the internal context', (t) => {
instance.listen(0, (err) => {
instance.server.unref()
if (err) t.threw(err)
const address = `http://127.0.0.1:${instance.server.address().port}/`
http.get(address, () => {}).on('error', t.threw)
http.get(getUrl(instance), () => {}).on('error', t.threw)
})
})
19 changes: 14 additions & 5 deletions test/http2/closing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const { once } = require('events')
const { buildCertificate } = require('../build-certificate')
t.before(buildCertificate)

function getUrl (app) {
const { address, port } = app.server.address()
if (address === '::1') {
return `http://[${address}]:${port}`
} else {
return `http://${address}:${port}`
}
}

t.test('http/2 request while fastify closing', t => {
let fastify
try {
Expand All @@ -30,7 +39,7 @@ t.test('http/2 request while fastify closing', t => {

// Skipped because there is likely a bug on Node 8.
t.test('return 200', { skip: semver.lt(process.versions.node, '10.15.0') }, t => {
const url = `http://127.0.0.1:${fastify.server.address().port}`
const url = getUrl(fastify)
const session = http2.connect(url, function () {
this.request({
':method': 'GET',
Expand Down Expand Up @@ -78,7 +87,7 @@ t.test('http/2 request while fastify closing - return503OnClosing: false', t =>

// Skipped because there is likely a bug on Node 8.
t.test('return 200', { skip: semver.lt(process.versions.node, '10.15.0') }, t => {
const url = `http://127.0.0.1:${fastify.server.address().port}`
const url = getUrl(fastify)
const session = http2.connect(url, function () {
this.request({
':method': 'GET',
Expand Down Expand Up @@ -115,7 +124,7 @@ t.test('http/2 closes successfully with async await', { skip: semver.lt(process.

await fastify.listen(0)

const url = `http://127.0.0.1:${fastify.server.address().port}`
const url = getUrl(fastify)
const session = await connect(url)
// An error might or might not happen, as it's OS dependent.
session.on('error', () => {})
Expand All @@ -135,7 +144,7 @@ t.test('https/2 closes successfully with async await', { skip: semver.lt(process

await fastify.listen(0)

const url = `http://127.0.0.1:${fastify.server.address().port}`
const url = getUrl(fastify)
const session = await connect(url)
// An error might or might not happen, as it's OS dependent.
session.on('error', () => {})
Expand All @@ -159,7 +168,7 @@ t.test('http/2 server side session emits a timeout event', { skip: semver.lt(pro

await fastify.listen(0)

const url = `http://127.0.0.1:${fastify.server.address().port}`
const url = getUrl(fastify)
const session = await connect(url)
const req = session.request({
':method': 'GET',
Expand Down
58 changes: 36 additions & 22 deletions test/listen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
const os = require('os')
const path = require('path')
const fs = require('fs')
const test = require('tap').test
const { test, before } = require('tap')
const Fastify = require('..')
const dns = require('dns').promises

let localhost
let localhostForURL

before(async function () {
const lookup = await dns.lookup('localhost')
localhost = lookup.address
if (lookup.family === 6) {
localhostForURL = `[${lookup.address}]`
} else {
localhostForURL = localhost
}
})

test('listen accepts a callback', t => {
t.plan(2)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen((err) => {
t.equal(fastify.server.address().address, '127.0.0.1')
t.equal(fastify.server.address().address, localhost)
t.error(err)
})
})
Expand All @@ -21,7 +35,7 @@ test('listen accepts a port and a callback', t => {
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, (err) => {
t.equal(fastify.server.address().address, '127.0.0.1')
t.equal(fastify.server.address().address, localhost)
t.error(err)
})
})
Expand All @@ -31,7 +45,7 @@ test('listen accepts a port and a callback with (err, address)', t => {
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, (err, address) => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
t.error(err)
})
})
Expand All @@ -40,7 +54,7 @@ test('listen accepts a port, address, and callback', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, '127.0.0.1', (err) => {
fastify.listen(0, localhost, (err) => {
t.error(err)
})
})
Expand Down Expand Up @@ -78,8 +92,8 @@ test('listen accepts a port, address and a callback with (err, address)', t => {
t.plan(2)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, '127.0.0.1', (err, address) => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
fastify.listen(0, localhost, (err, address) => {
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
t.error(err)
})
})
Expand All @@ -88,7 +102,7 @@ test('listen accepts a port, address, backlog and callback', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, '127.0.0.1', 511, (err) => {
fastify.listen(0, localhost, 511, (err) => {
t.error(err)
})
})
Expand All @@ -97,8 +111,8 @@ test('listen accepts a port, address, backlog and callback with (err, address)',
t.plan(2)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, '127.0.0.1', 511, (err, address) => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
fastify.listen(0, localhost, 511, (err, address) => {
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
t.error(err)
})
})
Expand All @@ -111,7 +125,7 @@ test('listen after Promise.resolve()', t => {
.then(() => {
f.listen(0, (err, address) => {
f.server.unref()
t.equal(address, 'http://127.0.0.1:' + f.server.address().port)
t.equal(address, `http://${localhostForURL}:${f.server.address().port}`)
t.error(err)
})
})
Expand Down Expand Up @@ -153,7 +167,7 @@ test('double listen errors callback with (err, address)', t => {
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, (err1, address1) => {
t.equal(address1, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address1, `http://${localhostForURL}:${fastify.server.address().port}`)
t.error(err1)
fastify.listen(fastify.server.address().port, (err2, address2) => {
t.equal(address2, null)
Expand All @@ -167,7 +181,7 @@ test('listen twice on the same port', t => {
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, (err1, address1) => {
t.equal(address1, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address1, `http://${localhostForURL}:${fastify.server.address().port}`)
t.error(err1)
const s2 = Fastify()
t.teardown(s2.close.bind(s2))
Expand All @@ -184,7 +198,7 @@ test('listen twice on the same port callback with (err, address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(0, (err1, address1) => {
const _port = fastify.server.address().port
t.equal(address1, 'http://127.0.0.1:' + _port)
t.equal(address1, `http://${localhostForURL}:${_port}`)
t.error(err1)
const s2 = Fastify()
t.teardown(s2.close.bind(s2))
Expand Down Expand Up @@ -221,7 +235,7 @@ test('listen without callback (port zero)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(0)
.then(() => {
t.equal(fastify.server.address().address, '127.0.0.1')
t.equal(fastify.server.address().address, localhost)
})
})

Expand All @@ -231,7 +245,7 @@ test('listen without callback (port not given)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen()
.then(() => {
t.equal(fastify.server.address().address, '127.0.0.1')
t.equal(fastify.server.address().address, localhost)
})
})

Expand All @@ -241,7 +255,7 @@ test('listen null without callback with (address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(null)
.then(address => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
})
})

Expand All @@ -251,7 +265,7 @@ test('listen without port without callback with (address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen()
.then(address => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
})
})

Expand All @@ -261,7 +275,7 @@ test('listen with undefined without callback with (address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(undefined)
.then(address => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
})
})

Expand All @@ -271,7 +285,7 @@ test('listen without callback with (address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(0)
.then(address => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
})
})

Expand All @@ -295,7 +309,7 @@ test('double listen without callback with (address)', t => {
t.teardown(fastify.close.bind(fastify))
fastify.listen(0)
.then(address => {
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
fastify.listen(0)
.catch(err => {
t.ok(err)
Expand Down Expand Up @@ -329,7 +343,7 @@ test('listen twice on the same port without callback rejects with (address)', t
.then(address => {
const s2 = Fastify()
t.teardown(s2.close.bind(s2))
t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port)
t.equal(address, `http://${localhostForURL}:${fastify.server.address().port}`)
s2.listen(fastify.server.address().port)
.catch(err => {
t.ok(err)
Expand Down
10 changes: 2 additions & 8 deletions test/request-error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ test('default clientError handler destroys sockets in writable state', t => {

const fastify = Fastify({
bodyLimit: 1,
keepAliveTimeout: 100,
logger: {
level: 'trace'
}
keepAliveTimeout: 100
})

fastify.server.emit('clientError', new Error(), {
Expand All @@ -181,10 +178,7 @@ test('default clientError handler destroys http sockets in non-writable state',

const fastify = Fastify({
bodyLimit: 1,
keepAliveTimeout: 100,
logger: {
level: 'trace'
}
keepAliveTimeout: 100
})

fastify.server.emit('clientError', new Error(), {
Expand Down
Loading