Debugging using REPL on one device

Suitest JavaScript API allows tests to be paused mid execution. The function uses node's Read-Eval-Print-Loop (REPL), learn more about REPL.


To enable REPL in Suitest, run the node process with the --experimental-repl-await flag.

Usage

Use REPL to debug and create your test more efficiently by using the repeater parameter for suitest.startREPL() function.

We recommend using REPL in the following way:

  1. Add a repeater function to the test you are debugging or any other module.

    module.exports =  { repeater: async function(){
        // empty repeater function
        }
    };
    
  2. Include suitest.startREPL() into your tests, which will pause the execution when it is reached and start REPL debugging. Make sure to include the optional repeater parameter.

    // test before REPL starts
    await suitest.startREPL({
        repeater:"repeater"
    });
    // rest of the test...
    
  3. Edit the body of the repeater function and save the file which will automatically execute the test lines within the repeater.

  4. Adjust the state of the application to match the expectation of the steps inside the repeater function.

  5. Continue editing until the function matches expected behavior.

The other option is to use REPL purely to experiment and then copy your commands into the test itself. This is incredibly useful when the user navigation is unclear.

Parameters

Parameters that can be used with suitest.startREPL():

Parameter Description Mandatory
cwd Current working directory unless other directory is specified. no, defaults to the directory of the file which calls suitest.startREPL
ignored Specifying files to ignore. no, defaults to empty
repeater Function that is run every time a file changes. no, defaults to empty
vars Object with key-value pairs to register globally in the REPL console. no, defaults to [{suitest}]
watch Specify files to watch, when files change Suitest will reacquire and run the repeater function. Expected to be relative to cwd. no, defaults to the directory of the file which calls suitest.startREPL

Commands

REPL supports the following commands when used in Suitest JavaScript API:

.break

While inputting a multi-line expression enter .break command (or press CTRL + C) to abort further input or processing of the expression.

.clear

Reset the REPL context to an empty object and clear any multi-line expression that is currently being inputted.

.editor

Enter editor mode (CTRL + D to finish, CTRL + C to cancel).

.exit

Close the I/O stream and exit REPL.

.help

Show this list of special commands.

.load

Load a file into the current REPL session. Example - .load ./tests/e2e.js

.save

Save the current REPL session to a file. Example - .save ./tests/e2e.js

Special keys

REPL supports the following special keys when used in Suitest JavaScript API:

CTRL + C

Press once for .break command. Press twice on a blank line for .exit command.

CRTL + D

Press for .exit command.

Tab

Press on blank line for global and local (scope) variables. Press on input to display autocompletion options.