class ShellSession

A shell session created by ShellTester#session.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ShellSession class.

Methods

capture(name, extra)

Captures the current terminal state into a file. It also prints the terminal state to the console.

It will be written to tmp/output/${name}.js and will begin with SESSION_DATA=, followed by the JSON-encoded ShellSessionCapturedData.

Extra properties may be added to the session by passing the extra argument.

Parameters
Name Type Description

name

string

The name of the capture file.

extra

Record<string, any>

Extra properties to add to the captured session data.

Returns

Promise<void>

Signature
capture(name: string, extra?: Record<string, any>): Promise<void>;

expect(str, timeoutMs)

Waits for the given string to be printed on the terminal. Gives up once timeoutMs has elapsed.

Parameters
Name Type Description

str

string

The text to wait for.

timeoutMs

number

The timeout in milliseconds.

Returns

Promise<void>

Signature
expect(str: string, timeoutMs?: number): Promise<void>;

resize(cols, rows)

Resizes the terminal.

Parameters
Name Type Description

cols

number

The number of columns.

rows

number

The number of rows.

Returns

Promise<void>

Signature
resize(cols?: number, rows?: number): Promise<void>;

retry(callback, timeoutMs)

Calls the given callback() function repeatedly until it no longer throws an error. Gives up once timeoutMs has elapsed.

Parameters
Name Type Description

callback

() => Promise<T>

The function to call.

timeoutMs

number

The timeout in milliseconds.

Returns

Promise<T>

Signature
retry<T>(callback: () => Promise<T>, timeoutMs?: number): Promise<T>;

send(data)

Send a string to the terminal.

Note that newline characters will *\*not\*\* be added automatically. To send a newline, use \r.

You can also send control characters such as \x03 (^C).

Parameters
Name Type Description

data

string

The string to send.

Returns

Promise<void>

Signature
send(data: string): Promise<void>;