/
return_sync.test.js
39 lines (30 loc) · 1.17 KB
/
return_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
'use strict'
const os = require('os')
const fse = require('../../')
const path = require('path')
const assert = require('assert')
/* global afterEach, beforeEach, describe, it */
describe('mkdirp / return value', () => {
let TEST_DIR
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-return')
fse.emptyDir(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))
it('should', () => {
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)
const dir = TEST_DIR + path.sep
const file = dir + [x, y, z].join(path.sep)
// should return the first dir created.
// By this point, it would be profoundly surprising if /tmp didn't
// already exist, since every other test makes things in there.
// Note that this will throw on failure, which will fail the test.
let made = fse.mkdirpSync(file)
assert.strictEqual(made, dir + x)
// making the same file again should have no effect.
made = fse.mkdirpSync(file)
assert.strictEqual(made, null)
})
})