Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test on Windows #3

Merged
merged 5 commits into from
Jan 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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