Script Node
The Script Node allows you to execute custom JavaScript code as a step in your test flow. It’s ideal for complex data transformations, custom business logic, and dynamic decision-making that goes beyond what’s possible with other visual nodes.
Script Pattern
To use the Script Node, you must define an async function named runScript. Inside this function, you can access and modify the test context.
async function runScript() {
// Your script logic here
// Access context variables
const existingData = $context.someValue;
// Modify context directly
$context.newProperty = "some value";
$context.existingProperty = "updated value";
// Work with complex data
$context.user = {
name: "John Doe",
email: "john@example.com",
};
// Array operations
const currentItems = $context.items || [];
$context.items = [...currentItems, { id: Date.now(), name: "new item" }];
}Key Points
- Function Name: The function must be named
runScript. - Async: The function must be declared as
async. - Context Access: Use the global
$contextobject to read and write variables in the test context. Any modifications to$contextare automatically saved after the script runs. - Available Libraries: Lodash (
_), Faker, Zod (z), Ky, and Luxon are available by default.
📚 See complete library documentation →
Available Globals
$context: The test context (read/write)._: Lodash library for utilities.faker: Generate mock data.z: Zod schema validation (v4.x).ky: Modern HTTP client.luxon: Date/time manipulation.console: For logging to the console.fetch: For making HTTP requests.JSON,Math,Date: JavaScript built-ins.