From da1a1b26b8251b2219ae2b04edbb4170294ab630 Mon Sep 17 00:00:00 2001 From: Brett Andrews Date: Wed, 6 Oct 2021 19:54:56 +1000 Subject: [PATCH] test: fix tests (#470) --- __tests__/integration.js | 2 +- __tests__/unit.js | 6 ++---- jest-helpers/lambda-edge-event.js | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/__tests__/integration.js b/__tests__/integration.js index 3f2e495d..6a98fc8a 100644 --- a/__tests__/integration.js +++ b/__tests__/integration.js @@ -354,7 +354,7 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo eventSourceName, path: '/users/2', httpMethod: 'PUT', - body: global.btoa(JSON.stringify({ name })), + body: Buffer.from(JSON.stringify({ name }), 'binary').toString('base64'), isBase64Encoded: true, multiValueHeaders: { 'content-type': ['application/json'] diff --git a/__tests__/unit.js b/__tests__/unit.js index cb8675e7..827fde73 100644 --- a/__tests__/unit.js +++ b/__tests__/unit.js @@ -82,7 +82,7 @@ function getReqRes (multiValueHeaders = {}) { return requestResponse } -test('getRequestResponse: with headers', async (done) => { +test('getRequestResponse: with headers', async () => { const { request } = await getReqRes({ 'x-foo': ['foo'] }) expect(request).toBeInstanceOf(ServerlessRequest) expect(request.body).toBeInstanceOf(Buffer) @@ -94,10 +94,9 @@ test('getRequestResponse: with headers', async (done) => { 'x-foo': 'foo', 'content-length': Buffer.byteLength('Hello serverless!') }) - done() }) -test('getRequestResponse: without headers', async (done) => { +test('getRequestResponse: without headers', async () => { const requestResponse = await getReqRes() expect(requestResponse.request).toBeInstanceOf(ServerlessRequest) expect(requestResponse.request.body).toBeInstanceOf(Buffer) @@ -108,7 +107,6 @@ test('getRequestResponse: without headers', async (done) => { expect(requestResponse.request.headers).toEqual({ 'content-length': Buffer.byteLength('Hello serverless!') }) - done() }) describe('respondToEventSourceWithError', () => { diff --git a/jest-helpers/lambda-edge-event.js b/jest-helpers/lambda-edge-event.js index 86874841..b766676f 100644 --- a/jest-helpers/lambda-edge-event.js +++ b/jest-helpers/lambda-edge-event.js @@ -126,7 +126,7 @@ function makeLambdaEdgeEvent (values = {}) { if (!mergedEvent.request.method) mergedEvent.request.method = values.httpMethod if (!mergedEvent.request.body.data) { - mergedEvent.request.body.data = values.isBase64Encoded ? values.body : global.btoa(values.body) + mergedEvent.request.body.data = values.isBase64Encoded ? values.body : Buffer.from(values.body || '', 'binary').toString('base64') } // if (!mergedEvent.request.querysting) mergedEvent.request.querysting = values.httpMethod return {