Comparing version 2.5.0 to 2.6.0
@@ -193,2 +193,5 @@ 'use strict'; | ||
} | ||
if (config.hasOwnProperty('birthtime')) { | ||
file.setBirthtime(config.birthtime); | ||
} | ||
return file; | ||
@@ -233,2 +236,5 @@ }; | ||
} | ||
if (config.hasOwnProperty('birthtime')) { | ||
link.setBirthtime(config.birthtime); | ||
} | ||
return link; | ||
@@ -271,2 +277,5 @@ }; | ||
} | ||
if (config.hasOwnProperty('birthtime')) { | ||
dir.setBirthtime(config.birthtime); | ||
} | ||
return dir; | ||
@@ -273,0 +282,0 @@ }; |
@@ -55,2 +55,8 @@ 'use strict'; | ||
/** | ||
* Birth time. | ||
* @type {Date} | ||
*/ | ||
this._birthtime = new Date(now); | ||
/** | ||
* Modification time. | ||
@@ -192,2 +198,20 @@ * @type {Date} | ||
/** | ||
* Get birth time. | ||
* @return {Date} Birth time. | ||
*/ | ||
Item.prototype.getBirthtime = function() { | ||
return this._birthtime; | ||
}; | ||
/** | ||
* Set change time. | ||
* @param {Date} birthtime Birth time. | ||
*/ | ||
Item.prototype.setBirthtime = function(birthtime) { | ||
this._birthtime = birthtime; | ||
}; | ||
/** | ||
* Get modification time. | ||
@@ -282,3 +306,4 @@ * @return {Date} Modification time. | ||
mtime: this.getMTime(), | ||
ctime: this.getCTime() | ||
ctime: this.getCTime(), | ||
birthtime: this.getBirthtime() | ||
}; | ||
@@ -285,0 +310,0 @@ }; |
{ | ||
"name": "mock-fs", | ||
"description": "A configurable mock file system. You know, for testing.", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/tschaub/mock-fs", |
@@ -59,6 +59,7 @@ # `mock-fs` | ||
* **uid** - `number` The user id. Defaults to `process.getuid()`. | ||
* **git** - `number` The group id. Defaults to `process.getgid()`. | ||
* **gid** - `number` The group id. Defaults to `process.getgid()`. | ||
* **atime** - `Date` The last file access time. Defaults to `new Date()`. Updated when file contents are accessed. | ||
* **ctime** - `Date` The last file change time. Defaults to `new Date()`. Updated when file owner or permissions change. | ||
* **mtime** - `Date` The last file modification time. Defaults to `new Date()`. Updated when file contents change. | ||
* **birthtime** - `Date` The time of file creation. Defaults to `new Date()`. | ||
@@ -104,6 +105,7 @@ To create a mock filesystem with a very old file named `foo`, you could do something like this: | ||
* **uid** - `number` The user id. Defaults to `process.getuid()`. | ||
* **git** - `number` The group id. Defaults to `process.getgid()`. | ||
* **gid** - `number` The group id. Defaults to `process.getgid()`. | ||
* **atime** - `Date` The last directory access time. Defaults to `new Date()`. | ||
* **ctime** - `Date` The last directory change time. Defaults to `new Date()`. Updated when owner or permissions change. | ||
* **mtime** - `Date` The last directory modification time. Defaults to `new Date()`. Updated when an item is added, removed, or renamed. | ||
* **birthtime** - `Date` The time of directory creation. Defaults to `new Date()`. | ||
* **items** - `Object` Directory contents. Members will generate additional files, directories, or symlinks. | ||
@@ -137,6 +139,7 @@ | ||
* **uid** - `number` The user id. Defaults to `process.getuid()`. | ||
* **git** - `number` The group id. Defaults to `process.getgid()`. | ||
* **gid** - `number` The group id. Defaults to `process.getgid()`. | ||
* **atime** - `Date` The last symlink access time. Defaults to `new Date()`. | ||
* **ctime** - `Date` The last symlink change time. Defaults to `new Date()`. | ||
* **mtime** - `Date` The last symlink modification time. Defaults to `new Date()`. | ||
* **birthtime** - `Date` The time of symlink creation. Defaults to `new Date()`. | ||
@@ -190,3 +193,3 @@ To create a mock filesystem with a file and a symlink, you could do something like this: | ||
Mock `fs.Stats` objects have the following properties: `dev`, `ino`, `nlink`, `mode`, `size`, `rdev`, `blksize`, `blocks`, `atime`, `ctime`, `mtime`, `uid`, and `gid`. In addition, all of the `is*()` method are provided (e.g. `isDirectory()`, `isFile()`, et al.). | ||
Mock `fs.Stats` objects have the following properties: `dev`, `ino`, `nlink`, `mode`, `size`, `rdev`, `blksize`, `blocks`, `atime`, `ctime`, `mtime`, `birthtime`, `uid`, and `gid`. In addition, all of the `is*()` method are provided (e.g. `isDirectory()`, `isFile()`, et al.). | ||
@@ -193,0 +196,0 @@ Mock file access is controlled based on file mode where `process.getuid()` and `process.getgid()` are available (POSIX systems). On other systems (e.g. Windows) the file mode has no effect. |
@@ -29,3 +29,4 @@ 'use strict'; | ||
ctime: new Date(2), | ||
mtime: new Date(3) | ||
mtime: new Date(3), | ||
birthtime: new Date(4) | ||
}), | ||
@@ -123,3 +124,3 @@ 'one-link.txt': FileSystem.symlink({path: './one.txt'}), | ||
it('includes atime, ctime, and mtime', function(done) { | ||
it('includes atime, ctime, mtime and birthtime', function(done) { | ||
var binding = new Binding(system); | ||
@@ -133,2 +134,3 @@ binding.stat(path.join('mock-dir', 'two.txt'), function(err, stats) { | ||
assert.equal(stats.mtime.getTime(), new Date(3).getTime()); | ||
assert.equal(stats.birthtime.getTime(), new Date(4).getTime()); | ||
done(); | ||
@@ -135,0 +137,0 @@ }); |
@@ -63,2 +63,24 @@ 'use strict'; | ||
describe('#getBirthtime()', function() { | ||
it('returns a date', function() { | ||
var item = new Item(); | ||
var date = item.getBirthtime(); | ||
assert.instanceOf(date, Date); | ||
assert.isTrue(date <= new Date()); | ||
}); | ||
}); | ||
describe('#setBirthtime()', function() { | ||
it('sets the birthtime', function() { | ||
var item = new Item(); | ||
var date = new Date(); | ||
item.setBirthtime(date); | ||
assert.equal(item.getBirthtime(), date); | ||
}); | ||
}); | ||
describe('#getMTime()', function() { | ||
@@ -65,0 +87,0 @@ |
490475
15257
199
43