diff --git a/lib/main.js b/lib/main.js index 748dbfcb..a139b1dc 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')) @@ -112,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`. @@ -126,16 +128,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..bd99c70b 100644 --- a/test/node-lambda.js +++ b/test/node-lambda.js @@ -188,10 +188,11 @@ 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: [123] .+ no: [123] .+ no: [123] .+Success:/, + stdoutRegExp: / no: 1 .+ no: 2 .+ no: 3 .+Success:/, exitCode: 0 }, done) })