mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 00:20:38 +01:00
Move tmpdir functionality to its own module (common/tmpdir). Backport-PR-URL: https://github.com/nodejs/node/pull/19488 PR-URL: https://github.com/nodejs/node/pull/17856 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
101 lines
2.5 KiB
JavaScript
101 lines
2.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
/*
|
|
* These tests make sure that the `options` object passed to these functions are
|
|
* never altered.
|
|
*
|
|
* Refer: https://github.com/nodejs/node/issues/7655
|
|
*/
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const errHandler = (e) => assert.ifError(e);
|
|
const options = Object.freeze({});
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
{
|
|
assert.doesNotThrow(() =>
|
|
fs.readFile(__filename, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readFileSync(__filename, options));
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(() =>
|
|
fs.readdir(__dirname, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readdirSync(__dirname, options));
|
|
}
|
|
|
|
if (common.canCreateSymLink()) {
|
|
const sourceFile = path.resolve(tmpdir.path, 'test-readlink');
|
|
const linkFile = path.resolve(tmpdir.path, 'test-readlink-link');
|
|
|
|
fs.writeFileSync(sourceFile, '');
|
|
fs.symlinkSync(sourceFile, linkFile);
|
|
|
|
assert.doesNotThrow(() =>
|
|
fs.readlink(linkFile, options, common.mustCall(errHandler))
|
|
);
|
|
assert.doesNotThrow(() => fs.readlinkSync(linkFile, options));
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(tmpdir.path, 'writeFile');
|
|
assert.doesNotThrow(() => fs.writeFileSync(fileName, 'ABCD', options));
|
|
assert.doesNotThrow(() =>
|
|
fs.writeFile(fileName, 'ABCD', options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(tmpdir.path, 'appendFile');
|
|
assert.doesNotThrow(() => fs.appendFileSync(fileName, 'ABCD', options));
|
|
assert.doesNotThrow(() =>
|
|
fs.appendFile(fileName, 'ABCD', options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
let watch;
|
|
assert.doesNotThrow(() => {
|
|
watch = fs.watch(__filename, options, common.mustNotCall());
|
|
});
|
|
watch.close();
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(
|
|
() => fs.watchFile(__filename, options, common.mustNotCall())
|
|
);
|
|
fs.unwatchFile(__filename);
|
|
}
|
|
|
|
{
|
|
assert.doesNotThrow(() => fs.realpathSync(__filename, options));
|
|
assert.doesNotThrow(() =>
|
|
fs.realpath(__filename, options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const tempFileName = path.resolve(tmpdir.path, 'mkdtemp-');
|
|
assert.doesNotThrow(() => fs.mkdtempSync(tempFileName, options));
|
|
assert.doesNotThrow(() =>
|
|
fs.mkdtemp(tempFileName, options, common.mustCall(errHandler))
|
|
);
|
|
}
|
|
|
|
{
|
|
const fileName = path.resolve(tmpdir.path, 'streams');
|
|
assert.doesNotThrow(() => {
|
|
fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
|
|
assert.doesNotThrow(() => fs.ReadStream(fileName, options));
|
|
}));
|
|
});
|
|
}
|