Skip to content

Commit

Permalink
Merge pull request #3 from tschaub/win
Browse files Browse the repository at this point in the history
Confirm that tests pass on Windows.
  • Loading branch information
tschaub committed Jan 13, 2014
2 parents 99e3fdf + a904f88 commit 85bd0ee
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ function getPathParts(filepath) {
var parts = path._makeLong(path.resolve(filepath)).split(path.sep);
parts.shift();
if (isWindows) {
// parts currently looks like ['', '?', 'c:', ...]
parts.shift();
var q = parts.shift(); // should be '?'
var base = '\\\\' + q + '\\' + parts.shift().toLowerCase();
parts.unshift(base);
}
if (parts[parts.length - 1] === '') {
parts.pop();
}
return parts;
}
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,6 @@ Mock `fs.Stats` objects have the following properties: `dev`, `ino`, `nlink`, `m

The following `fs` functions are *not* currently mocked (if your tests use these, they will work against the real file system): `fs.FSWatcher`, `fs.unwatchFile`, `fs.watch`, and `fs.watchFile`. Pull requests welcome.

Tested on Linux, OSX, and Windows using Node 0.8, 0.10, and 0.11. Check the tickets for a list of [known issues](https://github.com/tschaub/mock-fs/issues).

[![Current Status](https://secure.travis-ci.org/tschaub/mock-fs.png?branch=master)](https://travis-ci.org/tschaub/mock-fs)
62 changes: 60 additions & 2 deletions test/lib/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var os = require('os');
var path = require('path');

var mock = require('../../lib/index');
Expand All @@ -20,6 +21,27 @@ describe('The API', function() {

});

describe('mock()', function() {

it('creates process.cwd() and os.tmpdir() by default', function() {
mock();

assert.isTrue(fs.statSync(process.cwd()).isDirectory());
var tmp;
if (os.tmpdir) {
tmp = os.tmpdir();
} else if (os.tmpDir) {
tmp = os.tmpDir();
}
if (tmp) {
assert.isTrue(fs.statSync(tmp).isDirectory());
}

mock.restore();
});

});

describe('mock.restore()', function() {

it('restores bindings for the real file system', function() {
Expand Down Expand Up @@ -90,6 +112,34 @@ describe('The API', function() {

});

it('works with a trailing slash', function() {

mock({
'path/to/dir/': mock.directory({
mtime: new Date(8675309),
mode: 0644
})
});

assert.isTrue(fs.statSync('path/to/dir').isDirectory());
assert.isTrue(fs.statSync('path/to/dir/').isDirectory());

});

it('works without a trailing slash', function() {

mock({
'path/to/dir': mock.directory({
mtime: new Date(8675309),
mode: 0644
})
});

assert.isTrue(fs.statSync('path/to/dir').isDirectory());
assert.isTrue(fs.statSync('path/to/dir/').isDirectory());

});

});

describe('mock.symlink()', function() {
Expand Down Expand Up @@ -372,8 +422,16 @@ describe('Mocking the file system', function() {
assert.instanceOf(stats.ctime, Date);
assert.instanceOf(stats.mtime, Date);
assert.instanceOf(stats.atime, Date);
assert.isNumber(stats.uid);
assert.isNumber(stats.gid);
if (process.getuid) {
assert.isNumber(stats.uid);
} else {
assert.isUndefined(stats.uid);
}
if (process.getgid) {
assert.isNumber(stats.gid);
} else {
assert.isUndefined(stats.gid);
}
assert.equal(stats.nlink, 3);
assert.isNumber(stats.blocks);
assert.isNumber(stats.blksize);
Expand Down

0 comments on commit 85bd0ee

Please sign in to comment.