/
sync.test.js
56 lines (45 loc) · 1.4 KB
/
sync.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const fs = require('fs')
const os = require('os')
const fse = require('../..')
const path = require('path')
const assert = require('assert')
/* global afterEach, beforeEach, describe, it */
describe('mkdirp / sync', () => {
let TEST_DIR
let file
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-sync')
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
file = path.join(TEST_DIR, x, y, z)
done()
})
})
afterEach(done => fse.remove(TEST_DIR, done))
it('should', done => {
try {
fse.mkdirpSync(file, 0o755)
} catch (err) {
assert.fail(err)
}
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
assert.ok(ex, 'file created')
fs.stat(file, (err, stat) => {
assert.ifError(err)
// http://stackoverflow.com/questions/592448/c-how-to-set-file-permissions-cross-platform
if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & 0o777, 0o755)
}
assert.ok(stat.isDirectory(), 'target not a directory')
done()
})
})
})
})