From 43fa262a8c906aa9a88ebd7aa9ddbf8f25ccb50b Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 8 Jun 2017 21:38:44 +0900 Subject: [PATCH 1/3] Modify execution of multiple events to synchronous processing --- lib/main.js | 12 +++++------- test/node-lambda.js | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 748dbfcb..addfbfa3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -3,6 +3,7 @@ var path = require('path') var aws = require('aws-sdk') var exec = require('child_process').exec +var execSync = require('child_process').execSync var execFile = require('child_process').execFile var fs = require('fs-extra') var packageJson = require(path.join(__dirname, '..', 'package.json')) @@ -126,16 +127,13 @@ so you can easily test run multiple events. } fs.writeFileSync(tmpEventFile, JSON.stringify(event)) - exec(command(), { + const stdout = execSync(command(), { maxBuffer: maxBufferSize, env: process.env - }, (err, stdout, stderr) => { - console.log('>>> Event:', event, '<<<') - if (err) console.error(err) - console.log(stdout) - console.log(stderr) - fs.unlinkSync(tmpEventFile) }) + console.log('>>> Event:', event, '<<<') + console.log(stdout.toString()) + fs.unlinkSync(tmpEventFile) }) } diff --git a/test/node-lambda.js b/test/node-lambda.js index 2b90d9fb..de39050f 100644 --- a/test/node-lambda.js +++ b/test/node-lambda.js @@ -191,7 +191,7 @@ describe('bin/node-lambda', () => { it('`node-lambda run` exitCode is `0`', (done) => { _generateEventFile(eventObj) _testMain({ - stdoutRegExp: / no: [123] .+ no: [123] .+ no: [123] .+Success:/, + stdoutRegExp: / no: 1 .+ no: 2 .+ no: 3 .+Success:/, exitCode: 0 }, done) }) From b69d8f04211d203f70e0914a195abdafdc9f0091 Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 8 Jun 2017 21:41:34 +0900 Subject: [PATCH 2/3] Fix for Windows support --- lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/main.js b/lib/main.js index addfbfa3..a139b1dc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -113,6 +113,7 @@ so you can easily test run multiple events. if (index >= 0) return index return _argv.indexOf('--eventFile') })() + _argv[0] = 'node' // For Windows support // In order to reproduce the logic of callbackWaitsForEmptyEventLoop, // we are going to execute `node-lambda run`. From 5ffd84ad6d74ccdbd7f96b4e3885ba7b71086b76 Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 8 Jun 2017 21:50:30 +0900 Subject: [PATCH 3/3] Add timeout setting --- test/node-lambda.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/node-lambda.js b/test/node-lambda.js index de39050f..bd99c70b 100644 --- a/test/node-lambda.js +++ b/test/node-lambda.js @@ -188,7 +188,8 @@ describe('bin/node-lambda', () => { no: 3 }] - it('`node-lambda run` exitCode is `0`', (done) => { + it('`node-lambda run` exitCode is `0`', function (done) { + this.timeout(10000) // give it time to multiple executions _generateEventFile(eventObj) _testMain({ stdoutRegExp: / no: 1 .+ no: 2 .+ no: 3 .+Success:/,