| 1 |
'use strict' |
| 2 |
|
| 3 |
const os = require('os') |
| 4 |
const fse = require(process.cwd()) |
| 5 |
const path = require('path') |
| 6 |
const assert = require('assert') |
| 7 |
const util = require('util') |
| 8 |
|
| 9 |
/* global before, describe, it */ |
| 10 |
|
| 11 |
describe('mkdirp: issue-93, win32, when drive does not exist, it should return a cleaner error', () => { |
| 12 |
let TEST_DIR |
| 13 |
|
| 14 |
// only seems to be an issue on Windows. |
| 15 |
if (process.platform !== 'win32') return |
| 16 |
|
| 17 |
before(done => { |
| 18 |
TEST_DIR = path.join(os.tmpdir(), 'tests', 'fs-extra', 'mkdirp-issue-93') |
| 19 |
fse.emptyDir(TEST_DIR, err => { |
| 20 |
assert.ifError(err) |
| 21 |
done() |
| 22 |
}) |
| 23 |
}) |
| 24 |
|
| 25 |
it('should return a cleaner error than inifinite loop, stack crash', done => { |
| 26 |
const file = 'R:\\afasd\\afaff\\fdfd' // hopefully drive 'r' does not exist on appveyor |
| 27 |
// Different error codes on different Node versions (matches native mkdir behavior) |
| 28 |
const assertErr = (err) => assert( |
| 29 |
['EPERM', 'ENOENT'].includes(err.code), |
| 30 |
`expected 'EPERM' or 'ENOENT', got ${util.inspect(err.code)}` |
| 31 |
) |
| 32 |
|
| 33 |
fse.mkdirp(file, err => { |
| 34 |
assertErr(err) |
| 35 |
|
| 36 |
try { |
| 37 |
fse.mkdirsSync(file) |
| 38 |
} catch (err) { |
| 39 |
assertErr(err) |
| 40 |
} |
| 41 |
|
| 42 |
done() |
| 43 |
}) |
| 44 |
}) |
| 45 |
}) |