Page Contents

Home > @loopback/testlab > TestSandbox > (constructor)

TestSandbox.(constructor)

Will create a directory if it doesn’t already exist. If it exists, you still get an instance of the TestSandbox.

Signature:

constructor(rootPath: string, options?: TestSandboxOptions);

Parameters

Parameter Type Description
rootPath string Root path of the TestSandbox. If relative it will be resolved against the current directory.
options TestSandboxOptions (Optional) Options to control if/how the sandbox creates a subdirectory for the sandbox. If not provided, the sandbox will automatically creates a unique temporary subdirectory. This allows sandboxes with the same root path can be used in parallel during testing.

Example

// Create a sandbox as a unique temporary subdirectory under the rootPath
const sandbox = new TestSandbox(rootPath);
const sandbox = new TestSandbox(rootPath, {subdir: true});

// Create a sandbox in the root path directly
// This is same as the old behavior
const sandbox = new TestSandbox(rootPath, {subdir: false});

// Create a sandbox in the `test1` subdirectory of the root path
const sandbox = new TestSandbox(rootPath, {subdir: 'test1'});