filer/tests/spec/fs.exists.spec.js

86 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-02-13 19:20:14 +00:00
'use strict';
const util = require('../lib/test-utils.js');
const expect = require('chai').expect;
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
describe('fs.exists', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
it('should be a function', function() {
2019-02-13 19:20:14 +00:00
const fs = util.fs();
2014-05-23 20:53:50 +00:00
expect(typeof fs.exists).to.equal('function');
});
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
it('should return false if path does not exist', function(done) {
2019-02-13 19:20:14 +00:00
const fs = util.fs();
2014-05-23 20:53:50 +00:00
fs.exists('/tmp', function(result) {
expect(result).to.be.false;
done();
2014-02-21 11:53:12 +00:00
});
2014-05-23 20:53:50 +00:00
});
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
it('should return true if path exists', function(done) {
2019-02-13 19:20:14 +00:00
const fs = util.fs();
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
fs.open('/myfile', 'w', function(err, fd) {
if(err) throw err;
2014-05-23 20:53:50 +00:00
fs.close(fd, function(err) {
if(err) throw err;
2014-05-23 20:53:50 +00:00
fs.exists('/myfile', function(result) {
expect(result).to.be.true;
done();
2014-02-21 11:53:12 +00:00
});
});
});
2014-05-23 20:53:50 +00:00
});
it('should follow symbolic links and return true for the resulting path', function(done) {
2019-02-13 19:20:14 +00:00
const fs = util.fs();
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
2014-02-21 11:53:12 +00:00
2014-05-23 20:53:50 +00:00
fs.close(fd, function(error) {
2014-02-21 11:53:12 +00:00
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.symlink('/myfile', '/myfilelink', function(error) {
2014-02-21 11:53:12 +00:00
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.exists('/myfilelink', function(result) {
expect(result).to.be.true;
done();
2014-02-21 11:53:12 +00:00
});
});
});
});
});
it('should follow symbolic links and return false if for the resulting path does not exist', function(done) {
2019-02-13 19:20:14 +00:00
const fs = util.fs();
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
fs.close(fd, function(error) {
if(error) throw error;
fs.symlink('/myfile', '/myfilelink', function(error) {
if(error) throw error;
fs.unlink('/myfile', function(err) {
if(err) throw err;
fs.exists('/myfilelink', function(result) {
expect(result).to.be.false;
done();
});
});
});
});
});
});
2014-02-21 11:53:12 +00:00
});