PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/mkdirp/test/rel.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 32 lines | 28 code | 4 blank | 0 comment | 1 complexity | ee4926533441d5574469ed8afc9b2d21 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('rel', function (t) {
10    t.plan(5);
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 cwd = process.cwd();
16    process.chdir('/tmp');
17    
18    var file = [x,y,z].join('/');
19    
20    mkdirp(file, _0755, function (err) {
21        t.ifError(err);
22        exists(file, function (ex) {
23            t.ok(ex, 'file created');
24            fs.stat(file, function (err, stat) {
25                t.ifError(err);
26                process.chdir(cwd);
27                t.equal(stat.mode & _0777, _0755);
28                t.ok(stat.isDirectory(), 'target not a directory');
29            })
30        })
31    });
32});