summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-options-immutable.js
blob: 5c95213872b635b76552289f850e596d53c90a2d (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
66
67
68
69
70
71
72
73
74
75
'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();

fs.readFile(__filename, options, common.mustCall(errHandler));
fs.readFileSync(__filename, options);

fs.readdir(__dirname, options, common.mustCall(errHandler));
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);

  fs.readlink(linkFile, options, common.mustCall(errHandler));
  fs.readlinkSync(linkFile, options);
}

{
  const fileName = path.resolve(tmpdir.path, 'writeFile');
  fs.writeFileSync(fileName, 'ABCD', options);
  fs.writeFile(fileName, 'ABCD', options, common.mustCall(errHandler));
}

{
  const fileName = path.resolve(tmpdir.path, 'appendFile');
  fs.appendFileSync(fileName, 'ABCD', options);
  fs.appendFile(fileName, 'ABCD', options, common.mustCall(errHandler));
}

{
  const watch = fs.watch(__filename, options, common.mustNotCall());
  watch.close();
}

{
  fs.watchFile(__filename, options, common.mustNotCall());
  fs.unwatchFile(__filename);
}

{
  fs.realpathSync(__filename, options);
  fs.realpath(__filename, options, common.mustCall(errHandler));
}

{
  const tempFileName = path.resolve(tmpdir.path, 'mkdtemp-');
  fs.mkdtempSync(tempFileName, options);
  fs.mkdtemp(tempFileName, options, common.mustCall(errHandler));
}

{
  const fileName = path.resolve(tmpdir.path, 'streams');
  fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
    fs.ReadStream(fileName, options).destroy();
  })).end();
}