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

/node_modules/mkdirp/test/clobber.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 38 lines | 29 code | 8 blank | 1 comment | 2 complexity | b58e37e5922e9d03cd4b4e383ec8acd2 MD5 | raw file
 1var mkdirp = require('../').mkdirp;
 2var path = require('path');
 3var fs = require('fs');
 4var test = require('tap').test;
 5var _0755 = parseInt('0755', 8);
 6
 7var ps = [ '', 'tmp' ];
 8
 9for (var i = 0; i < 25; i++) {
10    var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
11    ps.push(dir);
12}
13
14var file = ps.join('/');
15
16// a file in the way
17var itw = ps.slice(0, 3).join('/');
18
19
20test('clobber-pre', function (t) {
21    console.error("about to write to "+itw)
22    fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.');
23
24    fs.stat(itw, function (er, stat) {
25        t.ifError(er)
26        t.ok(stat && stat.isFile(), 'should be file')
27        t.end()
28    })
29})
30
31test('clobber', function (t) {
32    t.plan(2);
33    mkdirp(file, _0755, function (err) {
34        t.ok(err);
35        t.equal(err.code, 'ENOTDIR');
36        t.end();
37    });
38});