Skip to content

Commit

Permalink
Add note on adding tests with node12
Browse files Browse the repository at this point in the history
Ref: openfaas/templates#196

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Feb 5, 2020
1 parent 41351bd commit d86942b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/cli/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,44 @@ module.exports = async (event, context) => {
}
```

##### Node.js 12 `node12` - adding unit tests

By default, an empty test step is written to package.json inside your function's handler folder, you can override this with your own command or test runner.

For example:

```json
{
"name": "function",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"scripts": {
"test": "mocha test/test.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^7.0.1"
}
}
```

Then create at least one test file such as: `function-name/test/test.js`:

```js
var chai = require("chai")
var expect = chai.expect;

describe('MyFunction', function() {
expect("foobar").to.have.lengthOf(3);
})
```

If the tests fail, this will also fail the build of your function and prevent it from passing. The logs will be made available via the logs of `faas-cli build/up`.

##### Node.js 12 `node12` - async/await with error

```js
Expand Down

0 comments on commit d86942b

Please sign in to comment.