PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/mkdirp/test/sync.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 32 lines | 28 code | 4 blank | 0 comment | 1 complexity | 0ce9d0bf0203775fd4073b4d436920b5 MD5 | raw file
 1var mkdirp = require('../');
 2var path = require('path');
 3var fs = require('fs');
 4var exists = fs.exists || path.exists;
 5var test = require('tap').test;
 6var _0777 = parseInt('0777', 8);
 7var _0755 = parseInt('0755', 8);
 8
 9test('sync', function (t) {
10    t.plan(4);
11    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
12    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
13    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
14
15    var file = '/tmp/' + [x,y,z].join('/');
16
17    try {
18        mkdirp.sync(file, _0755);
19    } catch (err) {
20        t.fail(err);
21        return t.end();
22    }
23
24    exists(file, function (ex) {
25        t.ok(ex, 'file created');
26        fs.stat(file, function (err, stat) {
27            t.ifError(err);
28            t.equal(stat.mode & _0777, _0755);
29            t.ok(stat.isDirectory(), 'target not a directory');
30        });
31    });
32});