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