Skip to Content
ScriptingNode 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

  • 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

  • You can use Node libraries like faker-js  or lightweight libraries like chance  and falso  to generate random data.
  • Use Pre Run tab -> Scripting tab to generate fake data using code.
  • Example custom script:
// 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");
Last updated on

Morty Proxy This is a proxified and sanitized view of the page, visit original site.