Debian Codegraph @

lib/mkdirs/__tests__/mkdirp.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 / mkdirp', () => {
12 let TEST_DIR
13
14 beforeEach(done => {
15 TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp')
16 fse.emptyDir(TEST_DIR, done)
17 })
18
19 afterEach(done => fse.remove(TEST_DIR, done))
20
21 it('should make the dir', done => {
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 const file = path.join(TEST_DIR, x, y, z)
27
28 fse.mkdirp(file, 0o755, err => {
29 assert.ifError(err)
30 fse.pathExists(file, (err, ex) => {
31 assert.ifError(err)
32 assert.ok(ex, 'file created')
33 fs.stat(file, (err, stat) => {
34 assert.ifError(err)
35
36 if (os.platform().indexOf('win') === 0) {
37 assert.strictEqual(stat.mode & 0o777, 0o666)
38 } else {
39 assert.strictEqual(stat.mode & 0o777, 0o755)
40 }
41
42 assert.ok(stat.isDirectory(), 'target not a directory')
43 done()
44 })
45 })
46 })
47 })
48 })