Skip to content

Commit 966b4fa

Browse files
domaslasauskasdaniel-cottone
authored andcommitted
Add async handler support for nodejs8.10 runtime (dherault#398)
1 parent a517c70 commit 966b4fa

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"David Bunker (https://github.com/dbunker)",
4545
"demetriusnunes (https://github.com/demetriusnunes)",
4646
"DJCrabhat (https://github.com/djcrabhat)",
47+
"Domas Lasauskas (https://github.com/domaslasauskas)",
4748
"Echo Nolan (https://github.com/enolan)",
4849
"Egor Kislitsyn (https://github.com/minibikini)",
4950
"Elliott Spira (https://github.com/em0ney)",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ class Offline {
779779
const x = handler(event, lambdaContext, lambdaContext.done);
780780

781781
// Promise support
782-
if (serviceRuntime === 'babel' && !this.requests[requestId].done) {
782+
if ((serviceRuntime === 'nodejs8.10' || serviceRuntime === 'babel') && !this.requests[requestId].done) {
783783
if (x && typeof x.then === 'function' && typeof x.catch === 'function') x.then(lambdaContext.succeed).catch(lambdaContext.fail);
784784
else if (x instanceof Error) lambdaContext.fail(x);
785785
}

test/integration/offline.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ describe('Offline', () => {
387387
else {
388388
cb('JSON body was mangled');
389389
}
390-
391390
}).toObject();
392391
done();
393392
});
@@ -421,4 +420,35 @@ describe('Offline', () => {
421420
});
422421
});
423422
});
423+
424+
context('aws runtime nodejs8.10', () => {
425+
const serverless = { service: { provider: {
426+
name: 'aws',
427+
stage: 'dev',
428+
region: 'us-east-1',
429+
runtime: 'nodejs8.10',
430+
} } };
431+
432+
it('should support handler returning Promise', done => {
433+
const offLine = new OffLineBuilder(new ServerlessBuilder(serverless))
434+
.addFunctionHTTP('index', {
435+
path: 'index',
436+
method: 'GET',
437+
}, (event, context) => Promise.resolve({
438+
statusCode: 200,
439+
body: JSON.stringify({ message: 'Hello World' }),
440+
})).toObject();
441+
442+
offLine.inject({
443+
method: 'GET',
444+
url: '/index',
445+
payload: { data: 'input' },
446+
}, res => {
447+
expect(res.headers).to.have.property('content-type', 'application/json');
448+
expect(res.statusCode).to.eq(200);
449+
expect(res.payload).to.eq('{"message":"Hello World"}');
450+
done();
451+
});
452+
});
453+
});
424454
});

0 commit comments

Comments
 (0)