Skip to content

Commit 1f5024a

Browse files
committed
Updated test
1 parent 03c89e9 commit 1f5024a

File tree

1 file changed

+62
-18
lines changed

1 file changed

+62
-18
lines changed

test.js

+62-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const compressPlugin = require('./index')
1313
test('should send a deflated data', t => {
1414
t.plan(2)
1515
const fastify = Fastify()
16-
fastify.register(compressPlugin)
16+
fastify.register(compressPlugin, { global: false })
1717

1818
fastify.get('/', (req, reply) => {
1919
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -36,7 +36,7 @@ test('should send a deflated data', t => {
3636
test('should send a gzipped data', t => {
3737
t.plan(2)
3838
const fastify = Fastify()
39-
fastify.register(compressPlugin)
39+
fastify.register(compressPlugin, { global: false })
4040

4141
fastify.get('/', (req, reply) => {
4242
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -59,7 +59,7 @@ test('should send a gzipped data', t => {
5959
test('should send a brotli data', t => {
6060
t.plan(2)
6161
const fastify = Fastify()
62-
fastify.register(compressPlugin, { brotli })
62+
fastify.register(compressPlugin, { brotli, global: false })
6363

6464
fastify.get('/', (req, reply) => {
6565
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -82,7 +82,7 @@ test('should send a brotli data', t => {
8282
test('should follow the encoding order', t => {
8383
t.plan(2)
8484
const fastify = Fastify()
85-
fastify.register(compressPlugin, { brotli })
85+
fastify.register(compressPlugin, { brotli, global: false })
8686

8787
fastify.get('/', (req, reply) => {
8888
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -105,7 +105,7 @@ test('should follow the encoding order', t => {
105105
test('Unsupported encoding', t => {
106106
t.plan(2)
107107
const fastify = Fastify()
108-
fastify.register(compressPlugin)
108+
fastify.register(compressPlugin, { global: false })
109109

110110
fastify.get('/', (req, reply) => {
111111
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -131,7 +131,7 @@ test('Unsupported encoding', t => {
131131
test('Missing header', t => {
132132
t.plan(2)
133133
const fastify = Fastify()
134-
fastify.register(compressPlugin)
134+
fastify.register(compressPlugin, { global: false })
135135

136136
fastify.get('/', (req, reply) => {
137137
reply.type('text/plain').compress(createReadStream('./package.json'))
@@ -154,7 +154,7 @@ test('Missing header', t => {
154154
test('Should close the stream', t => {
155155
t.plan(3)
156156
const fastify = Fastify()
157-
fastify.register(compressPlugin)
157+
fastify.register(compressPlugin, { global: false })
158158

159159
fastify.get('/', (req, reply) => {
160160
const stream = createReadStream('./package.json')
@@ -179,7 +179,7 @@ test('Should close the stream', t => {
179179
test('No compression header', t => {
180180
t.plan(2)
181181
const fastify = Fastify()
182-
fastify.register(compressPlugin)
182+
fastify.register(compressPlugin, { global: false, threshold: 0 })
183183

184184
fastify.get('/', (req, reply) => {
185185
reply.compress({ hello: 'world' })
@@ -201,7 +201,7 @@ test('No compression header', t => {
201201
test('Should compress json data (gzip)', t => {
202202
t.plan(1)
203203
const fastify = Fastify()
204-
fastify.register(compressPlugin)
204+
fastify.register(compressPlugin, { global: false, threshold: 0 })
205205
const json = { hello: 'world' }
206206

207207
fastify.get('/', (req, reply) => {
@@ -223,7 +223,7 @@ test('Should compress json data (gzip)', t => {
223223
test('Should compress json data (deflate)', t => {
224224
t.plan(1)
225225
const fastify = Fastify()
226-
fastify.register(compressPlugin)
226+
fastify.register(compressPlugin, { global: false, threshold: 0 })
227227
const json = { hello: 'world' }
228228

229229
fastify.get('/', (req, reply) => {
@@ -245,7 +245,7 @@ test('Should compress json data (deflate)', t => {
245245
test('Should compress json data (brotli)', t => {
246246
t.plan(1)
247247
const fastify = Fastify()
248-
fastify.register(compressPlugin, { brotli })
248+
fastify.register(compressPlugin, { global: false, brotli, threshold: 0 })
249249
const json = { hello: 'world' }
250250

251251
fastify.get('/', (req, reply) => {
@@ -267,7 +267,7 @@ test('Should compress json data (brotli)', t => {
267267
test('Should compress string data (gzip)', t => {
268268
t.plan(1)
269269
const fastify = Fastify()
270-
fastify.register(compressPlugin)
270+
fastify.register(compressPlugin, { global: false, threshold: 0 })
271271

272272
fastify.get('/', (req, reply) => {
273273
reply.type('text/plain').compress('hello')
@@ -288,7 +288,7 @@ test('Should compress string data (gzip)', t => {
288288
test('Should compress string data (deflate)', t => {
289289
t.plan(1)
290290
const fastify = Fastify()
291-
fastify.register(compressPlugin)
291+
fastify.register(compressPlugin, { global: false, threshold: 0 })
292292

293293
fastify.get('/', (req, reply) => {
294294
reply.type('text/plain').compress('hello')
@@ -309,7 +309,7 @@ test('Should compress string data (deflate)', t => {
309309
test('Should compress string data (brotli)', t => {
310310
t.plan(1)
311311
const fastify = Fastify()
312-
fastify.register(compressPlugin, { brotli })
312+
fastify.register(compressPlugin, { brotli, threshold: 0 })
313313

314314
fastify.get('/', (req, reply) => {
315315
reply.type('text/plain').compress('hello')
@@ -330,7 +330,7 @@ test('Should compress string data (brotli)', t => {
330330
test('Missing payload', t => {
331331
t.plan(2)
332332
const fastify = Fastify()
333-
fastify.register(compressPlugin)
333+
fastify.register(compressPlugin, { global: false })
334334

335335
fastify.get('/', (req, reply) => {
336336
reply.compress()
@@ -353,7 +353,7 @@ test('Missing payload', t => {
353353
test('Should compress json data (gzip) - global', t => {
354354
t.plan(1)
355355
const fastify = Fastify()
356-
fastify.register(compressPlugin, { global: true })
356+
fastify.register(compressPlugin, { threshold: 0 })
357357
const json = { hello: 'world' }
358358

359359
fastify.get('/', (req, reply) => {
@@ -375,7 +375,7 @@ test('Should compress json data (gzip) - global', t => {
375375
test('Should compress json data (deflate) - global', t => {
376376
t.plan(1)
377377
const fastify = Fastify()
378-
fastify.register(compressPlugin, { global: true })
378+
fastify.register(compressPlugin, { threshold: 0 })
379379
const json = { hello: 'world' }
380380

381381
fastify.get('/', (req, reply) => {
@@ -397,7 +397,7 @@ test('Should compress json data (deflate) - global', t => {
397397
test('Should compress json data (brotli) - global', t => {
398398
t.plan(1)
399399
const fastify = Fastify()
400-
fastify.register(compressPlugin, { global: true, brotli })
400+
fastify.register(compressPlugin, { brotli, threshold: 0 })
401401
const json = { hello: 'world' }
402402

403403
fastify.get('/', (req, reply) => {
@@ -415,3 +415,47 @@ test('Should compress json data (brotli) - global', t => {
415415
t.strictEqual(payload.toString('utf-8'), JSON.stringify(json))
416416
})
417417
})
418+
419+
test('identity header (compress)', t => {
420+
t.plan(2)
421+
const fastify = Fastify()
422+
fastify.register(compressPlugin, { global: false, threshold: 0 })
423+
424+
fastify.get('/', (req, reply) => {
425+
reply.compress({ hello: 'world' })
426+
})
427+
428+
fastify.inject({
429+
url: '/',
430+
method: 'GET',
431+
headers: {
432+
'accept-encoding': 'identity'
433+
}
434+
}, res => {
435+
const payload = JSON.parse(res.payload)
436+
t.notOk(res.headers['content-encoding'])
437+
t.deepEqual({ hello: 'world' }, payload)
438+
})
439+
})
440+
441+
test('identity header (hook)', t => {
442+
t.plan(2)
443+
const fastify = Fastify()
444+
fastify.register(compressPlugin, { threshold: 0 })
445+
446+
fastify.get('/', (req, reply) => {
447+
reply.send({ hello: 'world' })
448+
})
449+
450+
fastify.inject({
451+
url: '/',
452+
method: 'GET',
453+
headers: {
454+
'accept-encoding': 'identity'
455+
}
456+
}, res => {
457+
const payload = JSON.parse(res.payload)
458+
t.notOk(res.headers['content-encoding'])
459+
t.deepEqual({ hello: 'world' }, payload)
460+
})
461+
})

0 commit comments

Comments
 (0)