Defined in: packages/fs-testkit/src/file.js:15
new File(options): File;
Defined in: packages/fs-testkit/src/file.js:77
| Parameter | Type | Description |
|---|---|---|
options | { name: string; parent: Dir; sandbox: Sandbox; } | - |
options.name | string | - |
options.parent | Dir | - |
options.sandbox | Sandbox | - |
File
get absolutePath(): string;
Defined in: packages/fs-testkit/src/file.js:48
The absolute path of the file
string
get extension(): string;
Defined in: packages/fs-testkit/src/file.js:56
The extension of the file
string
get name(): string;
Defined in: packages/fs-testkit/src/file.js:24
The name of the file
string
get parent(): Dir;
Defined in: packages/fs-testkit/src/file.js:32
The parent Dir of the file
get path(): string;
Defined in: packages/fs-testkit/src/file.js:40
The path of the file relative to the sandbox root
string
access(mode): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:288
Check the access of the directory on the filesystem
| Parameter | Type | Description |
|---|---|---|
mode | number | undefined | - |
Promise<File>
contents(options?): Promise<string | Buffer<ArrayBufferLike>>;
Defined in: packages/fs-testkit/src/file.js:98
| Parameter | Type | Description |
|---|---|---|
options? | BufferEncoding | ObjectEncodingOptions & Abortable & object | null | - |
Promise<string | Buffer<ArrayBufferLike>>
File.read
copyTo(destDir, options?): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:159
| Parameter | Type | Description |
|---|---|---|
destDir | Dir | - |
options? | { as?: string; overwrite?: boolean; } | - |
options.as? | string | - |
options.overwrite? | boolean | - |
Promise<File>
Returns a File representing the copied destination path
create(contents, options?): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:278
| Parameter | Type | Description |
|---|---|---|
contents | | string | Stream | ArrayBufferView<ArrayBufferLike> | Iterable<string | ArrayBufferView<ArrayBufferLike>, any, any> | AsyncIterable<string | ArrayBufferView<ArrayBufferLike>, any, any> | - |
options? | (BufferEncoding | (ObjectEncodingOptions & { mode?: Mode | undefined; flag?: OpenMode | undefined; flush?: boolean | undefined; } & Abortable) | null | undefined) & { …; } | - |
Promise<File>
File.write
delete(): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:310
Delete the directory on the filesystem
Promise<File>
diffBlob(snapshotOne, snapshotTwo): Promise<BlobDiff[] | null>;
Defined in: packages/fs-testkit/src/file.js:431
Returns a diff for the file on the filesystem, treating the file as a blob
| Parameter | Type | Description |
|---|---|---|
snapshotOne | string | - |
snapshotTwo | string | - |
Promise<BlobDiff[] | null>
diffText(
snapshotOne,
snapshotTwo,
format): Promise<FileDiff>;
Defined in: packages/fs-testkit/src/file.js:341
| Parameter | Type | Description |
|---|---|---|
snapshotOne | string | - |
snapshotTwo | string | - |
format | "diff-object" | - |
Promise<FileDiff>
diffText(
snapshotOne,
snapshotTwo,
format): Promise<string>;
Defined in: packages/fs-testkit/src/file.js:348
| Parameter | Type | Description |
|---|---|---|
snapshotOne | string | - |
snapshotTwo | string | - |
format | "patch-string" | - |
Promise<string>
exists(): Promise<boolean>;
Defined in: packages/fs-testkit/src/file.js:301
Check the access of the directory on the filesystem
Not exactly the same as exists but should work in most cases
based on access(file, F_OK). See: https://github.com/nodejs/node/issues/39960
Implementation subject to change
Promise<boolean>
hash(snapshot?): Promise<string | undefined>;
Defined in: packages/fs-testkit/src/file.js:322
Creates a unique hash for the current directory and its contents based on the filesystem. Two files represented by the same hash have the same contents.
| Parameter | Type | Description |
|---|---|---|
snapshot? | string | - |
Promise<string | undefined>
move(newParent): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:126
Move the file to a new parent directory on the filesystem
| Parameter | Type | Description |
|---|---|---|
newParent | Dir | - |
Promise<File>
Returns a File representing the moved file at its new path
read(options?): Promise<string | Buffer<ArrayBufferLike>>;
Defined in: packages/fs-testkit/src/file.js:88
Reads the contents of the file
| Parameter | Type | Description |
|---|---|---|
options? | BufferEncoding | ObjectEncodingOptions & Abortable & object | null | - |
Promise<string | Buffer<ArrayBufferLike>>
rename(newFilename): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:107
Rename the name of the file
| Parameter | Type | Description |
|---|---|---|
newFilename | string | - |
Promise<File>
Returns a File representing the renamed file
size(options?): Promise<number | bigint>;
Defined in: packages/fs-testkit/src/file.js:334
Return the size of the file on the filesystem, in bytes
| Parameter | Type | Description |
|---|---|---|
options? | StatOptions | - |
Promise<number | bigint>
write(contents, options?): Promise<File>;
Defined in: packages/fs-testkit/src/file.js:212
Write contents to the file.
By default the existing contents will be overwritten, this can be changed by specifying options.overwrite.
The default options.prettier option will depend on the option passed to the sandbox, but can be changed by
specifying the options.prettier option when calling write. The contents are only passed to prettier when
it’s a known extension prettier can manage.
| Parameter | Type | Description |
|---|---|---|
contents | | string | Stream | ArrayBufferView<ArrayBufferLike> | Iterable<string | ArrayBufferView<ArrayBufferLike>, any, any> | AsyncIterable<string | ArrayBufferView<ArrayBufferLike>, any, any> | - |
options? | (BufferEncoding | (ObjectEncodingOptions & { mode?: Mode | undefined; flag?: OpenMode | undefined; flush?: boolean | undefined; } & Abortable) | null | undefined) & { …; } | - |
Promise<File>