1 | import FileSystem = require("./lib/filesystem");
|
2 | import File = require("./lib/file");
|
3 | import Directory = require("./lib/directory");
|
4 | import SymbolicLink = require("./lib/symlink");
|
5 |
|
6 | export = mock;
|
7 |
|
8 | /**
|
9 | * Swap out the fs bindings for a mock file system.
|
10 | *
|
11 | * _Note:_ Import this file _before_ any other modules that import the `fs`
|
12 | * module.
|
13 | *
|
14 | * @param config Mock file system configuration.
|
15 | * @param options Any filesystem options.
|
16 | * @param options.createCwd Create a directory for `process.cwd()` (defaults to
|
17 | * `true`).
|
18 | * @param options.createTmp Create a directory for `os.tmpdir()` (defaults to
|
19 | * `true`).
|
20 | */
|
21 | declare function mock(config?: FileSystem.DirectoryItems, options?: FileSystem.Options): void;
|
22 |
|
23 | declare namespace mock {
|
24 | /**
|
25 | * Temporarily bypass the mocked file system and load directly from the real file system.
|
26 | *
|
27 | * @example
|
28 | * const filePath = '/path/file.json';
|
29 | * const data = mock.bypass(() => fs.readFileSync(filePath, 'utf-8'));
|
30 | */
|
31 | function bypass<T>(fn: () => T): T;
|
32 |
|
33 | /**
|
34 | * Load a real file/folder into the mock file system.
|
35 | */
|
36 | function load(path: string, options?: FileSystem.LoaderOptions): FileSystem.DirectoryItem;
|
37 |
|
38 | /**
|
39 | * Get hold of the mocked filesystem's 'root'
|
40 | * If fs hasn't currently been replaced, this will return an empty object
|
41 | */
|
42 | function getMockRoot(): Directory | {};
|
43 |
|
44 | /**
|
45 | * Restore the fs bindings for the real file system.
|
46 | */
|
47 | function restore(): void;
|
48 |
|
49 | /**
|
50 | * Create a file factory.
|
51 | */
|
52 | function file(config?: FileSystem.FileOptions): () => File;
|
53 | /**
|
54 | * Create a directory factory.
|
55 | */
|
56 | function directory(config?: FileSystem.DirectoryOptions): () => Directory;
|
57 | /**
|
58 | * Create a symbolic link factory.
|
59 | */
|
60 | function symlink(config: FileSystem.SymlinkOptions): () => SymbolicLink;
|
61 | }
|