| 1 |
'use strict' |
| 2 |
|
| 3 |
const fs = require('fs') |
| 4 |
const os = require('os') |
| 5 |
const fse = require('../../') |
| 6 |
const path = require('path') |
| 7 |
const assert = require('assert') |
| 8 |
|
| 9 |
/* global afterEach, beforeEach, describe, it */ |
| 10 |
|
| 11 |
describe('mkdirp / chmod', () => { |
| 12 |
let TEST_DIR |
| 13 |
let TEST_SUBDIR |
| 14 |
|
| 15 |
beforeEach(done => { |
| 16 |
const ps = [] |
| 17 |
for (let i = 0; i < 15; i++) { |
| 18 |
const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16) |
| 19 |
ps.push(dir) |
| 20 |
} |
| 21 |
|
| 22 |
TEST_SUBDIR = ps.join(path.sep) |
| 23 |
|
| 24 |
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-chmod') |
| 25 |
TEST_SUBDIR = path.join(TEST_DIR, TEST_SUBDIR) |
| 26 |
|
| 27 |
fse.emptyDir(TEST_DIR, done) |
| 28 |
}) |
| 29 |
|
| 30 |
afterEach(done => fse.remove(TEST_DIR, done)) |
| 31 |
|
| 32 |
it('chmod-pre', done => { |
| 33 |
const mode = 0o744 |
| 34 |
fse.mkdirp(TEST_SUBDIR, mode, err => { |
| 35 |
assert.ifError(err, 'should not error') |
| 36 |
fs.stat(TEST_SUBDIR, (err, stat) => { |
| 37 |
assert.ifError(err, 'should exist') |
| 38 |
assert.ok(stat && stat.isDirectory(), 'should be directory') |
| 39 |
|
| 40 |
if (os.platform().indexOf('win') === 0) { |
| 41 |
assert.strictEqual(stat && stat.mode & 0o777, 0o666, 'windows shit') |
| 42 |
} else { |
| 43 |
assert.strictEqual(stat && stat.mode & 0o777, mode, 'should be 0744') |
| 44 |
} |
| 45 |
|
| 46 |
done() |
| 47 |
}) |
| 48 |
}) |
| 49 |
}) |
| 50 |
|
| 51 |
it('chmod', done => { |
| 52 |
const mode = 0o755 |
| 53 |
fse.mkdirp(TEST_SUBDIR, mode, err => { |
| 54 |
assert.ifError(err, 'should not error') |
| 55 |
fs.stat(TEST_SUBDIR, (err, stat) => { |
| 56 |
assert.ifError(err, 'should exist') |
| 57 |
assert.ok(stat && stat.isDirectory(), 'should be directory') |
| 58 |
done() |
| 59 |
}) |
| 60 |
}) |
| 61 |
}) |
| 62 |
}) |