Debian Codegraph @

lib/mkdirs/__tests__/perm_sync.test.js

raw
1 'use strict'
2
3 const fs = require('fs')
4 const os = require('os')
5 const fse = require(process.cwd())
6 const path = require('path')
7 const assert = require('assert')
8
9 /* global afterEach, beforeEach, describe, it */
10
11 describe('mkdirp / perm_sync', () => {
12 let TEST_DIR
13
14 beforeEach(done => {
15 TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-perm-sync')
16 fse.emptyDir(TEST_DIR, done)
17 })
18
19 afterEach(done => fse.remove(TEST_DIR, done))
20
21 it('sync perm', done => {
22 const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16) + '.json')
23
24 fse.mkdirpSync(file, 0o755)
25 fse.pathExists(file, (err, ex) => {
26 assert.ifError(err)
27 assert.ok(ex, 'file created')
28 fs.stat(file, (err, stat) => {
29 assert.ifError(err)
30
31 if (os.platform().indexOf('win') === 0) {
32 assert.strictEqual(stat.mode & 0o777, 0o666)
33 } else {
34 assert.strictEqual(stat.mode & 0o777, 0o755)
35 }
36
37 assert.ok(stat.isDirectory(), 'target not a directory')
38 done()
39 })
40 })
41 })
42
43 it('sync root perm', done => {
44 const file = TEST_DIR
45 fse.mkdirpSync(file, 0o755)
46 fse.pathExists(file, (err, ex) => {
47 assert.ifError(err)
48 assert.ok(ex, 'file created')
49 fs.stat(file, (err, stat) => {
50 assert.ifError(err)
51 assert.ok(stat.isDirectory(), 'target not a directory')
52 done()
53 })
54 })
55 })
56 })