Azure Functions Node Harness
Easily invoke your Functions from test harnesses, etc.
🚧 This library is not supported by the Azure Functions team. 🚧 Please leave feedback and suggestions (through github issues).
Install
npm i azure-functions-node-harness
Usage
var func = ; var queueFunc = ; // Optional config: , {dirname: __dirname}); var invocation = queueFunc; invocation
FunctionsHarness(nameOrPath: string, [config: Object])
var func = ; var queueFunc = ; // Optional config: , {dirname: __dirname}); var httpFunc = 'queue'; //same thing - supports new and factory idioms
Parameters
- nameOrPath: string
- Selects the name or path you want to load. Uses node module loading logic (i.e.
queue
will look for./queue/index.js
, )
- Selects the name or path you want to load. Uses node module loading logic (i.e.
- config: Object
- Helps adjust settings. Mostly advanced features.
- Properties:
- dirname: string
- Which directory to look in for functions. Useful when tests are in a different directory than sample functions.
- moduleConfig: object
- instead of looking up function you can pass a function and it's function.json manually. mostly used internally.
- dirname: string
#.invoke(data: Object, [cb: function])
var func = ; var queueFunc = ; // Supports callbacksqueueFunc
Parameters
- data
- Key-value list of inputs. Use the name of your bindings for the keys
- cb
- Optionally give a callback for your Function. If you don't, the function will return a Promise.
#.invokeHttpTrigger(httpTriggerData,data: Object, [cb: function])
Invoke http trigger functions. It is possible to use the invoke
to get the same results but this simplifies the building of the request object.
var httpFunction = ; httpFunction;
If you use the sample.dat
file for testing locally with the Azure functions CLI you can use that file by calling invokeHttpTrigger
with no parameters.
var httpFunction = ; // sample.dat is used for request body. httpFunction;
Parameters
- httpTrigger
- object with reqBody. Simplifies building the entire http request object. Can override any parameters like
headers
.
- object with reqBody. Simplifies building the entire http request object. Can override any parameters like
- data
- Key-value list of other inputs. Use the name of your bindings for the keys
- cb
- Optionally give a callback for your Function. If you don't, the function will return a Promise.
Using with test frameworks (coming soon...)
The general idea is to set up the function once then call invoke in each test. If you use chai and chai-as-promised, you should be able to have some nifty assertions.
mocha
coming soon
chai
coming soon
chai-as-promised
coming soon
tape
Your test file would look like:
var test = ;var funcHarness = ;
Build
Clone this repository then run:
npm install
npm test