Debian Codegraph @

lib/mkdirs/__tests__/perm.test.js

raw
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 / perm', () => {
12 let TEST_DIR
13
14 beforeEach(done => {
15 TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-perm')
16 fse.emptyDir(TEST_DIR, done)
17 })
18
19 afterEach(done => fse.remove(TEST_DIR, done))
20
21 it('async perm', done => {
22 const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16))
23
24 fse.mkdirp(file, 0o755, err => {
25 assert.ifError(err)
26 fse.pathExists(file, (err, ex) => {
27 assert.ifError(err)
28 assert.ok(ex, 'file created')
29 fs.stat(file, (err, stat) => {
30 assert.ifError(err)
31
32 if (os.platform().indexOf('win') === 0) {
33 assert.strictEqual(stat.mode & 0o777, 0o666)
34 } else {
35 assert.strictEqual(stat.mode & 0o777, 0o755)
36 }
37
38 assert.ok(stat.isDirectory(), 'target not a directory')
39 done()
40 })
41 })
42 })
43 })
44
45 it('async root perm', done => {
46 fse.mkdirp(path.join(os.tmpdir(), 'tmp'), 0o755, err => {
47 assert.ifError(err)
48 done()
49 })
50 })
51 })