Debian Codegraph @

lib/mkdirs/__tests__/rel.test.js

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