install gulp
This commit is contained in:
+101
@@ -0,0 +1,101 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vfs = require('../lib/fs'),
|
||||
TEST_DIR = path.join(__dirname, 'test-dir');
|
||||
|
||||
module.exports = {
|
||||
setUp : function(done) {
|
||||
fs.mkdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
tearDown : function(done) {
|
||||
fs.rmdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
'should copy file' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file'),
|
||||
targetFile = path.join(TEST_DIR, 'target-file');
|
||||
fs.writeFileSync(sourceFile, 'source');
|
||||
vfs.copy(sourceFile, targetFile)
|
||||
.then(function() {
|
||||
test.equal(fs.readFileSync(targetFile, 'utf8'), 'source');
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(sourceFile);
|
||||
fs.unlinkSync(targetFile);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should copy file if target exists' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file'),
|
||||
targetFile = path.join(TEST_DIR, 'target-file');
|
||||
fs.writeFileSync(sourceFile, 'source');
|
||||
fs.writeFileSync(targetFile, 'target');
|
||||
vfs.copy(sourceFile, targetFile)
|
||||
.then(function() {
|
||||
test.equal(fs.readFileSync(targetFile, 'utf8'), 'source');
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(sourceFile);
|
||||
fs.unlinkSync(targetFile);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should not copy file if source is directory' : function(test) {
|
||||
var sourceDir = path.join(TEST_DIR, 'source-dir'),
|
||||
targetFile = path.join(TEST_DIR, 'target-file');
|
||||
fs.mkdirSync(sourceDir);
|
||||
vfs.copy(sourceDir, targetFile)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function(err) {
|
||||
test.equal(err.code, 'EISDIR');
|
||||
})
|
||||
.always(function() {
|
||||
fs.rmdirSync(sourceDir);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should not copy file if target is directory' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file'),
|
||||
targetDir = path.join(TEST_DIR, 'target-dir');
|
||||
fs.writeFileSync(sourceFile, 'source');
|
||||
fs.mkdirSync(targetDir);
|
||||
vfs.copy(sourceFile, targetDir)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function(err) {
|
||||
test.equal(err.code, 'EISDIR');
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(sourceFile);
|
||||
fs.rmdirSync(targetDir);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should not copy if target not exists' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file'),
|
||||
targetFile = path.join(TEST_DIR, 'target-file');
|
||||
vfs.copy(sourceFile, targetFile)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function(err) {
|
||||
test.equal(err.code, 'ENOENT');
|
||||
})
|
||||
.always(function() {
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vfs = require('../lib/fs'),
|
||||
TEST_DIR = path.join(__dirname, 'test-dir');
|
||||
|
||||
module.exports = {
|
||||
setUp : function(done) {
|
||||
fs.mkdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
tearDown : function(done) {
|
||||
fs.rmdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
'should return true if the file is a symbolic link' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file'),
|
||||
targetFile = path.join(TEST_DIR, 'target-file');
|
||||
fs.writeFileSync(sourceFile, 'source');
|
||||
fs.symlinkSync(sourceFile, targetFile);
|
||||
vfs.isSymLink(targetFile)
|
||||
.then(function(isSymLink) {
|
||||
test.ok(isSymLink);
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(sourceFile);
|
||||
fs.unlinkSync(targetFile);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should return false if the file is not a symbolic link' : function(test) {
|
||||
var sourceFile = path.join(TEST_DIR, 'source-file');
|
||||
fs.writeFileSync(sourceFile, 'source');
|
||||
vfs.isSymLink(sourceFile)
|
||||
.then(function(isSymLink) {
|
||||
test.ok(!isSymLink);
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(sourceFile);
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vfs = require('../lib/fs'),
|
||||
TEST_DIR = path.join(__dirname, 'test-dir');
|
||||
|
||||
module.exports = {
|
||||
setUp : function(done) {
|
||||
fs.mkdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
tearDown : function(done) {
|
||||
fs.rmdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
'should make directory' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'a');
|
||||
vfs.makeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
return vfs.exists(dir);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(promise.valueOf());
|
||||
test.ok(fs.statSync(dir).isDirectory());
|
||||
fs.rmdirSync(dir);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should make directory if exists' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'a');
|
||||
fs.mkdirSync(dir);
|
||||
vfs.makeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
return vfs.exists(dir);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(promise.valueOf());
|
||||
test.ok(fs.statSync(dir).isDirectory());
|
||||
fs.rmdirSync(dir);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should be failed if directory exists' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'a');
|
||||
fs.mkdirSync(dir);
|
||||
vfs.makeDir(dir, true)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function() {
|
||||
test.ok(true);
|
||||
})
|
||||
.always(function() {
|
||||
fs.rmdirSync(dir);
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should be failed if file with same name exists' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'test-file');
|
||||
fs.writeFileSync(dir, 'test');
|
||||
vfs.makeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function() {
|
||||
test.ok(true);
|
||||
})
|
||||
.always(function() {
|
||||
fs.unlinkSync(path.join(TEST_DIR, 'test-file'));
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should make directory tree' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'a/b/c');
|
||||
vfs.makeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
return vfs.exists(dir);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(promise.valueOf());
|
||||
test.ok(fs.statSync(dir).isDirectory());
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a/b/c'));
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a/b'));
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a'));
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should make directory tree if exists' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'a/b/c');
|
||||
fs.mkdirSync(path.join(TEST_DIR, 'a'));
|
||||
fs.mkdirSync(path.join(TEST_DIR, 'a', 'b'));
|
||||
fs.mkdirSync(dir);
|
||||
vfs.makeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(true);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function() {
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a/b/c'));
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a/b'));
|
||||
fs.rmdirSync(path.join(TEST_DIR, 'a'));
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
os = require('os'),
|
||||
vfs = require('../lib/fs'),
|
||||
tmpDir = os.tmpdir || os.tmpDir || function() { return '/tmp'; },
|
||||
TEST_DIR = path.join(__dirname, 'test-dir');
|
||||
|
||||
module.exports = {
|
||||
setUp : function(done) {
|
||||
fs.mkdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
tearDown : function(done) {
|
||||
fs.rmdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
'should make temporary file with default options' : function(test) {
|
||||
var filePath;
|
||||
vfs.makeTmpFile()
|
||||
.then(
|
||||
function(_filePath) {
|
||||
return vfs.exists(filePath = _filePath);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
throw Error();
|
||||
})
|
||||
.then(function(exists) {
|
||||
fs.unlinkSync(filePath);
|
||||
test.strictEqual(path.dirname(filePath), path.resolve(tmpDir()));
|
||||
test.strictEqual(path.extname(filePath), '.tmp');
|
||||
test.ok(exists);
|
||||
})
|
||||
.always(function() {
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should make temporary file in custom directory' : function(test) {
|
||||
var filePath;
|
||||
vfs.makeTmpFile({ dir : TEST_DIR })
|
||||
.then(
|
||||
function(_filePath) {
|
||||
return vfs.exists(filePath = _filePath);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
throw Error();
|
||||
})
|
||||
.then(function(exists) {
|
||||
fs.unlinkSync(filePath);
|
||||
test.ok(exists);
|
||||
test.strictEqual(path.dirname(filePath), TEST_DIR);
|
||||
})
|
||||
.always(function() {
|
||||
test.done();
|
||||
})
|
||||
},
|
||||
|
||||
'should make temporary file with custom prefix' : function(test) {
|
||||
var filePath;
|
||||
vfs.makeTmpFile({ prefix : '__prefix' })
|
||||
.then(
|
||||
function(_filePath) {
|
||||
return vfs.exists(filePath = _filePath);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
throw Error();
|
||||
})
|
||||
.then(function(exists) {
|
||||
fs.unlinkSync(filePath);
|
||||
test.ok(exists);
|
||||
test.ok(filePath.indexOf('__prefix') > -1);
|
||||
})
|
||||
.always(function() {
|
||||
test.done();
|
||||
})
|
||||
},
|
||||
|
||||
'should make temporary file with custom extension' : function(test) {
|
||||
var filePath;
|
||||
vfs.makeTmpFile({ ext : '.css' })
|
||||
.then(
|
||||
function(_filePath) {
|
||||
return vfs.exists(filePath = _filePath);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
throw Error();
|
||||
})
|
||||
.then(function(exists) {
|
||||
fs.unlinkSync(filePath);
|
||||
test.ok(exists);
|
||||
test.strictEqual(path.extname(filePath), '.css');
|
||||
})
|
||||
.always(function() {
|
||||
test.done();
|
||||
})
|
||||
}
|
||||
};
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vfs = require('../lib/fs'),
|
||||
TEST_DIR = path.join(__dirname, 'test-dir');
|
||||
|
||||
module.exports = {
|
||||
setUp : function(done) {
|
||||
fs.mkdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
tearDown : function(done) {
|
||||
fs.rmdirSync(TEST_DIR);
|
||||
done();
|
||||
},
|
||||
|
||||
'should remove empty directory' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'dir');
|
||||
fs.mkdirSync(dir);
|
||||
vfs.removeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
return vfs.exists(dir);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(!promise.valueOf());
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should remove directory tree' : function(test) {
|
||||
var dir = path.join(TEST_DIR, 'dir');
|
||||
fs.mkdirSync(dir);
|
||||
fs.mkdirSync(path.join(dir, 'a'));
|
||||
fs.writeFileSync(path.join(dir, 'a', 'file'), 'file');
|
||||
fs.mkdirSync(path.join(dir, 'a', 'b'));
|
||||
fs.writeFileSync(path.join(dir, 'a', 'b', 'file1'), 'file1');
|
||||
fs.writeFileSync(path.join(dir, 'a', 'b', 'file2'), 'file2');
|
||||
vfs.removeDir(dir)
|
||||
.then(
|
||||
function() {
|
||||
return vfs.exists(dir);
|
||||
},
|
||||
function() {
|
||||
test.ok(false);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(!promise.valueOf());
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
|
||||
'should not remove file' : function(test) {
|
||||
var filePath = path.join(TEST_DIR, 'file');
|
||||
fs.writeFileSync(filePath, 'file');
|
||||
vfs.removeDir(filePath)
|
||||
.then(
|
||||
function() {
|
||||
test.ok(false);
|
||||
},
|
||||
function(err) {
|
||||
test.equal(err.code, 'ENOTDIR');
|
||||
return vfs.exists(filePath);
|
||||
})
|
||||
.always(function(promise) {
|
||||
test.ok(promise.valueOf());
|
||||
fs.unlinkSync(filePath);
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
require('nodeunit').reporters.default.run(
|
||||
fs.readdirSync(__dirname)
|
||||
.filter(function(file){
|
||||
return fs.statSync(path.join(__dirname, file)).isFile() && file !== 'runner.js';
|
||||
})
|
||||
.map(function(file) {
|
||||
return path.join('test', file);
|
||||
}),
|
||||
null,
|
||||
function(err) {
|
||||
err && process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user