serverless-test-plugin
Advanced tools
Comparing version 0.2.2 to 0.2.3
49
index.js
@@ -150,3 +150,3 @@ 'use strict'; | ||
let count = 0, succeeded = 0, failed = 0; | ||
return BbPromise.each(functions, function(functionData) { | ||
return BbPromise.each(functions, (functionData) => { | ||
let functionTestSuite = junitWriter.addTestsuite(functionData.name); | ||
@@ -170,3 +170,3 @@ count++; | ||
try { | ||
return BbPromise.try(() => { | ||
// We intercept all stdout from the function and dump | ||
@@ -187,3 +187,4 @@ // it into our test results instead. | ||
return functionData.run(stage, region, eventData) | ||
.then(function(result) { | ||
.timeout(functionData.timeout * 1000) | ||
.then((result) => { | ||
let duration = (Date.now() - startTime) / 1000; | ||
@@ -196,3 +197,9 @@ unhookIntercept(); // stop intercepting stdout | ||
if (!result || result.status !== "success") { | ||
let msg = result.error.toString(); | ||
let msg; | ||
if (result && result.error) { | ||
msg = result.error.toString(); | ||
} | ||
else { | ||
msg = "xxxx"; | ||
} | ||
testCase.addFailure(msg, "Failed"); | ||
@@ -204,10 +211,2 @@ | ||
} | ||
else if (duration > functionData.timeout) { | ||
let msg = `Timeout of ${functionData.timeout} seconds exceeded`; | ||
testCase.addFailure(msg, "Timeout"); | ||
SCli.log(chalk.bgMagenta.white(" TIMEOUT ") + " " + | ||
chalk.magenta(msg)); | ||
failed++; | ||
} | ||
else { | ||
@@ -219,5 +218,15 @@ // Done. | ||
}) | ||
.catch(function(err) { | ||
.catch(BbPromise.TimeoutError, () => { | ||
unhookIntercept(); // stop intercepting stdout | ||
let msg = `Timeout of ${functionData.timeout} seconds exceeded`; | ||
testCase.addFailure(msg, "Timeout"); | ||
SCli.log(chalk.bgMagenta.white(" TIMEOUT ") + " " + | ||
chalk.magenta(msg)); | ||
failed++; | ||
}) | ||
.catch((err) => { | ||
unhookIntercept(); // stop intercepting stdout | ||
let msg = err.toString(); | ||
@@ -231,4 +240,4 @@ testCase.addFailure(msg, "Failed"); | ||
}); | ||
} | ||
catch (err) { | ||
}) | ||
.catch((err) => { | ||
@@ -241,3 +250,3 @@ SCli.log("-----------------"); | ||
evt.data.result.response = err.message; | ||
} | ||
}); | ||
} | ||
@@ -249,3 +258,3 @@ else { | ||
}) | ||
.then(function() { | ||
.then(() => { | ||
@@ -270,6 +279,6 @@ SCli.log("-----------------"); | ||
}) | ||
.then(function() { | ||
.then(() => { | ||
process.exit(failed > 0 ? 1 : 0); // FIXME force exit | ||
}) | ||
.catch(function(err) { | ||
.catch((err) => { | ||
@@ -283,3 +292,3 @@ SCli.log("-----------------"); | ||
}) | ||
.finally(function() { | ||
.finally(() => { | ||
process.env.SERVERLESS_TEST = undefined; | ||
@@ -286,0 +295,0 @@ }); |
{ | ||
"name": "serverless-test-plugin", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=4.0" |
@@ -98,2 +98,5 @@ #Serverless Test Plugin | ||
### 0.2.3 | ||
* Properly time out a function call, e.g. in case the response callback is never invoked. | ||
### 0.2.2 | ||
@@ -100,0 +103,0 @@ * Exit with error code 1 in case one or more tests fail. This should help integrating the |
14150
245
128