1. Constructors
  2. Constructor
  3. Accessors
  4. absolutePath
  5. name
  6. parent
  7. path
  8. Methods
  9. access()
  10. at()
  11. contains()
  12. contents()
  13. copyFromExternal()
  14. copyTo()
  15. create()
  16. delete()
  17. diff()
  18. dir()
  19. exists()
  20. file()
  21. hash()
  22. move()
  23. read()
  24. rename()
  25. scaffold()
  26. tree()
  27. treeString()

Class: Dir

Defined in: packages/fs-testkit/src/dir.js:17

Constructors

Constructor

new Dir(options): Dir;

Defined in: packages/fs-testkit/src/dir.js:28

Parameters

ParameterTypeDescription
options{ name: string; parent: Dir | null; sandbox: Sandbox; }-
options.namestring-
options.parentDir | null-
options.sandboxSandbox-

Returns

Dir

Accessors

absolutePath

Get Signature

get absolutePath(): string;

Defined in: packages/fs-testkit/src/dir.js:62

The directory’s absolute path

Returns

string


name

Get Signature

get name(): string;

Defined in: packages/fs-testkit/src/dir.js:38

The directory’s name

Returns

string


parent

Get Signature

get parent(): Dir | null;

Defined in: packages/fs-testkit/src/dir.js:46

The directory’s parent

Returns

Dir | null


path

Get Signature

get path(): string;

Defined in: packages/fs-testkit/src/dir.js:54

The directory’s relative path. Returns an empty string ("") if path is the sandbox root.

Returns

string

Methods

access()

access(mode?): Promise<Dir>;

Defined in: packages/fs-testkit/src/dir.js:250

Check the access of the directory on the filesystem, returned promise rejects if not accessible, otherwise resolves

Parameters

ParameterTypeDescription
mode?number-

Returns

Promise<Dir>


at()

at(path, type?): File | Dir;

Defined in: packages/fs-testkit/src/dir.js:110

Create a Dir or File at a given path relative to the current directory. The returned instance is inferred based on whether the relative path has an extension, this can be forced by specifying the type argument.

Parameters

ParameterTypeDescription
pathstring-
type?"Dir" | "File"-

Returns

File | Dir


contains()

contains(fileOrDir): boolean;

Defined in: packages/fs-testkit/src/dir.js:136

Returns true if the File or Dir argument is contained by the directory, otherwise false. This method does not check if anything exists on the filesystem. Use the exists method on File or Dir instances to check if they exist on the filesystem.

Parameters

ParameterTypeDescription
fileOrDirFile | Dir-

Returns

boolean


contents()

contents(options?): Promise<(File | Dir)[]>;

Defined in: packages/fs-testkit/src/dir.js:171

Provides the contents of the directory as an array of Dir and File instances

Parameters

ParameterTypeDescription
options?ObjectEncodingOptions & object-

Returns

Promise<(File | Dir)[]>


copyFromExternal()

copyFromExternal(srcPath, options?): Promise<(File | Dir)[]>;

Defined in: packages/fs-testkit/src/dir.js:492

Copies an file or directory at an absolute path from outside the sandbox into the current directory

Parameters

ParameterTypeDescription
srcPathstring-
options?{ as?: string; contentsOnly?: boolean; overwrite?: boolean; recursive?: boolean; }-
options.as?stringdefaults to undefined - when copying the directory and not its contents the directory copied can be renamed as specified by the options.as
options.contentsOnly?booleandefaults to true - Applies only when copying directories, when true it copies the contents of the directory (equivalent to cp src/ dist), when false it copies the directory and its contents (equivalent to cp src dist)
options.overwrite?booleandefaults to false
options.recursive?booleandefaults to true

Returns

Promise<(File | Dir)[]>

Returns an array of Dir and/or File instances representing the copied items. When copying a directory and its contents (options.contentsOnly is false) the returned array contains a single Dir instance.


copyTo()

copyTo(destDir, options?): Promise<(File | Dir)[]>;

Defined in: packages/fs-testkit/src/dir.js:406

Copies a file or directory into the current directory. See contentsOnly option for control over copying the directory or its contents.

Parameters

ParameterTypeDescription
destDirDir-
options?{ as?: string; contentsOnly?: boolean; overwrite?: boolean; recursive?: boolean; }-
options.as?stringdefaults to undefined - when copying the directory and not its contents the directory copied can be renamed as specified by the options.as
options.contentsOnly?booleandefaults to true - Applies only when copying directories, when true it copies the contents of the directory (equivalent to cp src/ dist), when false it copies the directory and its contents (equivalent to cp src dist)
options.overwrite?booleandefaults to false
options.recursive?booleandefaults to true

Returns

Promise<(File | Dir)[]>


create()

create(options?): Promise<Dir>;

Defined in: packages/fs-testkit/src/dir.js:146

Creates the directory on the filesystem. By default, intermediate directories are recursively created, this can be changed by providing a options.recursive argument

Parameters

