/
clobber.test.js
49 lines (38 loc) · 1.07 KB
/
clobber.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
40
41
42
43
44
45
46
47
48
49
'use strict'
const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')
/* global before, describe, it */
describe('mkdirp / clobber', () => {
let TEST_DIR
let file
before(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-clobber')
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
const ps = [TEST_DIR]
for (let i = 0; i < 15; i++) {
const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
ps.push(dir)
}
file = ps.join(path.sep)
// a file in the way
const itw = ps.slice(0, 2).join(path.sep)
fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.')
fs.stat(itw, (err, stat) => {
assert.ifError(err)
assert.ok(stat && stat.isFile(), 'should be file')
done()
})
})
})
it('should clobber', done => {
fse.mkdirp(file, 0o755, err => {
assert.ok(err)
assert.strictEqual(err.code, 'ENOTDIR')
done()
})
})
})