summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-mkdir.js
blob: ae13b9bc7a071d87895a803d814f98a98d360e85 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');

function unlink(pathname) {
  try {
    fs.rmdirSync(pathname);
  } catch (e) {
  }
}

common.refreshTmpDir();

(function() {
  var ncalls = 0;
  var pathname = common.tmpDir + '/test1';

  unlink(pathname);

  fs.mkdir(pathname, function(err) {
    assert.equal(err, null);
    assert.equal(common.fileExists(pathname), true);
    ncalls++;
  });

  process.on('exit', function() {
    unlink(pathname);
    assert.equal(ncalls, 1);
  });
})();

(function() {
  var ncalls = 0;
  var pathname = common.tmpDir + '/test2';

  unlink(pathname);

  fs.mkdir(pathname, 0o777, function(err) {
    assert.equal(err, null);
    assert.equal(common.fileExists(pathname), true);
    ncalls++;
  });

  process.on('exit', function() {
    unlink(pathname);
    assert.equal(ncalls, 1);
  });
})();

(function() {
  var pathname = common.tmpDir + '/test3';

  unlink(pathname);
  fs.mkdirSync(pathname);

  var exists = common.fileExists(pathname);
  unlink(pathname);

  assert.equal(exists, true);
})();

// Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop).
process.nextTick(function() {});