mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
b925379f50
Refs: https://github.com/nodejs/node/issues/26435 PR-URL: https://github.com/nodejs/node/pull/26980 Reviewed-By: James M Snell <jasnell@gmail.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
const tmpFolder = fs.mkdtempSync(path.join(tmpdir.path, 'foo.'));
|
|
|
|
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
|
|
assert(fs.existsSync(tmpFolder));
|
|
|
|
const utf8 = fs.mkdtempSync(path.join(tmpdir.path, '\u0222abc.'));
|
|
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
|
|
Buffer.byteLength('\u0222abc.XXXXXX'));
|
|
assert(fs.existsSync(utf8));
|
|
|
|
function handler(err, folder) {
|
|
assert.ifError(err);
|
|
assert(fs.existsSync(folder));
|
|
assert.strictEqual(this, undefined);
|
|
}
|
|
|
|
fs.mkdtemp(path.join(tmpdir.path, '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(tmpdir.path, 'bar.'), {}, common.mustCall(handler));
|
|
|
|
const warningMsg = 'mkdtemp() templates ending with X are not portable. ' +
|
|
'For details see: https://nodejs.org/api/fs.html';
|
|
common.expectWarning('Warning', warningMsg);
|
|
fs.mkdtemp(path.join(tmpdir.path, 'bar.X'), common.mustCall(handler));
|