Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 10 lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ Lambda.prototype._runHandler = function (handler, event, program, context) {
var callback = function (err, result) {
if (err) {
console.log('Error: ' + err);
process.exit(-1);
process.exit(255);
}
console.log('Success:');
if (result) {
console.log(JSON.stringify(result));
if (!result) {
process.exit(0);
}
process.exit(0);
console.log(JSON.stringify(result));
};

context.getRemainingTimeInMillis = function () {
Expand All @@ -85,7 +85,7 @@ Lambda.prototype._runHandler = function (handler, event, program, context) {

if (['nodejs4.3', 'nodejs6.10'].indexOf(program.runtime) == -1) {
console.error("Runtime [" + program.runtime + "] is not supported.");
process.exit(-2);
process.exit(254);
}
handler(event, context, callback);
};
Expand Down
2 changes: 1 addition & 1 deletion 2 test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function _timeout(params) {
}
}

describe('node-lambda', function () {
describe('lib/main', function () {
if (process.platform == 'win32') {
// It seems that it takes time for file operation in Windows.
// So set `timeout(60000)` for the whole test.
Expand Down
80 changes: 80 additions & 0 deletions 80 test/node-lambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

const assert = require('chai').assert;
const path = require('path');
const fs = require('fs-extra');
const spawn = require('child_process').spawn;
const execSync = require('child_process').execSync;
const nodeLambdaPath = path.join(__dirname, '..', 'bin', 'node-lambda');

// The reason for specifying the node command in this test is to support Windows.
describe('bin/node-lambda', () => {
describe('node-lambda run', () => {
const _generateHandlerFile = (callbackString) => {
fs.writeFileSync(
'__test.js',
fs.readFileSync('index.js').toString()
.replace(/callback\(null\);/, callbackString)
);
};

before(() => execSync(`node ${nodeLambdaPath} setup`));

after(() => {
[
'.env',
'context.json',
'event.json',
'deploy.env',
'event_sources.json',
'__test.js'
].forEach((file) => fs.unlinkSync(file));
});

it('`node-lambda run` exitCode is `0` (callback(null))', (done) => {
const run = spawn('node', [nodeLambdaPath, 'run']);
var stdoutString = '';
run.stdout.on('data', (data) => {
stdoutString += data.toString().replace(/\r|\n/g, '');
});

run.on('exit', (code) => {
assert.match(stdoutString, /Success:$/);
assert.equal(code, 0);
done();
});
});

it('`node-lambda run` exitCode is `0` (callback(null, "text"))', (done) => {
_generateHandlerFile('callback(null, "text");');

const run = spawn('node', [nodeLambdaPath, 'run', '--handler', '__test.handler']);
var stdoutString = '';
run.stdout.on('data', (data) => {
stdoutString += data.toString().replace(/\r|\n/g, '');
});

run.on('exit', (code) => {
assert.match(stdoutString, /Success:"text"$/);
assert.equal(code, 0);
done();
});
});

it('`node-lambda run` exitCode is `255` (callback(new Error("e")))', (done) => {
_generateHandlerFile('callback(new Error("e"));');

const run = spawn('node', [nodeLambdaPath, 'run', '--handler', '__test.handler']);
var stdoutString = '';
run.stdout.on('data', (data) => {
stdoutString += data.toString().replace(/\r|\n/g, '');
});

run.on('exit', (code) => {
assert.match(stdoutString, /Error: Error: e$/);
assert.equal(code, 255);
done();
});
});
});
});
2 changes: 1 addition & 1 deletion 2 test/schedule_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const mockResponse = {

var schedule = null;

describe('schedule_events', () => {
describe('lib/schedule_events', () => {
before(() => {
aws.mock('CloudWatchEvents', 'putRule', (params, callback) => {
callback(null, mockResponse.putRule);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.