Add type definitions for mock-fs

This commit is contained in:
Wim Looman
2015-03-16 10:54:50 +13:00
parent 95d860879f
commit 190b451f85
2 changed files with 130 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
/// <reference path="mock-fs.d.ts" />
var mock = require('mock-fs');
function a() {
mock({
'path/to/fake/dir': {
'some-file.txt': 'file content here',
'empty-dir': {/** empty directory */}
},
'path/to/some.png': new Buffer([8, 6, 7, 5, 3, 0, 9]),
'some/other/path': {/** another empty directory */}
});
// after a test runs
mock.restore();
}
function b() {
mock({
'path/to/file.txt': 'file content here'
});
}
function c() {
mock({
foo: mock.file({
content: 'file content here',
ctime: new Date(1),
mtime: new Date(1)
})
});
}
function d() {
// note that this could also be written as
// mock({'path/to/dir': { /** config */ }})
mock({
path: {
to: {
dir: {
file1: 'text content',
file2: new Buffer([1, 2, 3, 4])
}
}
}
});
}
function e() {
mock({
'some/dir': mock.directory({
mode: 0755,
items: {
file1: 'file one content',
file2: new Buffer([8, 6, 7, 5, 3, 0, 9])
}
})
});
}
function f() {
mock({
'some/dir': {
'regular-file': 'file contents',
'a-symlink': mock.symlink({
path: 'regular-file'
})
}
});
}
var mockedFS = mock.fs({
'/file': 'blah'
});
if (mockedFS.readFileSync('/file', { encoding: 'utf8' }) === 'blah') {
console.log('woo');
}
+51
View File
@@ -0,0 +1,51 @@
// Type definitions for mock-fs 2.5.0
// Project: https://github.com/tschaub/mock-fs
// Definitions by: Wim Looman <https://github.com/Nemo157>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "mock-fs" {
import fs = require("fs");
function mock(config?: mock.Config): void;
module mock {
function file(config: FileConfig): File;
function directory(config: DirectoryConfig): Directory;
function symlink(config: SymlinkConfig): Symlink;
function restore(): void;
function fs(config?: Config): typeof fs;
interface Config {
[path: string]: string | Buffer | File | Directory | Symlink | Config;
}
interface CommonConfig {
mode?: number;
uid?: number;
git?: number;
atime?: Date;
ctime?: Date;
mtime?: Date;
}
interface FileConfig extends CommonConfig {
content: string | Buffer;
}
interface DirectoryConfig extends CommonConfig {
items: Config;
}
interface SymlinkConfig extends CommonConfig {
path: string;
}
class File { private _file: any; }
class Directory { private _directory: any; }
class Symlink { private _symlink: any; }
}
export = mock;
}