|
|
@ -34,6 +34,8 @@ describe('fse-ensure-symlink', function () { |
|
|
|
[['./foo.txt', './alpha/beta/gamma/symlink.txt'], 'file-error', 'file-success'], |
|
|
|
[['./missing.txt', './symlink.txt'], 'file-broken', 'file-error'], |
|
|
|
[['./missing.txt', './missing-dir/symlink.txt'], 'file-error', 'file-error'], |
|
|
|
// error is thrown if destination path exists
|
|
|
|
[['./foo.txt', './dir-foo/foo.txt'], 'file-error', 'file-dest-exists'], |
|
|
|
[['./dir-foo', './symlink-dir-foo'], 'dir-success', 'dir-success'], |
|
|
|
[['../dir-bar', './dir-foo/symlink-dir-bar'], 'dir-success', 'dir-success'], |
|
|
|
[['./dir-bar', './dir-foo/symlink-dir-bar'], 'dir-broken', 'dir-success'], |
|
|
@ -45,6 +47,8 @@ describe('fse-ensure-symlink', function () { |
|
|
|
[['./dir-foo', './alpha/beta/dir-foo'], 'dir-error', 'dir-success'], |
|
|
|
[['./dir-foo', './alpha/beta/gamma/dir-foo'], 'dir-error', 'dir-success'], |
|
|
|
[['./missing', './dir-foo/symlink-dir-missing'], 'dir-broken', 'dir-error'], |
|
|
|
// error is thrown if destination path exists
|
|
|
|
[['./dir-foo', './real-alpha/real-beta'], 'dir-error', 'dir-dest-exists'], |
|
|
|
[[path.resolve(path.join(TEST_DIR, './foo.txt')), './symlink.txt'], 'file-success', 'file-success'], |
|
|
|
[[path.resolve(path.join(TEST_DIR, './dir-foo/foo.txt')), './symlink.txt'], 'file-success', 'file-success'], |
|
|
|
[[path.resolve(path.join(TEST_DIR, './missing.txt')), './symlink.txt'], 'file-broken', 'file-error'], |
|
|
@ -141,6 +145,23 @@ describe('fse-ensure-symlink', function () { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function fileDestExists (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
|
var should = util.format('should do nothing using src `%s` and dst `%s`', srcpath, dstpath) |
|
|
|
it(should, function (done) { |
|
|
|
var destinationContentBefore = fs.readFileSync(dstpath, 'utf8') |
|
|
|
var callback = function (err) { |
|
|
|
if (err) return done(err) |
|
|
|
var destinationContentAfter = fs.readFileSync(dstpath, 'utf8') |
|
|
|
assert.equal(destinationContentBefore, destinationContentAfter) |
|
|
|
return done() |
|
|
|
} |
|
|
|
args.push(callback) |
|
|
|
return fn.apply(null, args) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function dirSuccess (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
@ -206,6 +227,23 @@ describe('fse-ensure-symlink', function () { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function dirDestExists (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
|
var should = util.format('should do nothing using src `%s` and dst `%s`', srcpath, dstpath) |
|
|
|
it(should, function (done) { |
|
|
|
var destinationContentBefore = fs.readdirSync(dstpath) |
|
|
|
var callback = function (err) { |
|
|
|
if (err) return done(err) |
|
|
|
var destinationContentAfter = fs.readdirSync(dstpath) |
|
|
|
assert.deepEqual(destinationContentBefore, destinationContentAfter) |
|
|
|
return done() |
|
|
|
} |
|
|
|
args.push(callback) |
|
|
|
return fn.apply(null, args) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function fileSuccessSync (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
@ -261,6 +299,18 @@ describe('fse-ensure-symlink', function () { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function fileDestExistsSync (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
|
var should = util.format('should do nothing using src `%s` and dst `%s`', srcpath, dstpath) |
|
|
|
it(should, function () { |
|
|
|
var destinationContentBefore = fs.readFileSync(dstpath, 'utf8') |
|
|
|
fn.apply(null, args) |
|
|
|
var destinationContentAfter = fs.readFileSync(dstpath, 'utf8') |
|
|
|
assert.equal(destinationContentBefore, destinationContentAfter) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function dirSuccessSync (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
@ -316,6 +366,18 @@ describe('fse-ensure-symlink', function () { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function dirDestExistsSync (args, fn) { |
|
|
|
var srcpath = args[0] |
|
|
|
var dstpath = args[1] |
|
|
|
var should = util.format('should do nothing using src `%s` and dst `%s`', srcpath, dstpath) |
|
|
|
it(should, function () { |
|
|
|
var destinationContentBefore = fs.readdirSync(dstpath) |
|
|
|
fn.apply(null, args) |
|
|
|
var destinationContentAfter = fs.readdirSync(dstpath) |
|
|
|
assert.deepEqual(destinationContentBefore, destinationContentAfter) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
describe('fs.symlink()', function () { |
|
|
|
var fn = fs.symlink |
|
|
|
tests.forEach(function (test) { |
|
|
@ -325,10 +387,12 @@ describe('fse-ensure-symlink', function () { |
|
|
|
if (nativeBehavior === 'file-success') fileSuccess(args, fn) |
|
|
|
if (nativeBehavior === 'file-broken') fileBroken(args, fn) |
|
|
|
if (nativeBehavior === 'file-error') fileError(args, fn) |
|
|
|
if (nativeBehavior === 'file-dest-exists') fileDestExists(args, fn) |
|
|
|
args.push('dir') |
|
|
|
if (nativeBehavior === 'dir-success') dirSuccess(args, fn) |
|
|
|
if (nativeBehavior === 'dir-broken') dirBroken(args, fn) |
|
|
|
if (nativeBehavior === 'dir-error') dirError(args, fn) |
|
|
|
if (nativeBehavior === 'dir-dest-exists') dirDestExists(args, fn) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
@ -341,9 +405,11 @@ describe('fse-ensure-symlink', function () { |
|
|
|
if (newBehavior === 'file-success') fileSuccess(args, fn) |
|
|
|
if (newBehavior === 'file-broken') fileBroken(args, fn) |
|
|
|
if (newBehavior === 'file-error') fileError(args, fn) |
|
|
|
if (newBehavior === 'file-dest-exists') fileDestExists(args, fn) |
|
|
|
if (newBehavior === 'dir-success') dirSuccess(args, fn) |
|
|
|
if (newBehavior === 'dir-broken') dirBroken(args, fn) |
|
|
|
if (newBehavior === 'dir-error') dirError(args, fn) |
|
|
|
if (newBehavior === 'dir-dest-exists') dirDestExists(args, fn) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
@ -356,10 +422,12 @@ describe('fse-ensure-symlink', function () { |
|
|
|
if (nativeBehavior === 'file-success') fileSuccessSync(args, fn) |
|
|
|
if (nativeBehavior === 'file-broken') fileBrokenSync(args, fn) |
|
|
|
if (nativeBehavior === 'file-error') fileErrorSync(args, fn) |
|
|
|
if (nativeBehavior === 'file-dest-exists') fileDestExistsSync(args, fn) |
|
|
|
args.push('dir') |
|
|
|
if (nativeBehavior === 'dir-success') dirSuccessSync(args, fn) |
|
|
|
if (nativeBehavior === 'dir-broken') dirBrokenSync(args, fn) |
|
|
|
if (nativeBehavior === 'dir-error') dirErrorSync(args, fn) |
|
|
|
if (nativeBehavior === 'dir-dest-exists') dirDestExistsSync(args, fn) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
@ -372,9 +440,11 @@ describe('fse-ensure-symlink', function () { |
|
|
|
if (newBehavior === 'file-success') fileSuccessSync(args, fn) |
|
|
|
if (newBehavior === 'file-broken') fileBrokenSync(args, fn) |
|
|
|
if (newBehavior === 'file-error') fileErrorSync(args, fn) |
|
|
|
if (newBehavior === 'file-dest-exists') fileDestExistsSync(args, fn) |
|
|
|
if (newBehavior === 'dir-success') dirSuccessSync(args, fn) |
|
|
|
if (newBehavior === 'dir-broken') dirBrokenSync(args, fn) |
|
|
|
if (newBehavior === 'dir-error') dirErrorSync(args, fn) |
|
|
|
if (newBehavior === 'dir-dest-exists') dirDestExistsSync(args, fn) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|