Aktueller Stand
This commit is contained in:
32
backend/node_modules/fastify/test/stream.2.test.js
generated
vendored
32
backend/node_modules/fastify/test/stream.2.test.js
generated
vendored
@@ -1,13 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const proxyquire = require('proxyquire')
|
||||
const fs = require('node:fs')
|
||||
const resolve = require('node:path').resolve
|
||||
const zlib = require('node:zlib')
|
||||
const pipeline = require('node:stream').pipeline
|
||||
const Fastify = require('..')
|
||||
const { waitForCb } = require('./toolkit')
|
||||
|
||||
test('onSend hook stream', t => {
|
||||
t.plan(4)
|
||||
@@ -17,6 +17,8 @@ test('onSend hook stream', t => {
|
||||
reply.send({ hello: 'world' })
|
||||
})
|
||||
|
||||
const { stepIn, patience } = waitForCb({ steps: 2 })
|
||||
|
||||
fastify.addHook('onSend', (req, reply, payload, done) => {
|
||||
const gzStream = zlib.createGzip()
|
||||
|
||||
@@ -24,7 +26,10 @@ test('onSend hook stream', t => {
|
||||
pipeline(
|
||||
fs.createReadStream(resolve(__filename), 'utf8'),
|
||||
gzStream,
|
||||
t.error
|
||||
(err) => {
|
||||
t.assert.ifError(err)
|
||||
stepIn()
|
||||
}
|
||||
)
|
||||
done(null, gzStream)
|
||||
})
|
||||
@@ -33,16 +38,19 @@ test('onSend hook stream', t => {
|
||||
url: '/',
|
||||
method: 'GET'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.headers['content-encoding'], 'gzip')
|
||||
t.assert.ifError(err)
|
||||
t.assert.strictEqual(res.headers['content-encoding'], 'gzip')
|
||||
const file = fs.readFileSync(resolve(__filename), 'utf8')
|
||||
const payload = zlib.gunzipSync(res.rawPayload)
|
||||
t.equal(payload.toString('utf-8'), file)
|
||||
t.assert.strictEqual(payload.toString('utf-8'), file)
|
||||
fastify.close()
|
||||
stepIn()
|
||||
})
|
||||
|
||||
return patience
|
||||
})
|
||||
|
||||
test('onSend hook stream should work even if payload is not a proper stream', t => {
|
||||
test('onSend hook stream should work even if payload is not a proper stream', (t, testDone) => {
|
||||
t.plan(1)
|
||||
|
||||
const reply = proxyquire('../lib/reply', {
|
||||
@@ -59,8 +67,9 @@ test('onSend hook stream should work even if payload is not a proper stream', t
|
||||
fatal: () => { },
|
||||
error: () => { },
|
||||
warn: (message) => {
|
||||
t.equal(message, 'stream payload does not end properly')
|
||||
t.assert.strictEqual(message, 'stream payload does not end properly')
|
||||
fastify.close()
|
||||
testDone()
|
||||
},
|
||||
info: () => { },
|
||||
debug: () => { },
|
||||
@@ -68,7 +77,7 @@ test('onSend hook stream should work even if payload is not a proper stream', t
|
||||
child: () => { return spyLogger }
|
||||
}
|
||||
|
||||
const fastify = Fastify({ logger: spyLogger })
|
||||
const fastify = Fastify({ loggerInstance: spyLogger })
|
||||
fastify.get('/', function (req, reply) {
|
||||
reply.send({ hello: 'world' })
|
||||
})
|
||||
@@ -83,7 +92,7 @@ test('onSend hook stream should work even if payload is not a proper stream', t
|
||||
})
|
||||
})
|
||||
|
||||
test('onSend hook stream should work on payload with "close" ending function', t => {
|
||||
test('onSend hook stream should work on payload with "close" ending function', (t, testDone) => {
|
||||
t.plan(1)
|
||||
|
||||
const reply = proxyquire('../lib/reply', {
|
||||
@@ -106,7 +115,8 @@ test('onSend hook stream should work on payload with "close" ending function', t
|
||||
pipe: () => { },
|
||||
close: (cb) => {
|
||||
cb()
|
||||
t.pass()
|
||||
t.assert.ok('close callback called')
|
||||
testDone()
|
||||
}
|
||||
}
|
||||
done(null, fakeStream)
|
||||
|
||||
Reference in New Issue
Block a user