diff --git a/package.json b/package.json index 8d5bd1df..080e2130 100644 --- a/package.json +++ b/package.json @@ -27,23 +27,24 @@ }, "homepage": "https://github.com/fastify/fastify-reply-from#readme", "devDependencies": { - "fastify": "^1.11.2", - "got": "^9.2.1", + "fastify": "^1.13.2", + "got": "^9.4.0", "h2url": "^0.1.2", - "msgpack5": "^4.2.0", + "msgpack5": "^4.2.1", "nock": "^10.0.0", "pre-commit": "^1.2.2", "proxyquire": "^2.1.0", "simple-get": "^3.0.3", "snazzy": "^8.0.0", "standard": "^12.0.1", - "tap": "^12.0.1" + "tap": "^12.1.1" }, "dependencies": { "end-of-stream": "^1.4.1", - "fastify-plugin": "^1.2.0", - "semver": "^5.5.1", + "fastify-plugin": "^1.3.0", + "pump": "^3.0.0", + "semver": "^5.6.0", "tiny-lru": "^5.0.1", - "undici": "^0.3.2" + "undici": "^0.3.3" } } diff --git a/test/http2/full-post-http2.js b/test/http2/full-post-http2.js index 064beb8e..598f137c 100644 --- a/test/http2/full-post-http2.js +++ b/test/http2/full-post-http2.js @@ -1,33 +1,33 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const Fastify = require('fastify') const From = require('../..') const got = require('got') -const instance = Fastify() +test('http -> http2', async function (t) { + const instance = Fastify() -t.tearDown(instance.close.bind(instance)) + t.tearDown(instance.close.bind(instance)) -const target = Fastify({ - http2: true -}) + const target = Fastify({ + http2: true + }) -target.post('/', (request, reply) => { - t.pass('request proxied') - t.deepEqual(request.body, { something: 'else' }) - reply.code(200).header('x-my-header', 'hello!').send({ - hello: 'world' + target.post('/', (request, reply) => { + t.pass('request proxied') + t.deepEqual(request.body, { something: 'else' }) + reply.code(200).header('x-my-header', 'hello!').send({ + hello: 'world' + }) }) -}) -instance.post('/', (request, reply) => { - reply.from() -}) + instance.post('/', (request, reply) => { + reply.from() + }) -t.tearDown(target.close.bind(target)) + t.tearDown(target.close.bind(target)) -async function run () { await target.listen(0) instance.register(From, { @@ -37,20 +37,12 @@ async function run () { await instance.listen(0) - t.test('http -> http2', async (t) => { - try { - const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, { - body: { something: 'else' }, - json: true - }) - t.equal(statusCode, 200) - t.equal(headers['x-my-header'], 'hello!') - t.match(headers['content-type'], /application\/json/) - t.deepEqual(body, { hello: 'world' }) - } catch (err) { - t.error(err) - } + const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, { + body: { something: 'else' }, + json: true }) -} - -run() + t.equal(statusCode, 200) + t.equal(headers['x-my-header'], 'hello!') + t.match(headers['content-type'], /application\/json/) + t.deepEqual(body, { hello: 'world' }) +}) diff --git a/test/http2/http-http2.js b/test/http2/http-http2.js index dd9e9816..8f1171a3 100644 --- a/test/http2/http-http2.js +++ b/test/http2/http-http2.js @@ -1,32 +1,32 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const Fastify = require('fastify') const From = require('../..') const got = require('got') -const instance = Fastify() +test('http -> http2', async (t) => { + const instance = Fastify() -t.tearDown(instance.close.bind(instance)) + t.tearDown(instance.close.bind(instance)) -const target = Fastify({ - http2: true -}) + const target = Fastify({ + http2: true + }) -target.get('/', (request, reply) => { - t.pass('request proxied') - reply.code(404).header('x-my-header', 'hello!').send({ - hello: 'world' + target.get('/', (request, reply) => { + t.pass('request proxied') + reply.code(404).header('x-my-header', 'hello!').send({ + hello: 'world' + }) }) -}) -instance.get('/', (request, reply) => { - reply.from() -}) + instance.get('/', (request, reply) => { + reply.from() + }) -t.tearDown(target.close.bind(target)) + t.tearDown(target.close.bind(target)) -async function run () { await target.listen(0) instance.register(From, { @@ -36,20 +36,17 @@ async function run () { await instance.listen(0) - t.test('http -> http2', async (t) => { - try { - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - } catch (err) { - t.equal(err.response.statusCode, 404) - t.equal(err.response.headers['x-my-header'], 'hello!') - t.match(err.response.headers['content-type'], /application\/json/) - t.deepEqual(JSON.parse(err.response.body), { hello: 'world' }) - return - } - t.fail() - }) -} - -run() + try { + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + } catch (err) { + t.equal(err.response.statusCode, 404) + t.equal(err.response.headers['x-my-header'], 'hello!') + t.match(err.response.headers['content-type'], /application\/json/) + t.deepEqual(JSON.parse(err.response.body), { hello: 'world' }) + return + } + + t.fail() +}) diff --git a/test/http2/http2-invalid-target.js b/test/http2/http2-invalid-target.js index 7fbcd3ca..affba575 100644 --- a/test/http2/http2-invalid-target.js +++ b/test/http2/http2-invalid-target.js @@ -1,19 +1,18 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const Fastify = require('fastify') const From = require('../..') const got = require('got') -const instance = Fastify() +test('http -> http2', async (t) => { + const instance = Fastify() -t.tearDown(instance.close.bind(instance)) + t.tearDown(instance.close.bind(instance)) -instance.get('/', (request, reply) => { - reply.from() -}) - -async function run () { + instance.get('/', (request, reply) => { + reply.from() + }) instance.register(From, { base: `http://abc.xyz1`, http2: true @@ -21,23 +20,19 @@ async function run () { await instance.listen(0) - t.test('http -> http2', async (t) => { - try { - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - } catch (err) { - t.equal(err.response.statusCode, 503) - t.match(err.response.headers['content-type'], /application\/json/) - t.deepEqual(JSON.parse(err.response.body), { - statusCode: 503, - error: 'Service Unavailable', - message: 'Service Unavailable' - }) - return - } - t.fail() - }) -} - -run() + try { + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + } catch (err) { + t.equal(err.response.statusCode, 503) + t.match(err.response.headers['content-type'], /application\/json/) + t.deepEqual(JSON.parse(err.response.body), { + statusCode: 503, + error: 'Service Unavailable', + message: 'Service Unavailable' + }) + return + } + t.fail() +}) diff --git a/test/http2/http2-target-crash.js b/test/http2/http2-target-crash.js index 6bb271eb..0c932c95 100644 --- a/test/http2/http2-target-crash.js +++ b/test/http2/http2-target-crash.js @@ -1,32 +1,32 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const Fastify = require('fastify') const From = require('../..') const got = require('got') -const instance = Fastify() +test('http -> http2 crash', async (t) => { + const instance = Fastify() -t.tearDown(instance.close.bind(instance)) + t.tearDown(instance.close.bind(instance)) -const target = Fastify({ - http2: true -}) + const target = Fastify({ + http2: true + }) -target.get('/', (request, reply) => { - t.pass('request proxied') - reply.code(200).send({ - hello: 'world' + target.get('/', (request, reply) => { + t.pass('request proxied') + reply.code(200).send({ + hello: 'world' + }) }) -}) -instance.get('/', (request, reply) => { - reply.from() -}) + instance.get('/', (request, reply) => { + reply.from() + }) -t.tearDown(target.close.bind(target)) + t.tearDown(target.close.bind(target)) -async function run () { await target.listen(0) instance.register(From, { @@ -36,24 +36,20 @@ async function run () { await instance.listen(0) - t.test('http -> http2 crash', async (t) => { - try { - await target.close() - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - } catch (err) { - t.equal(err.response.statusCode, 503) - t.match(err.response.headers['content-type'], /application\/json/) - t.deepEqual(JSON.parse(err.response.body), { - statusCode: 503, - error: 'Service Unavailable', - message: 'Service Unavailable' - }) - return - } - t.fail() - }) -} - -run() + try { + await target.close() + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + } catch (err) { + t.equal(err.response.statusCode, 503) + t.match(err.response.headers['content-type'], /application\/json/) + t.deepEqual(JSON.parse(err.response.body), { + statusCode: 503, + error: 'Service Unavailable', + message: 'Service Unavailable' + }) + return + } + t.fail() +}) diff --git a/test/http2/http2-target-multi-crash.js b/test/http2/http2-target-multi-crash.js index 733f5c9e..f59e49c8 100644 --- a/test/http2/http2-target-multi-crash.js +++ b/test/http2/http2-target-multi-crash.js @@ -1,19 +1,19 @@ 'use strict' -const t = require('tap') +const { test } = require('tap') const Fastify = require('fastify') const From = require('../..') const got = require('got') -const instance = Fastify() +test('http -> http2 crash multiple times', async (t) => { + const instance = Fastify() -t.tearDown(instance.close.bind(instance)) + t.tearDown(instance.close.bind(instance)) -instance.get('/', (request, reply) => { - reply.from() -}) + instance.get('/', (request, reply) => { + reply.from() + }) -async function run () { instance.register(From, { base: `http://localhost:3128`, http2: true @@ -21,50 +21,45 @@ async function run () { await instance.listen(0) - t.test('http -> http2 crash multiple times', async (t) => { - try { - let target = setupTarget() - await target.listen(3128) - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - await target.close() - target = setupTarget() - await target.listen(3128) - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - await target.close() - await got(`http://localhost:${instance.server.address().port}`, { - rejectUnauthorized: false - }) - } catch (err) { - console.error(err) - t.equal(err.response.statusCode, 503) - t.match(err.response.headers['content-type'], /application\/json/) - t.deepEqual(JSON.parse(err.response.body), { - statusCode: 503, - error: 'Service Unavailable', - message: 'Service Unavailable' - }) - return - } - t.fail() - }) -} - -run() + try { + let target = setupTarget() + await target.listen(3128) + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + await target.close() + target = setupTarget() + await target.listen(3128) + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + await target.close() + await got(`http://localhost:${instance.server.address().port}`, { + rejectUnauthorized: false + }) + } catch (err) { + t.equal(err.response.statusCode, 503) + t.match(err.response.headers['content-type'], /application\/json/) + t.deepEqual(JSON.parse(err.response.body), { + statusCode: 503, + error: 'Service Unavailable', + message: 'Service Unavailable' + }) + return + } + t.fail() -function setupTarget () { - const target = Fastify({ - http2: true - }) + function setupTarget () { + const target = Fastify({ + http2: true + }) - target.get('/', (request, reply) => { - t.pass('request proxied') - reply.code(200).send({ - hello: 'world' + target.get('/', (request, reply) => { + t.pass('request proxied') + reply.code(200).send({ + hello: 'world' + }) }) - }) - return target -} + return target + } +})