Scripting
Node Libraries

Import Node Modules

This feature is available in the paid version.
  • Now you can import any external node module.
  • The node module will be automatically downloaded and installed from the npm registry.
  • e.g: var moment = await tc.loadModule("moment");
console.log("load node module");
 
var moment = await tc.loadModule("moment");
 
// use moment specific version
var moment = await tc.loadModule("moment", "2.30.0");
 
console.log(moment().format());
tc.setVar("date", moment().format());

Load Module from Path

This feature is available in the paid version.
  • Load a module from the specified folder path.
  • This functionality is useful for loading private modules or modules hosted on registries other than npm.
  • The module path can be relative to the project root or an absolute path.
console.log("load local module");
 
var moment = tc.loadFromPath("thunder-tests/packages/node_modules/moment");

Generate fake data

    // example code to load faker-js module
    var { faker } = await tc.loadModule("@faker-js/faker");
    tc.setVar("firstName", faker.person.firstName());
 
    // example code to load chance module
    var Chance = await tc.loadModule("chance");
    var chance = new Chance();
    tc.setVar("firstName", chance.name());
 
    // example code to load falso module
    var falso = await tc.loadModule("@ngneat/falso");
    var user = falso.randUser();
    tc.setVar("firstName", user.firstName);

NOTE

 // to save Env value to Active Environment
 tc.setVar("firstName", faker.person.firstName());
 
// If you do not want to save to the Environment file
// then use the request scope
 tc.setVar("firstName", faker.person.firstName(), "request");