fastify-compress
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -155,2 +155,5 @@ 'use strict' | ||
module.exports = fp(compressPlugin, '>=0.20.0') | ||
module.exports = fp(compressPlugin, { | ||
fastify: '>=0.39.1', | ||
name: 'fastify-compress' | ||
}) |
{ | ||
"name": "fastify-compress", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Fastify compression utils", | ||
"main": "index.js", | ||
"dependencies": { | ||
"fastify-plugin": "^0.1.1", | ||
"fastify-plugin": "^0.2.1", | ||
"mime-db": "^1.32.0", | ||
@@ -13,6 +13,6 @@ "pump": "^2.0.0", | ||
"devDependencies": { | ||
"fastify": "^0.35.3", | ||
"fastify": "^0.39.1", | ||
"iltorb": "^2.0.3", | ||
"standard": "^10.0.3", | ||
"tap": "^11.0.0" | ||
"tap": "^11.0.1" | ||
}, | ||
@@ -19,0 +19,0 @@ "scripts": { |
137
test.js
@@ -14,3 +14,3 @@ 'use strict' | ||
test('should send a deflated data', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -29,3 +29,4 @@ fastify.register(compressPlugin, { global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'deflate') | ||
@@ -39,3 +40,3 @@ const file = readFileSync('./package.json', 'utf8') | ||
test('should send a gzipped data', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -54,3 +55,4 @@ fastify.register(compressPlugin, { global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'gzip') | ||
@@ -64,3 +66,3 @@ const file = readFileSync('./package.json', 'utf8') | ||
test('should send a gzipped data for * header', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -79,3 +81,4 @@ fastify.register(compressPlugin, { global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'gzip') | ||
@@ -89,3 +92,3 @@ const file = readFileSync('./package.json', 'utf8') | ||
test('should send a brotli data', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -104,3 +107,4 @@ fastify.register(compressPlugin, { brotli, global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'br') | ||
@@ -114,3 +118,3 @@ const file = readFileSync('./package.json', 'utf8') | ||
test('should follow the encoding order', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -129,3 +133,4 @@ fastify.register(compressPlugin, { brotli, global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'br') | ||
@@ -139,3 +144,3 @@ const file = readFileSync('./package.json', 'utf8') | ||
test('Unsupported encoding', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -154,3 +159,4 @@ fastify.register(compressPlugin, { global: false }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -167,3 +173,3 @@ t.strictEqual(res.statusCode, 406) | ||
test('should not compress on missing header', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -179,3 +185,4 @@ fastify.register(compressPlugin, { global: false }) | ||
method: 'GET' | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -187,3 +194,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should close the stream', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -201,3 +208,4 @@ fastify.register(compressPlugin, { global: false }) | ||
method: 'GET' | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const file = readFileSync('./package.json', 'utf8') | ||
@@ -210,3 +218,3 @@ t.strictEqual(res.statusCode, 200) | ||
test('Should send 406 error on invalid accept encoding', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -226,3 +234,4 @@ fastify.register(compressPlugin, { global: true }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -239,3 +248,3 @@ t.strictEqual(res.statusCode, 406) | ||
test('No compression header', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -254,3 +263,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -263,3 +273,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should compress json data (gzip)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -279,3 +289,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.gunzipSync(res.rawPayload) | ||
@@ -287,3 +298,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('Should compress json data (deflate)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -303,3 +314,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.inflateSync(res.rawPayload) | ||
@@ -311,3 +323,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('Should compress json data (brotli)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -327,3 +339,4 @@ fastify.register(compressPlugin, { global: false, brotli, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = brotli.decompressSync(res.rawPayload) | ||
@@ -335,3 +348,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('Should compress string data (gzip)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -350,3 +363,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.gunzipSync(res.rawPayload) | ||
@@ -358,3 +372,3 @@ t.strictEqual(payload.toString('utf-8'), 'hello') | ||
test('Should compress string data (deflate)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -373,3 +387,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.inflateSync(res.rawPayload) | ||
@@ -381,3 +396,3 @@ t.strictEqual(payload.toString('utf-8'), 'hello') | ||
test('Should compress string data (brotli)', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -387,3 +402,3 @@ fastify.register(compressPlugin, { brotli, threshold: 0 }) | ||
fastify.get('/', (req, reply) => { | ||
reply.type('text/plain').compress('hello') | ||
reply.type('text/plain').send('hello') | ||
}) | ||
@@ -397,3 +412,4 @@ | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = brotli.decompressSync(res.rawPayload) | ||
@@ -405,3 +421,3 @@ t.strictEqual(payload.toString('utf-8'), 'hello') | ||
test('Missing payload', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -417,3 +433,4 @@ fastify.register(compressPlugin, { global: false }) | ||
method: 'GET' | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -430,3 +447,3 @@ t.strictEqual(res.statusCode, 500) | ||
test('Should compress json data (gzip) - global', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -446,3 +463,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.gunzipSync(res.rawPayload) | ||
@@ -454,3 +472,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('Should not compress on x-no-compression header', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -470,3 +488,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -479,3 +498,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should not try compress missing payload', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -494,3 +513,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -503,3 +523,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should not compress if content-type is a invalid type', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -519,3 +539,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -528,3 +549,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should not compress if content-type is a invalid type', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -543,3 +564,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -552,3 +574,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should not compress if payload length is smaller than threshold', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -567,3 +589,4 @@ fastify.register(compressPlugin, { threshold: 128 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.statusCode, 200) | ||
@@ -576,3 +599,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('Should compress json data (deflate) - global', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -592,3 +615,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = zlib.inflateSync(res.rawPayload) | ||
@@ -600,3 +624,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('Should compress json data (brotli) - global', t => { | ||
t.plan(1) | ||
t.plan(2) | ||
const fastify = Fastify() | ||
@@ -616,3 +640,4 @@ fastify.register(compressPlugin, { brotli, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = brotli.decompressSync(res.rawPayload) | ||
@@ -624,3 +649,3 @@ t.strictEqual(payload.toString('utf-8'), JSON.stringify(json)) | ||
test('identity header (compress)', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -639,3 +664,4 @@ fastify.register(compressPlugin, { global: false, threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -648,3 +674,3 @@ t.notOk(res.headers['content-encoding']) | ||
test('identity header (hook)', t => { | ||
t.plan(2) | ||
t.plan(3) | ||
const fastify = Fastify() | ||
@@ -663,3 +689,4 @@ fastify.register(compressPlugin, { threshold: 0 }) | ||
} | ||
}, res => { | ||
}, (err, res) => { | ||
t.error(err) | ||
const payload = JSON.parse(res.payload) | ||
@@ -666,0 +693,0 @@ t.notOk(res.headers['content-encoding']) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24386
690
1
+ Addedfastify-plugin@0.2.2(transitive)
- Removedfastify-plugin@0.1.1(transitive)
Updatedfastify-plugin@^0.2.1