Defined in: packages/fs-testkit/src/dir.js:17
new Dir(options): Dir;
Defined in: packages/fs-testkit/src/dir.js:28
| Parameter | Type | Description |
|---|---|---|
options | { name: string; parent: Dir | null; sandbox: Sandbox; } | - |
options.name | string | - |
options.parent | Dir | null | - |
options.sandbox | Sandbox | - |
Dir
get absolutePath(): string;
Defined in: packages/fs-testkit/src/dir.js:62
The directory’s absolute path
string
get name(): string;
Defined in: packages/fs-testkit/src/dir.js:38
The directory’s name
string
get parent(): Dir | null;
Defined in: packages/fs-testkit/src/dir.js:46
The directory’s parent
Dir | null
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.
string
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
| Parameter | Type | Description |
|---|---|---|
mode? | number | - |
Promise<Dir>
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.
| Parameter | Type | Description |
|---|---|---|
path | string | - |
type? | "Dir" | "File" | - |
File | Dir
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.
| Parameter | Type | Description |
|---|---|---|
fileOrDir | File | Dir | - |
boolean
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
| Parameter | Type | Description |
|---|---|---|
options? | ObjectEncodingOptions & object | - |
Promise<(File | Dir)[]>
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
| Parameter | Type | Description |
|---|---|---|
srcPath | string | - |
options? | { as?: string; contentsOnly?: boolean; overwrite?: boolean; recursive?: boolean; } | - |
options.as? | string | defaults to undefined - when copying the directory and not its contents the directory copied can be renamed as specified by the options.as |
options.contentsOnly? | boolean | defaults 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? | boolean | defaults to false |
options.recursive? | boolean | defaults to true |
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(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.
| Parameter | Type | Description |
|---|---|---|
destDir | Dir | - |
options? | { as?: string; contentsOnly?: boolean; overwrite?: boolean; recursive?: boolean; } | - |
options.as? | string | defaults to undefined - when copying the directory and not its contents the directory copied can be renamed as specified by the options.as |
options.contentsOnly? | boolean | defaults 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? | boolean | defaults to false |
options.recursive? | boolean | defaults to true |
Promise<(File | Dir)[]>
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
| Parameter | Type | Description |
|---|---|---|
options? | Mode | MakeDirectoryOptions | null | - |
Promise<Dir>
delete(options?): Promise<Dir>;
Defined in: packages/fs-testkit/src/dir.js:273
Delete the directory on the filesystem
| Parameter | Type | Description |
|---|---|---|
options? | RmOptions | - |
Promise<Dir>
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
| Parameter | Type | Description |
|---|---|---|
snapshotOne | string | - |
snapshotTwo | string | - |
options? | { includeDirs?: boolean; } | - |
options.includeDirs? | boolean | - |
Promise<DirDiff[]>
dir(name): Dir;
Defined in: packages/fs-testkit/src/dir.js:95
Create a Dir pointing to the given name within the directory
| Parameter | Type | Description |
|---|---|---|
name | string | - |
Dir
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
Promise<boolean>
file(name): File;
Defined in: packages/fs-testkit/src/dir.js:83
Create a File pointing to the given name within the directory
| Parameter | Type | Description |
|---|---|---|
name | string | - |
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.
| Parameter | Type | Description |
|---|---|---|
snapshot? | string | - |
Promise<string | undefined>
Returns hash string if the directory exists for the given snapshot or the current filesystem, otherwise returns undefined
move(newParent): Promise<Dir>;
Defined in: packages/fs-testkit/src/dir.js:212
Move the directory to a new parent directory on the filesystem
| Parameter | Type | Description |
|---|---|---|
newParent | Dir | - |
Promise<Dir>
Returns a Dir representing the moved directory at its new path
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
| Parameter | Type | Description |
|---|---|---|
options | ObjectEncodingOptions & object | undefined | - |
Promise<(File | Dir)[]>
rename(newDirname): Promise<Dir>;
Defined in: packages/fs-testkit/src/dir.js:192
Rename the name of the directory on the filesystem
| Parameter | Type | Description |
|---|---|---|
newDirname | string | - |
Promise<Dir>
Returns a Dir representing the renamed directory at its new path
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 Parameter | Default type | Description |
|---|---|---|
T extends ScaffoldDir<ScaffoldFile> | - | |
Opts extends ScaffoldOptions | object |
| Parameter | Type | Description |
|---|---|---|
scaffoldDir | T | - |
options? | Opts | - |
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(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
| Parameter | Type | Description |
|---|---|---|
options? | { blobFileMask?: "hash" | "filename"; textFileMask?: "hash" | "filename" | "file-contents"; } | - |
options.blobFileMask? | "hash" | "filename" | - |
options.textFileMask? | "hash" | "filename" | "file-contents" | - |
Promise<ObjectTree<string>>
treeString(options?): Promise<string>;
Defined in: packages/fs-testkit/src/dir.js:323
Returns a tree string of the filesystem from the current directory
| Parameter | Type | Description |
|---|---|---|
options? | { blobFileMask?: "hash" | "filename"; textFileMask?: "hash" | "filename" | "file-contents"; } | - |
options.blobFileMask? | "hash" | "filename" | - |
options.textFileMask? | "hash" | "filename" | "file-contents" | - |
Promise<string>