Inbuilt Libraries
A summary of external helper libraries available in the tests
There are many additional external helper functions available in the scope of the test body. Let’s have a short look at them.
Chance.js
Chance.js is a random content generation library which is quite useful to generate data. For example, if you wanted to generate a random street address, you can use chance.js:
And voila, you have a completely random fake street address.
Day.js
Day.js is another useful library, especially to manipulate time. In the example given below, we will calculate the elapsed time since the simulation started (iteration 0)
Underscore.js/Lodash
Underscore.js is another popular library that is a must-have for serious javascript programmers. Here is an example of filtering even values in an array:
DeAsync.js
DeAsync.js can be used to create synchronous behaviour out of async or callback-based functions. Though async functions should be used as much as possible, in some cases, DeAsync could make life easier. For Example, in the code snippet given below, we are waiting for the callback function to finish while calling setTimeout() async function.
JSON Web Tokens
JSON web tokens are gaining popularity as an authorization mechanism. IOTIFY tests support creating JWTs by integrating the jsonwebtoken NPM library.
Geolib
Geolib is a useful library for geospatial operations or for manipulating locations. For example, to get the distance from Delhi to a specified coordinate, use the following code snippet:
Geohash
Geohash allows the conversion of Latitude and Longitude pairs to a geohash and vice versa.
Native built-in objects
There are several built-in modules available in the function body. Math is one of them which is quite useful for arithmetic operations.
Last updated