Star

Created With

linkFunction Types

REST-EZ supports three ways of writing custom JS:

These types have access to different Context



linkInline Functions

REST-EZ utilizes the following special yaml types to enable the use of JS functions:



linkJS Synchronous Functions

Basic usage:

1link# basic function (synchronous)

2linkrun_type: inline

3linkinline:

4link function: !!js/function >

5link function () {

6link // ...

7link }


Use the arguments property to pass an array of arguments:

1link# basic function (synchronous)

2linkrun_type: inline

3linkinline:

4link arguments:

5link - Kiran Mandadi

6link function: !!js/function >

7link function (name) {

8link console.log(`Hello, ${name}.`);

9link }

10link



linkJS Async Functions

Basic usage:

1link# async function

2linkrun_type: inline

3linkinline:

4link function: !js/asyncFunction >

5link async function () {

6link // return new Promise((resolve, reject) => { ... });

7link // -- or --

8link // return await doSomething();

9link }


Use the arguments property to pass an array of arguments:

1link# async function

2linkrun_type: inline

3linkinline:

4link arguments:

5link - name: Matthew

6link dob: 1984-03-02

7link function: !js/asyncFunction >

8link async function (options) {

9link // return await doSomething(options.name, options.dob);

10link // -- or --

11link // return new Promise((resolve, reject) => { ... });

12link }



⚠️ NOTE: using require or import inside inline function is not yet supported. Use the JS modules approach below:



linkJS From External Files

You can run code from any external file:

some-suite.yml
1linkrun_type: module

2linkmodule:

3link module_path: 'path/to/a/file.js'

4link function_name: nameOfSomeFunction

path/to/a/file.js
1linkmodule.exports = {

2link someFunction: function () {

3link // do something

4link }

5link};


Use the arguments property to pass an array of arguments:

some-suite.yml
1linkrun_type: module

2linkmodule:

3link arguments:

4link - Argument one is a string.

5link - { name: 'Person', age: 72 }

6link - [ 'argument', 3, 'is', an', 'array' ]

7link module_path: 'path/to/a/file.js'

8link function_name: nameOfSomeFunction

path/to/a/file.js
1linkmodule.exports = {

2link someFunction: function (arg1, arg2) {

3link // do something

4link }

5link};



Function TypesInline FunctionsJS Synchronous FunctionsJS Async FunctionsJS From External Files

Home

Getting Startedchevron_right
Basicschevron_right
Requestchevron_right

Request Basics Headers Cookies Query Parameters Path Parameters

Payload Bodychevron_right

File Uploads Auto-Retry Additional Options

Response Validationchevron_right

Overview

Assertionschevron_right

Status Code Headers & Cookies

Bodychevron_right
Hooks & JSchevron_right

Overview

Function Typeschevron_right
Suite-Level Hookschevron_right
Spec-Level Hookschevron_right
Contextchevron_right
DRY & Reusing Specschevron_right
Command Line Interface (CLI)chevron_right