summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-mkdtemp.js
blob: 60d1196c5a5631824f8f0ce5ae2e85efd0991714 (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
'use strict';

const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const Buffer = require('buffer').Buffer;

common.refreshTmpDir();

const tmpFolder = fs.mkdtempSync(path.join(common.tmpDir, 'foo.'));

assert(path.basename(tmpFolder).length === 'foo.XXXXXX'.length);
assert(common.fileExists(tmpFolder));

const utf8 = fs.mkdtempSync(path.join(common.tmpDir, '\u0222abc.'));
assert.equal(Buffer.byteLength(path.basename(utf8)),
             Buffer.byteLength('\u0222abc.XXXXXX'));
assert(common.fileExists(utf8));

function handler(err, folder) {
  assert.ifError(err);
  assert(common.fileExists(folder));
  assert.strictEqual(this, null);
}

fs.mkdtemp(path.join(common.tmpDir, 'bar.'), common.mustCall(handler));

// Same test as above, but making sure that passing an options object doesn't
// affect the way the callback function is handled.
fs.mkdtemp(path.join(common.tmpDir, 'bar.'), {}, common.mustCall(handler));