ParameterTypeDescription
options?Mode | MakeDirectoryOptions | null-

Returns

Promise<Dir>


delete()

delete(options?): Promise<Dir>;

Defined in: packages/fs-testkit/src/dir.js:273

Delete the directory on the filesystem

Parameters

ParameterTypeDescription
options?RmOptions-

Returns

Promise<Dir>


diff()

diff(
   snapshotOne, 
   snapshotTwo, 
options?): Promise<DirDiff[]>;

Defined in: packages/fs-testkit/src/dir.js:383

Creates an array of objects that describe the diff of the directory between two snapshots. By default, the diff of directories are included, this can be changed by specifying options.includeDirs

Parameters

ParameterTypeDescription
snapshotOnestring-
snapshotTwostring-
options?{ includeDirs?: boolean; }-
options.includeDirs?boolean-

Returns

Promise<DirDiff[]>


dir()

dir(name): Dir;

Defined in: packages/fs-testkit/src/dir.js:95

Create a Dir pointing to the given name within the directory

Parameters

ParameterTypeDescription
namestring-

Returns

Dir


exists()

exists(): Promise<boolean>;

Defined in: packages/fs-testkit/src/dir.js:262

Returns true if the directory exists on the filesystem, otherwise false, based on fs.access(file, F_OK). Implementation subject to change

Returns

Promise<boolean>


file()

file(name): File;

Defined in: packages/fs-testkit/src/dir.js:83

Create a File pointing to the given name within the directory

Parameters

ParameterTypeDescription
namestring-

Returns

File


hash()

hash(snapshot?): Promise<string | undefined>;

Defined in: packages/fs-testkit/src/dir.js:366

Creates a unique hash for the directory and its contents based on the filesystem, optionally for a given snapshot. Two directories represented by the same hash have the same contents.

Parameters

ParameterTypeDescription
snapshot?string-

Returns

Promise<string | undefined>

Returns hash string if the directory exists for the given snapshot or the current filesystem, otherwise returns undefined


move()

move(newParent): Promise<Dir>;

Defined in: packages/fs-testkit/src/dir.js:212

Move the directory to a new parent directory on the filesystem

Parameters

ParameterTypeDescription
newParentDir-

Returns

Promise<Dir>

Returns a Dir representing the moved directory at its new path


read()

read(options): Promise<(File | Dir)[]>;

Defined in: packages/fs-testkit/src/dir.js:162

Provides the contents of the directory as an array of Dir and File instances Alias for Dir.contents

Parameters

ParameterTypeDescription
optionsObjectEncodingOptions & object | undefined-

Returns

Promise<(File | Dir)[]>


rename()

rename(newDirname): Promise<Dir>;

Defined in: packages/fs-testkit/src/dir.js:192

Rename the name of the directory on the filesystem

Parameters

ParameterTypeDescription
newDirnamestring-

Returns

Promise<Dir>

Returns a Dir representing the renamed directory at its new path


scaffold()

scaffold<T, Opts>(scaffoldDir, options?): Promise<ScaffoldResult<T, Opts>>;

Defined in: packages/fs-testkit/src/dir.js:299

Scaffold nested files and directories on the file system, within the current directory. The file options can be specified for all files, for example: dir.scaffold({ dir: { “readme.md”: ”# My Readme” }}, { overwrite: true, prettier: true })

or file options can be specified per file, for example: dir.scaffold({ dir: { “readme.md”: [”# My Readme”, { overwrite: true, prettier: true }] }});

By default options.prettier option will based on the option passed to the sandbox. Only files with known extensions to prettier can be prettier.

Type Parameters

Type ParameterDefault typeDescription
T extends ScaffoldDir<ScaffoldFile>-
Opts extends ScaffoldOptionsobject

Parameters

ParameterTypeDescription
scaffoldDirT-
options?Opts-

Returns

Promise<ScaffoldResult<T, Opts>>

Returns an object representing the scaffolded structure, with the same shape as the scaffoldDir argument. By default Dir instances are not included unless options.includeDirInstances is true.


tree()

tree(options?): Promise<ObjectTree<string>>;

Defined in: packages/fs-testkit/src/dir.js:345

Returns a object representing the nested tree structure of the directory from the filesystem

Parameters

ParameterTypeDescription
options?{ blobFileMask?: "hash" | "filename"; textFileMask?: "hash" | "filename" | "file-contents"; }-
options.blobFileMask?"hash" | "filename"-
options.textFileMask?"hash" | "filename" | "file-contents"-

Returns

Promise<ObjectTree<string>>


treeString()

treeString(options?): Promise<string>;

Defined in: packages/fs-testkit/src/dir.js:323

Returns a tree string of the filesystem from the current directory

Parameters

ParameterTypeDescription
options?{ blobFileMask?: "hash" | "filename"; textFileMask?: "hash" | "filename" | "file-contents"; }-
options.blobFileMask?"hash" | "filename"-
options.textFileMask?"hash" | "filename" | "file-contents"-

Returns

Promise<string>