Skip to main content
Run a command in the sandbox, for example to create test files, install software, or launch an app. exec() returns the commandโ€™s output.
  • On Linux sandboxes, use 'sh'. The command runs in Bash.
  • On Windows sandboxes, use 'pwsh'. The command runs in PowerShell.

Signature

Parameters

ExecOptions
required
Commands run in one shell session that stays open for the whole test. A cd or an environment variable you set carries over to the next exec() call.

Returns

Promise<string>. The commandโ€™s standard output, with leading and trailing whitespace trimmed. Output over 5 MB is cut off.

Errors

exec() throws when:
  • The command exits with a non-zero code. The message is Command failed with exit code <code>: <stderr>.
  • The command runs longer than timeout.
To allow a failure, catch the error:

Examples

Create a file the test needs

Read a value and check it

Install software on Windows

Launch an app on Windows

To open Chrome, VS Code, Electron apps, or installers, use provision instead. It launches the app and waits for it.

Positional form

Older tests pass the options as arguments:
It behaves the same. Use the options object in new tests.
language: 'js' is also accepted. It runs the code in Node on your own machine, not in the sandbox, and returns the value you assign to a result variable. Write the JavaScript directly in your test instead.

Complete example

tests/download.test.mjs