• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const fs = require('fs');
6const path = require('path');
7
8const tmpdir = require('../common/tmpdir');
9tmpdir.refresh();
10
11const tmpFolder = fs.mkdtempSync(path.join(tmpdir.path, 'foo.'));
12
13assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
14assert(fs.existsSync(tmpFolder));
15
16const utf8 = fs.mkdtempSync(path.join(tmpdir.path, '\u0222abc.'));
17assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
18                   Buffer.byteLength('\u0222abc.XXXXXX'));
19assert(fs.existsSync(utf8));
20
21function handler(err, folder) {
22  assert.ifError(err);
23  assert(fs.existsSync(folder));
24  assert.strictEqual(this, undefined);
25}
26
27fs.mkdtemp(path.join(tmpdir.path, 'bar.'), common.mustCall(handler));
28
29// Same test as above, but making sure that passing an options object doesn't
30// affect the way the callback function is handled.
31fs.mkdtemp(path.join(tmpdir.path, 'bar.'), {}, common.mustCall(handler));
32
33const warningMsg = 'mkdtemp() templates ending with X are not portable. ' +
34                   'For details see: https://nodejs.org/api/fs.html';
35common.expectWarning('Warning', warningMsg);
36fs.mkdtemp(path.join(tmpdir.path, 'bar.X'), common.mustCall(handler));
37