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
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
describe('fs.mkdir', function () {
|
2014-05-23 20:53:50 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
it('should be a function', function () {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.mkdir).to.be.a('function');
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
it('should return an error if part of the parent path does not exist', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
fs.mkdir('/tmp/mydir', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).to.exist;
|
2018-07-15 17:25:35 +00:00
|
|
|
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
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
it('should return an error if the path already exists', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
fs.mkdir('/', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).to.exist;
|
2018-07-15 17:25:35 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
it('should make a new directory', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
fs.mkdir('/tmp', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).not.to.exist;
|
2018-10-16 23:27:12 +00:00
|
|
|
if (error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
fs.stat('/tmp', function (error, stats) {
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(error).not.to.exist;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(stats).to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(stats.isDirectory()).to.be.true;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-16 23:27:12 +00:00
|
|
|
});
|
2018-10-09 21:28:14 +00:00
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
describe('fs.promises.mkdir', function () {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should be a function', function () {
|
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.promises.mkdir).to.be.a('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error if part of the parent path does not exist', function () {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
return fs.promises.mkdir('/tmp/mydir')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error if the path already exists', function () {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
return fs.promises.mkdir('/')
|
|
|
|
.catch(error =>{
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('EEXIST');
|
|
|
|
});
|
2018-10-09 21:28:14 +00:00
|
|
|
});
|
|
|
|
|
2018-10-16 23:27:12 +00:00
|
|
|
it('should make a new directory', function () {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
return fs.promises.mkdir('/tmp')
|
|
|
|
.then(() => fs.promises.stat('/tmp'))
|
|
|
|
.then(stats => {
|
|
|
|
expect(stats).to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(stats.isDirectory()).to.be.true;
|
2018-10-16 23:27:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a promise', function () {
|
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.promises.mkdir('/tmp')).to.be.a('promise');
|
|
|
|
});
|
2018-10-09 21:28:14 +00:00
|
|
|
});
|