1. Constructors
  2. Constructor
  3. Accessors
  4. absolutePath
  5. extension
  6. name
  7. parent
  8. path
  9. Methods
  10. access()
  11. contents()
  12. copyTo()
  13. create()
  14. delete()
  15. diffBlob()
  16. diffText()
  17. exists()
  18. hash()
  19. move()
  20. read()
  21. rename()
  22. size()
  23. write()

Class: File

Defined in: packages/fs-testkit/src/file.js:15

Constructors

Constructor

new File(options): File;

Defined in: packages/fs-testkit/src/file.js:77

Parameters

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

Returns

File

Accessors

absolutePath

Get Signature

get absolutePath(): string;

Defined in: packages/fs-testkit/src/file.js:48

The absolute path of the file

Returns

string


extension

Get Signature

get extension(): string;

Defined in: packages/fs-testkit/src/file.js:56

The extension of the file

Returns

string


name

Get Signature

get name(): string;

Defined in: packages/fs-testkit/src/file.js:24

The name of the file

Returns

string


parent

Get Signature

get parent(): Dir;

Defined in: packages/fs-testkit/src/file.js:32

The parent Dir of the file

Returns

Dir


path

Get Signature

get path(): string;

Defined in: packages/fs-testkit/src/file.js:40

The path of the file relative to the sandbox root

Returns

string

Methods

access()

access(mode): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:288

Check the access of the directory on the filesystem

Parameters

ParameterTypeDescription
modenumber | undefined-

Returns

Promise<File>


contents()

contents(options?): Promise<string | Buffer<ArrayBufferLike>>;

Defined in: packages/fs-testkit/src/file.js:98

Parameters

ParameterTypeDescription
options?BufferEncoding | ObjectEncodingOptions & Abortable & object | null-

Returns

Promise<string | Buffer<ArrayBufferLike>>

Alias

File.read


copyTo()

copyTo(destDir, options?): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:159

Parameters

ParameterTypeDescription
destDirDir-
options?{ as?: string; overwrite?: boolean; }-
options.as?string-
options.overwrite?boolean-

Returns

Promise<File>

Returns a File representing the copied destination path


create()

create(contents, options?): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:278

Parameters

ParameterTypeDescription
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) & { …; }-

Returns

Promise<File>

Alias

File.write


delete()

delete(): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:310

Delete the directory on the filesystem

Returns

Promise<File>


diffBlob()

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

Parameters

ParameterTypeDescription
snapshotOnestring-
snapshotTwostring-

Returns

Promise<BlobDiff[] | null>


diffText()

Call Signature

diffText(
   snapshotOne, 
   snapshotTwo, 
format): Promise<FileDiff>;

Defined in: packages/fs-testkit/src/file.js:341

Parameters
ParameterTypeDescription
snapshotOnestring-
snapshotTwostring-
format"diff-object"-
Returns

Promise<FileDiff>

Call Signature

diffText(
   snapshotOne, 
   snapshotTwo, 
format): Promise<string>;

Defined in: packages/fs-testkit/src/file.js:348

Parameters
ParameterTypeDescription
snapshotOnestring-
snapshotTwostring-
format"patch-string"-
Returns

Promise<string>


exists()

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

Returns

Promise<boolean>


hash()

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.

Parameters

ParameterTypeDescription
snapshot?string-

Returns

Promise<string | undefined>


move()

move(newParent): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:126

Move the file to a new parent directory on the filesystem

Parameters

ParameterTypeDescription
newParentDir-

Returns

Promise<File>

Returns a File representing the moved file at its new path


read()

read(options?): Promise<string | Buffer<ArrayBufferLike>>;

Defined in: packages/fs-testkit/src/file.js:88

Reads the contents of the file

Parameters

ParameterTypeDescription
options?BufferEncoding | ObjectEncodingOptions & Abortable & object | null-

Returns

Promise<string | Buffer<ArrayBufferLike>>


rename()

rename(newFilename): Promise<File>;

Defined in: packages/fs-testkit/src/file.js:107

Rename the name of the file

Parameters

ParameterTypeDescription
newFilenamestring-

Returns

Promise<File>

Returns a File representing the renamed file


size()

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

Parameters

ParameterTypeDescription
options?StatOptions-

Returns

Promise<number | bigint>


write()

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.

Parameters

ParameterTypeDescription
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) & { …; }-

Returns

Promise<File>