diff --git a/.eslintrc.json b/.eslintrc.json index 9d9cf5e6f..d2e830b31 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "extends": "airbnb-base", "env": { - "node": true + "node": true, + "mocha": true }, "rules": { "strict": "off", diff --git a/README.md b/README.md index 351e4797e..1323a7f64 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder- | [Aws Fetch File And Store In S3](https://github.com/serverless/examples/tree/master/aws-node-fetch-file-and-store-in-s3)
Fetch an image from remote source (URL) and then upload the image to a S3 bucket. | nodeJS | | [Aws Function Compiled With Babel](https://github.com/serverless/examples/tree/master/aws-node-function-compiled-with-babel)
Demonstrating how to compile all your code with Babel | nodeJS | | [Aws Github Webhook Listener](https://github.com/serverless/examples/tree/master/aws-node-github-webhook-listener)
Extend your github repositories with this github webhook listener | nodeJS | +| [Aws Node Helloworld Tested](https://github.com/serverless/examples/tree/master/aws-node-helloworld-tested)
A simple example showing a http helloworld including a unit test. | nodeJS | | [Aws Iot Event](https://github.com/serverless/examples/tree/master/aws-node-iot-event)
Example on how to setup a AWS IoT Rule to send events to a Lambda function | nodeJS | | [Aws Node Rekognition Analysis S3 Image](https://github.com/serverless/examples/tree/master/aws-node-rekognition-analysis-s3-image)
Analyse an Image from an S3 Bucket with Amazon Rekognition | nodeJS | | [Aws Node Restapi Mongodb](https://github.com/serverless/examples/tree/master/aws-node-rest-api-mongodb)
Serverless REST API with MongoDB using Mongoose and Bluebird | nodeJS | diff --git a/aws-node-helloworld-tested/README.md b/aws-node-helloworld-tested/README.md new file mode 100644 index 000000000..cc1c62ca1 --- /dev/null +++ b/aws-node-helloworld-tested/README.md @@ -0,0 +1,44 @@ +# AWS Node Helloworld Tested + +A simple example showing a http helloworld including a unit test. + +## Install + + $ serverless install -u https://github.com/serverless/examples/tree/master/aws-node-helloworld-tested -n helloworld + +## Deploy + + $ cd helloworld + $ serverless deploy + Serverless: Packaging service... + Serverless: Creating Stack... + Serverless: Checking Stack create progress... + ..... + Serverless: Stack create finished... + Serverless: Uploading CloudFormation file to S3... + Serverless: Uploading artifacts... + Serverless: Uploading service .zip file to S3 (1.36 KB)... + Serverless: Updating Stack... + Serverless: Checking Stack update progress... + ............................... + Serverless: Stack update finished... + Service Information + service: hellworld + stage: dev + region: us-east-1 + api keys: + None + endpoints: + GET - https://.execute-api.us-east-1.amazonaws.com/dev/hello-world + functions: + helloWorld: hellworld-dev-helloWorld + +## Testout endpoint + + $ curl -sL $(sls info |grep -oEi 'http.*') | jq .message + "Go Serverless v1.0! Your function executed successfully!" + + +## Run local unit tests + + npm test \ No newline at end of file diff --git a/aws-node-helloworld-tested/handler.js b/aws-node-helloworld-tested/handler.js new file mode 100644 index 000000000..bbd62edf0 --- /dev/null +++ b/aws-node-helloworld-tested/handler.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports.helloworld = (event, context, callback) => { + const response = { + statusCode: 200, + body: JSON.stringify({ + message: 'Go Serverless v1.0! Your function executed successfully!', + input: event, + }), + }; + + callback(null, response); +}; diff --git a/aws-node-helloworld-tested/handler.test.js b/aws-node-helloworld-tested/handler.test.js new file mode 100644 index 000000000..a5abbafad --- /dev/null +++ b/aws-node-helloworld-tested/handler.test.js @@ -0,0 +1,23 @@ +const assert = require('assert'); + +const hander = require('./handler'); + +describe('Handler', () => { + describe('#helloworld', () => { + it('should return 200 status code', (done) => { + const callback = (err, result) => { + assert.equal('200', result.statusCode); + done(); + }; + hander.helloworld({}, {}, callback); + }); + + it('should return the hellworld message as json', (done) => { + const callback = (err, result) => { + assert.equal('Go Serverless v1.0! Your function executed successfully!', JSON.parse(result.body).message); + done(); + }; + hander.helloworld({}, {}, callback); + }); + }); +}); diff --git a/aws-node-helloworld-tested/package.json b/aws-node-helloworld-tested/package.json new file mode 100644 index 000000000..23a0451f4 --- /dev/null +++ b/aws-node-helloworld-tested/package.json @@ -0,0 +1,14 @@ +{ + "name": "aws-node-helloworld-tested", + "version": "0.0.1", + "description": "A simple example showing a http helloworld including a unit test.", + "main": "handler.js", + "scripts": { + "test": "mocha handler.test.js" + }, + "author": "Matthias Luebken", + "license": "MIT", + "devDependencies": { + "mocha": "^3.4.2" + } +} \ No newline at end of file diff --git a/aws-node-helloworld-tested/serverless.yml b/aws-node-helloworld-tested/serverless.yml new file mode 100644 index 000000000..f690aef69 --- /dev/null +++ b/aws-node-helloworld-tested/serverless.yml @@ -0,0 +1,23 @@ +# Welcome to serverless. Read the docs at https://serverless.com/framework/docs/ + +service: helloworld + +# The `provider` block defines where your service will be deployed +provider: + name: aws + runtime: nodejs6.10 + +# Exclude tests for deployment +package: + exclude: + - "*.test.js" + +# The `functions` block defines what code to deploy +functions: + helloWorld: + handler: handler.helloworld + # The `events` block defines how to trigger the handler.helloWorld code + events: + - http: + path: hello-world + method: get \ No newline at end of file diff --git a/package.json b/package.json index 1c56a555e..059ab9e07 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,11 @@ "markdown-magic": "^0.1.13" }, "devDependencies": { + "eslint": "^3.19.0", + "eslint-config-airbnb": "^15.0.1", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-jsx-a11y": "^5.0.3", + "eslint-plugin-react": "^7.0.1", "markdown-magic": "^0.1.14" } }