{"id":22166137,"url":"https://github.com/alextanhongpin/serverless-test","last_synced_at":"2026-04-17T01:31:42.679Z","repository":{"id":79115253,"uuid":"91636507","full_name":"alextanhongpin/serverless-test","owner":"alextanhongpin","description":"Simple test for aws serverless","archived":false,"fork":false,"pushed_at":"2017-05-30T16:47:12.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T16:15:18.699Z","etag":null,"topics":["aws","serverless-testing","sls"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alextanhongpin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-18T01:43:19.000Z","updated_at":"2017-05-30T16:23:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"0ba6c375-d6ba-469e-b1ce-b3d7ccd2bbb3","html_url":"https://github.com/alextanhongpin/serverless-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alextanhongpin/serverless-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fserverless-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fserverless-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fserverless-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fserverless-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alextanhongpin","download_url":"https://codeload.github.com/alextanhongpin/serverless-test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alextanhongpin%2Fserverless-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31911444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"ssl_error","status_checked_at":"2026-04-16T18:21:47.142Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","serverless-testing","sls"],"created_at":"2024-12-02T05:18:12.093Z","updated_at":"2026-04-17T01:31:42.650Z","avatar_url":"https://github.com/alextanhongpin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverless testing with Mocha\n\nThis will briefly guide you on how to carry out testing with serverless lambda.\n\n### Installation\n\nThe following dependencies is required:\n\n```bash\n# Install the mocha test framework globally\n$ npm i -g mocha\n\n# Install the serverless-mocha-plugin as development dependencies\n$ npm i --save-dev serverless-mocha-plugin\n\n$ npm i -g serverless\n\n```\n\nYou might also need to include your `AWS_SECRET_ACCESS_KEY` and `AWS_ACCESS_KEY_ID` in your environment.\n\n### Add Test Plugin\n\nOnce you have the mocha and the plugin installed, then add the following line to your `serverless.yml`:\n\n```yml\n# Code not shown due to brevity\nfunctions:\n  hello:\n    handler: handler.hello\n\nplugins:\n  - serverless-mocha-plugin\n\n```\n\nRun `$ sls` to see a list of available commands. You should be able to see additional commands available for testing, namely:\n\n1. create test\n2. invoke test\n\n\n### Create Test\n\nLet's say you have a handler:\n\n```javascript\n\nmodule.exports.hello = (event, context, callback) =\u003e {\n\t// Code not shown due to brevity\n}\n```\n\nIn order to create a test for `hello` function, type the following in your terminal:\n\n```bash\n$ sls create test --function hello\n# or short\n$ sls create test -f hello\n```\n\nA test folder with the file `hello.js` will be created.\n\n### Run the test\n\nNow you can run the test with the command:\n```bash\n# Invokes the test\n$ sls invoke test\n```\n\n### Mock Dependencies\n\nIf you are using SQS, SNS, or DynamoDB, you can mock them using the library `aws-sdk-mock`:\n\n```js\nconst AWS = require('aws-sdk-mock')\n \nAWS.mock('DynamoDB', 'putItem', function (params, callback){\n  callback(null, \"successfully put item in database\")\n})\n \nAWS.mock('SNS', 'publish', 'test-message')\n \n/**\n    TESTS\n**/\n \nAWS.restore('SNS', 'publish')\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextanhongpin%2Fserverless-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falextanhongpin%2Fserverless-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falextanhongpin%2Fserverless-test/lists"}