LogoLogo
HomeSign UpGithub
  • Home
  • Release Notes
  • Getting Started
    • Create your first Test
    • Create Run Settings
    • Analyze the results
      • Job Summary
      • Logs
      • State
      • Payload
    • Look deeper with Metrics
  • Concepts
    • Workspaces
      • Role Based Access Control (RBAC)
      • Invitation Management
      • GitHub Integration
      • Deletion of Workspaces
      • System Status
    • Understanding Tests
      • Stages Management
        • Init Stage
        • Running Stage(s)
        • Finished State
      • Generating Messages
        • Scripting Environment
        • State Object
      • Response Handler
      • Preview Tests
      • Exporting/Importing Tests
        • Import OpenAPI JSON/YAML
      • Locking/Unlocking a test
    • Stateful Simulation
      • Mapping the IoT device lifecycle
    • Protocol Settings
      • MQTT
      • HTTP
      • Using other protocols
    • Run Settings
      • Network Simulation
      • Execution Strategies
      • Client Distribution
    • Scenarios
    • Glob Storage
    • Metrics
    • Mailbox
    • Licensing and Limits
    • Deployment Models
  • Additional Helpers
    • External Libraries
    • Inbuilt Libraries
    • IoTIFY Helper Functions
      • Job Functions
      • Messaging Functions
      • Glob Functions
      • Metrics Functions
      • Mailbox Functions
      • Data Generation Functions
  • platform integrations
    • AWS IoT Connector
  • Guides
    • Smart City
    • Smart Home
    • Load Testing Kafka
  • IoT Testing
    • Overview
      • Feed offline sensor data from Google Sheets to your IoT platform
    • Functional Testing
      • Basic functional test
      • Geofencing Validation
    • Performance Testing
      • MQTT end to end latency Measurement
    • Security Testing
    • Load Testing
    • Test Automation & CI/CD integration
  • API
    • Simulation API
    • Glob APIs
    • Metrics API
  • Glossary
  • Create Account
  • TEMP
    • Getting Started
      • Beginner
      • Developer
      • Tester
    • Walkthrough
    • Protocol Settings
      • CoAP
      • Raw (TCP/UDP/TLS/DTLS)
      • LWM2M
      • NONE
    • Under the hood
    • Google Sheets API
    • Azure IoT
    • Losant IoT
      • Losant Connector
      • Parking Space Management
      • Waste Management
      • Connected Truck
      • Delivery Van
    • Google Cloud IoT Core
    • IBM Cloud
      • Simple Messaging
      • IBM Bluemix: Monitoring Energy Consumption
    • Dweet.io
    • JMeter and why it fails at IoT
Powered by GitBook
On this page
  • Chance.js
  • Day.js
  • Underscore.js/Lodash
  • DeAsync.js
  • JSON Web Tokens
  • Geolib
  • Geohash
  • Native built-in objects

Was this helpful?

  1. Additional Helpers

Inbuilt Libraries

A summary of external helper libraries available in the tests

PreviousExternal LibrariesNextIoTIFY Helper Functions

Last updated 2 years ago

Was this helpful?

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

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:

state['street'] = chance.address();
state['city'] = chance.city();
state['zip'] = chance.zip(); 

return JSON.stringify(state);

And voila, you have a completely random fake street address.

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)

{
    if (state['start'] === undefined) {
        state['start'] = dayjs();
    }

    state['elapsed'] = dayjs(state['start']).fromNow();

    return JSON.stringify(state);
}

Underscore.js/Lodash

{

    var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) {
        return num % 2 == 0;
    });

    return JSON.stringify(evens);
}

DeAsync.js

{
    var ret;
    setTimeout(function() {
        ret = "hello";
    }, 3000);
    while (ret === undefined) {
        deasync.sleep(100);
    }
}

JSON Web Tokens

{
  var token = jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' });
}

Geolib

{
   var distance = geolib.getDistance( 
   location('Delhi'), 
   {latitude: 51.519475, longitude: 7.46694444});
}

Geohash

{
    let hash = geohash.encode(37.8324, 112.5584);
    var latlon = geohash.decode('ww8p1r4t8');
}

Native built-in objects

is another popular library that is a must-have for serious javascript programmers. Here is an example of filtering even values in an array:

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 are gaining popularity as an authorization mechanism. IOTIFY tests support creating JWTs by integrating the NPM library.

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:

allows the conversion of Latitude and Longitude pairs to a geohash and vice versa.

There are several built-in modules available in the function body. is one of them which is quite useful for arithmetic operations.

Chance.js
Day.js
Underscore.js
DeAsync.js
jsonwebtoken
Geolib
Geohash
Math