Skip to content

Commit da1a1b2

Browse files
authored
test: fix tests (#470)
1 parent 35c686c commit da1a1b2

3 files changed

Lines changed: 4 additions & 6 deletions

File tree

__tests__/integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe.each(EACH_MATRIX)('%s:%s: integration tests', (eventSourceName, framewo
354354
eventSourceName,
355355
path: '/users/2',
356356
httpMethod: 'PUT',
357-
body: global.btoa(JSON.stringify({ name })),
357+
body: Buffer.from(JSON.stringify({ name }), 'binary').toString('base64'),
358358
isBase64Encoded: true,
359359
multiValueHeaders: {
360360
'content-type': ['application/json']

__tests__/unit.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function getReqRes (multiValueHeaders = {}) {
8282
return requestResponse
8383
}
8484

85-
test('getRequestResponse: with headers', async (done) => {
85+
test('getRequestResponse: with headers', async () => {
8686
const { request } = await getReqRes({ 'x-foo': ['foo'] })
8787
expect(request).toBeInstanceOf(ServerlessRequest)
8888
expect(request.body).toBeInstanceOf(Buffer)
@@ -94,10 +94,9 @@ test('getRequestResponse: with headers', async (done) => {
9494
'x-foo': 'foo',
9595
'content-length': Buffer.byteLength('Hello serverless!')
9696
})
97-
done()
9897
})
9998

100-
test('getRequestResponse: without headers', async (done) => {
99+
test('getRequestResponse: without headers', async () => {
101100
const requestResponse = await getReqRes()
102101
expect(requestResponse.request).toBeInstanceOf(ServerlessRequest)
103102
expect(requestResponse.request.body).toBeInstanceOf(Buffer)
@@ -108,7 +107,6 @@ test('getRequestResponse: without headers', async (done) => {
108107
expect(requestResponse.request.headers).toEqual({
109108
'content-length': Buffer.byteLength('Hello serverless!')
110109
})
111-
done()
112110
})
113111

114112
describe('respondToEventSourceWithError', () => {

jest-helpers/lambda-edge-event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function makeLambdaEdgeEvent (values = {}) {
126126
if (!mergedEvent.request.method) mergedEvent.request.method = values.httpMethod
127127

128128
if (!mergedEvent.request.body.data) {
129-
mergedEvent.request.body.data = values.isBase64Encoded ? values.body : global.btoa(values.body)
129+
mergedEvent.request.body.data = values.isBase64Encoded ? values.body : Buffer.from(values.body || '', 'binary').toString('base64')
130130
}
131131
// if (!mergedEvent.request.querysting) mergedEvent.request.querysting = values.httpMethod
132132
return {

0 commit comments

Comments
 (0)