Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('emptyDir() - callback', callback => {
const target = join(tmpDir, 'test');
const checkExistsMap = {
[join('.hidden', 'a.txt')]: true,
[join('.hidden', 'b.js')]: true,
[join('.hidden', 'c', 'd')]: true,
'e.txt': false,
'f.js': false,
'.g': true,
[join('folder', 'h.txt')]: false,
[join('folder', 'i.js')]: false,
[join('folder', '.j')]: true
};
createDummyFolder(target, tiferr(callback, () => {
fs.emptyDir(target, tiferr(callback, files => {
files.should.have.members([
'e.txt',
'f.js',
join('folder', 'h.txt'),
join('folder', 'i.js')
]);
return Promise.map(Object.keys(checkExistsMap), path => {
return fs.exists(join(target, path)).should.become(checkExistsMap[path]);
}).asCallback(tiferr(callback, () => {
fs.rmdir(target, callback);
}));
}));
}));
});
it('mkdirs() - callback', callback => {
const target = join(tmpDir, 'a', 'b', 'c');
fs.mkdirs(target, tiferr(callback, () => {
fs.exists(target, exist => {
exist.should.be.true;
fs.rmdir(join(tmpDir, 'a'), callback);
});
}));
});
it('ensurePath() - callback', callback => {
const target = join(tmpDir, 'test');
const filenames = ['foo.txt', 'foo-1.txt', 'foo-2.md', 'bar.txt'];
Promise.map(filenames, path => fs.writeFile(join(target, path))).asCallback(tiferr(callback, () => {
fs.ensurePath(join(target, 'foo.txt'), tiferr(callback, path => {
path.should.eql(join(target, 'foo-2.txt'));
fs.rmdir(target, callback);
}));
}));
});
Promise.map(filenames, path => fs.writeFile(join(target, path))).asCallback(tiferr(callback, () => {
fs.ensurePath(join(target, 'foo.txt'), tiferr(callback, path => {
path.should.eql(join(target, 'foo-2.txt'));
fs.rmdir(target, callback);
}));
}));
});
fs.copyDir(src, dest, tiferr(callback, files => {
files.should.have.members(finenames);
fs.rmdir(src, tiferr(callback, () => {
Promise.map(finenames, path => fs.readFile(join(dest, path))).asCallback(tiferr(callback, result => {
result.should.eql(['e', 'f', 'h', 'i']);
fs.rmdir(dest, callback);
}));
}));
}));
}));
createDummyFolder(target, tiferr(callback, () => {
fs.listDir(target, tiferr(callback, paths => {
paths.should.have.members(filenames);
fs.rmdir(target, callback);
}));
}));
});
createDummyFolder(src, tiferr(callback, () => {
fs.copyDir(src, dest, tiferr(callback, files => {
files.should.have.members(finenames);
fs.rmdir(src, tiferr(callback, () => {
Promise.map(finenames, path => fs.readFile(join(dest, path))).asCallback(tiferr(callback, result => {
result.should.eql(['e', 'f', 'h', 'i']);
fs.rmdir(dest, callback);
}));
}));
}));
}));
});
fs.writeFile(src, body, tiferr(callback, () => {
fs.copyFile(src, dest, tiferr(callback, () => {
fs.readFile(dest, tiferr(callback, content => {
content.should.eql(body);
Promise.all([
fs.unlink(src),
fs.rmdir(join(tmpDir, 'a'))
]).asCallback(callback);
}));
}));
}));
});
createDummyFolder(target, tiferr(callback, () => {
fs.emptyDir(target, tiferr(callback, files => {
files.should.have.members([
'e.txt',
'f.js',
join('folder', 'h.txt'),
join('folder', 'i.js')
]);
return Promise.map(Object.keys(checkExistsMap), path => {
return fs.exists(join(target, path)).should.become(checkExistsMap[path]);
}).asCallback(tiferr(callback, () => {
fs.rmdir(target, callback);
}));
}));
}));
});
fs.writeFile(target, body, tiferr(callback, () => {
fs.appendFile(target, body2, tiferr(callback, () => {
fs.readFile(target, tiferr(callback, content => {
content.should.eql(body + body2);
fs.rmdir(join(tmpDir, 'a'), callback);
}));
}));
}));
});