| 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 before, describe, it */ |
| 10 |
|
| 11 |
describe('mkdirp / clobber', () => { |
| 12 |
let TEST_DIR |
| 13 |
let file |
| 14 |
|
| 15 |
before(done => { |
| 16 |
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-clobber') |
| 17 |
fse.emptyDir(TEST_DIR, err => { |
| 18 |
assert.ifError(err) |
| 19 |
|
| 20 |
const ps = [TEST_DIR] |
| 21 |
|
| 22 |
for (let i = 0; i < 15; i++) { |
| 23 |
const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16) |
| 24 |
ps.push(dir) |
| 25 |
} |
| 26 |
|
| 27 |
file = ps.join(path.sep) |
| 28 |
|
| 29 |
// a file in the way |
| 30 |
const itw = ps.slice(0, 2).join(path.sep) |
| 31 |
|
| 32 |
fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.') |
| 33 |
|
| 34 |
fs.stat(itw, (err, stat) => { |
| 35 |
assert.ifError(err) |
| 36 |
assert.ok(stat && stat.isFile(), 'should be file') |
| 37 |
done() |
| 38 |
}) |
| 39 |
}) |
| 40 |
}) |
| 41 |
|
| 42 |
it('should clobber', done => { |
| 43 |
fse.mkdirp(file, 0o755, err => { |
| 44 |
assert.ok(err) |
| 45 |
assert.strictEqual(err.code, 'ENOTDIR') |
| 46 |
done() |
| 47 |
}) |
| 48 |
}) |
| 49 |
}) |