filer/tests/spec/fs.mkdir.spec.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-05-23 20:53:50 +00:00
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
describe('fs.mkdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should be a function', function() {
var fs = util.fs();
expect(fs.mkdir).to.be.a('function');
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if part of the parent path does not exist', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if the path already exists', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EEXIST');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
2014-05-23 20:53:50 +00:00
});
it('should make a new directory', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.stat('/tmp', function(error, stats) {
expect(error).not.to.exist;
2014-05-23 20:53:50 +00:00
expect(stats).to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
2013-11-27 17:18:09 +00:00
});
});
});
it('should error if {recursive:true} is not specified on a deep path', function(done) {
var fs = util.fs();
fs.mkdir('/tmp/deep/path', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
done();
});
});
it('should error if only a mode is specified on a deep path (should default to recursive:false)', function(done) {
var fs = util.fs();
fs.mkdir('/tmp/deep/path', 0o777, function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
done();
});
});
it('should create all paths if {recursive:true} is specified on a deep path', function(done) {
var fs = util.fs();
fs.mkdir('/tmp/deep/path', {recursive:true}, function(error) {
expect(error).not.to.exist;
if(error) throw error;
fs.stat('/tmp/deep/path', function(error, stats) {
expect(error).not.to.exist;
expect(stats).to.exist;
expect(stats.type).to.equal('DIRECTORY');
done();
});
});
});
2014-05-23 20:53:50 +00:00
});