forked from ahmadnassri/mkdirp-promise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·36 lines (25 loc) · 1.04 KB
/
index.js
File metadata and controls
executable file
·36 lines (25 loc) · 1.04 KB
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
'use strict'
const mkdir = require('mkdirp')
const mkdirp = require('../lib/index')
const path = require('path')
const rimraf = require('rimraf')
const tap = require('tap')
const base = path.join('test', 'tmp')
tap.beforeEach(done => mkdir(base, done))
tap.afterEach(done => rimraf(base, done))
tap.test('should successfully create a directory tree', assert => {
assert.plan(1)
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 file = path.join(base, path.join.apply(null, [x, y, z]))
return mkdirp(file).then(made => assert.equal(made, path.resolve(path.join(base, x))))
})
tap.test('should catch thrown errors', assert => {
assert.plan(1)
return mkdirp(true).catch(err => assert.match(err, /^TypeError/))
})
tap.test('should catch errors', assert => {
assert.plan(1)
return mkdirp(path.join('test', 'index.js', 'foo')).catch((err) => assert.equal(err.code, 'ENOTDIR'))
})