Skip to content

Commit 2fa8b6a

Browse files
committed
update zlib tests to account for platform differences
1 parent 23343af commit 2fa8b6a

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [10.x, 12.x, 14.x, 15.x]
20-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19+
node-version: [14.x]
2120

2221
steps:
2322
- uses: actions/checkout@v2

__tests__/errorHandling.unit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ describe('Error Handling Tests:', function() {
396396
console.log = log => { try { _log = JSON.parse(log) } catch(e) { _log = log } }
397397
let result = await new Promise(r => api9.run(_event,{},(e,res) => { r(res) }))
398398
console.log = logger
399-
// console.log(result);
400-
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 500, body: 'H4sIAAAAAAAAE6tWSi0qyi9SslIKycgsVgCiRIWS1OIShZKMovzyPAWIrI5SfHJpcUl+rpJVSVFpKpCblFicamYC4dYCAL2BVyJFAAAA', isBase64Encoded: true })
399+
let body = gzipSync(`{"error":"This is a test thrown error","_custom":true,"_base64":true}`).toString('base64')
400+
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 500, body, isBase64Encoded: true })
401401
})
402402
})
403403
}) // end ERROR HANDLING tests

__tests__/responses.unit.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22

3-
43
const sinon = require('sinon') // Require Sinon.js library
54
const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
65
const S3 = require('../lib/s3-service') // Init S3 Service
7-
const { gzipSync } = require('zlib')
6+
const { gzipSync, brotliCompressSync, deflateSync } = require('zlib')
87

98
// Init API instance
109
const api = require('../index')({ version: 'v1.0' })
@@ -129,7 +128,7 @@ api4.get('/testGZIP', function(req,res) {
129128
res.json({ object: true })
130129
})
131130

132-
api5.get('/testGZIP', function(req,res) {
131+
api5.get('/testCompression', function(req,res) {
133132
res.json({ object: true })
134133
})
135134

@@ -285,13 +284,32 @@ describe('Response Tests:', function() {
285284
it('Custom serializer (GZIP)', async function() {
286285
let _event = Object.assign({},event,{ path: '/testGZIP'})
287286
let result = await new Promise(r => api4.run(_event,{},(e,res) => { r(res) }))
288-
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body: 'H4sIAAAAAAAAE6tWyk/KSk0uUbIqKSpN1VGKTy4tLsnPhXOTEotTzUwg3FoAan86iy0AAAA=', isBase64Encoded: true })
287+
288+
let body = gzipSync(`{"object":true,"_custom":true,"_base64":true}`).toString('base64')
289+
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
289290
}) // end it
290291

291292
it('Compression (GZIP)', async function() {
292-
let _event = Object.assign({},event,{ path: '/testGZIP'})
293+
let _event = Object.assign({},event,{ path: '/testCompression'})
294+
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
295+
let body = gzipSync(`{"object":true}`).toString('base64')
296+
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
297+
}) // end it
298+
299+
it('Compression (Brotli)', async function() {
300+
let _event = Object.assign({},event,{ path: '/testCompression'})
301+
_event.multiValueHeaders['Accept-Encoding'] = ['br','deflate','gzip']
302+
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
303+
let body = brotliCompressSync(`{"object":true}`).toString('base64')
304+
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['br'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
305+
}) // end it
306+
307+
it('Compression (Deflate)', async function() {
308+
let _event = Object.assign({},event,{ path: '/testCompression'})
309+
_event.multiValueHeaders['Accept-Encoding'] = ['deflate']
293310
let result = await new Promise(r => api5.run(_event,{},(e,res) => { r(res) }))
294-
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['gzip'], 'content-type': ['application/json'] }, statusCode: 200, body: 'H4sIAAAAAAAAE6tWyk/KSk0uUbIqKSpNrQUAAQd5Ug8AAAA=', isBase64Encoded: true })
311+
let body = deflateSync(`{"object":true}`).toString('base64')
312+
expect(result).toEqual({ multiValueHeaders: { 'content-encoding': ['deflate'], 'content-type': ['application/json'] }, statusCode: 200, body, isBase64Encoded: true })
295313
}) // end it
296314

297315
afterEach(function() {

0 commit comments

Comments
 (0)