Skip to content

Commit 661b055

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
test: use tmpdir.resolve() in fs tests
PR-URL: #49126 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b3c56d2 commit 661b055

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+167
-207
lines changed

test/parallel/test-fs-access.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ if (common.isIBMi)
1313

1414
const assert = require('assert');
1515
const fs = require('fs');
16-
const path = require('path');
1716

1817
const { internalBinding } = require('internal/test/binding');
1918
const { UV_ENOENT } = internalBinding('uv');
2019

2120
const tmpdir = require('../common/tmpdir');
22-
const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist');
23-
const readOnlyFile = path.join(tmpdir.path, 'read_only_file');
24-
const readWriteFile = path.join(tmpdir.path, 'read_write_file');
21+
const doesNotExist = tmpdir.resolve('__this_should_not_exist');
22+
const readOnlyFile = tmpdir.resolve('read_only_file');
23+
const readWriteFile = tmpdir.resolve('read_write_file');
2524

2625
function createFileWithPerms(file, mode) {
2726
fs.writeFileSync(file, '');

test/parallel/test-fs-append-file-sync.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'use strict';
2323
const common = require('../common');
2424
const assert = require('assert');
25-
const join = require('path').join;
2625
const fs = require('fs');
2726

2827
const currentFileData = 'ABCD';
@@ -40,7 +39,7 @@ const tmpdir = require('../common/tmpdir');
4039
tmpdir.refresh();
4140

4241
// Test that empty file will be created and have content added.
43-
const filename = join(tmpdir.path, 'append-sync.txt');
42+
const filename = tmpdir.resolve('append-sync.txt');
4443

4544
fs.appendFileSync(filename, data);
4645

@@ -49,7 +48,7 @@ const fileData = fs.readFileSync(filename);
4948
assert.strictEqual(Buffer.byteLength(data), fileData.length);
5049

5150
// Test that appends data to a non empty file.
52-
const filename2 = join(tmpdir.path, 'append-sync2.txt');
51+
const filename2 = tmpdir.resolve('append-sync2.txt');
5352
fs.writeFileSync(filename2, currentFileData);
5453

5554
fs.appendFileSync(filename2, data);
@@ -60,7 +59,7 @@ assert.strictEqual(Buffer.byteLength(data) + currentFileData.length,
6059
fileData2.length);
6160

6261
// Test that appendFileSync accepts buffers.
63-
const filename3 = join(tmpdir.path, 'append-sync3.txt');
62+
const filename3 = tmpdir.resolve('append-sync3.txt');
6463
fs.writeFileSync(filename3, currentFileData);
6564

6665
const buf = Buffer.from(data, 'utf8');
@@ -70,7 +69,7 @@ const fileData3 = fs.readFileSync(filename3);
7069

7170
assert.strictEqual(buf.length + currentFileData.length, fileData3.length);
7271

73-
const filename4 = join(tmpdir.path, 'append-sync4.txt');
72+
const filename4 = tmpdir.resolve('append-sync4.txt');
7473
fs.writeFileSync(filename4, currentFileData, common.mustNotMutateObjectDeep({ mode: m }));
7574

7675
[
@@ -95,7 +94,7 @@ assert.strictEqual(Buffer.byteLength(String(num)) + currentFileData.length,
9594
fileData4.length);
9695

9796
// Test that appendFile accepts file descriptors.
98-
const filename5 = join(tmpdir.path, 'append-sync5.txt');
97+
const filename5 = tmpdir.resolve('append-sync5.txt');
9998
fs.writeFileSync(filename5, currentFileData);
10099

101100
const filename5fd = fs.openSync(filename5, 'a+', 0o600);

test/parallel/test-fs-append-file.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525
const fs = require('fs');
26-
const join = require('path').join;
2726

2827
const tmpdir = require('../common/tmpdir');
2928

@@ -43,7 +42,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
4342

4443
// Test that empty file will be created and have content added (callback API).
4544
{
46-
const filename = join(tmpdir.path, 'append.txt');
45+
const filename = tmpdir.resolve('append.txt');
4746

4847
fs.appendFile(filename, s, common.mustSucceed(() => {
4948
fs.readFile(filename, common.mustSucceed((buffer) => {
@@ -54,7 +53,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
5453

5554
// Test that empty file will be created and have content added (promise API).
5655
{
57-
const filename = join(tmpdir.path, 'append-promise.txt');
56+
const filename = tmpdir.resolve('append-promise.txt');
5857

5958
fs.promises.appendFile(filename, s)
6059
.then(common.mustCall(() => fs.promises.readFile(filename)))
@@ -66,7 +65,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
6665

6766
// Test that appends data to a non-empty file (callback API).
6867
{
69-
const filename = join(tmpdir.path, 'append-non-empty.txt');
68+
const filename = tmpdir.resolve('append-non-empty.txt');
7069
fs.writeFileSync(filename, currentFileData);
7170

7271
fs.appendFile(filename, s, common.mustSucceed(() => {
@@ -79,7 +78,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
7978

8079
// Test that appends data to a non-empty file (promise API).
8180
{
82-
const filename = join(tmpdir.path, 'append-non-empty-promise.txt');
81+
const filename = tmpdir.resolve('append-non-empty-promise.txt');
8382
fs.writeFileSync(filename, currentFileData);
8483

8584
fs.promises.appendFile(filename, s)
@@ -93,7 +92,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
9392

9493
// Test that appendFile accepts buffers (callback API).
9594
{
96-
const filename = join(tmpdir.path, 'append-buffer.txt');
95+
const filename = tmpdir.resolve('append-buffer.txt');
9796
fs.writeFileSync(filename, currentFileData);
9897

9998
const buf = Buffer.from(s, 'utf8');
@@ -107,7 +106,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
107106

108107
// Test that appendFile accepts buffers (promises API).
109108
{
110-
const filename = join(tmpdir.path, 'append-buffer-promises.txt');
109+
const filename = tmpdir.resolve('append-buffer-promises.txt');
111110
fs.writeFileSync(filename, currentFileData);
112111

113112
const buf = Buffer.from(s, 'utf8');
@@ -126,7 +125,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
126125
code: 'ERR_INVALID_ARG_TYPE',
127126
message: /"data"|"buffer"/
128127
};
129-
const filename = join(tmpdir.path, 'append-invalid-data.txt');
128+
const filename = tmpdir.resolve('append-invalid-data.txt');
130129

131130
assert.throws(
132131
() => fs.appendFile(filename, data, common.mustNotCall()),
@@ -154,7 +153,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
154153

155154
// Test that appendFile accepts file descriptors (callback API).
156155
{
157-
const filename = join(tmpdir.path, 'append-descriptors.txt');
156+
const filename = tmpdir.resolve('append-descriptors.txt');
158157
fs.writeFileSync(filename, currentFileData);
159158

160159
fs.open(filename, 'a+', common.mustSucceed((fd) => {
@@ -171,7 +170,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
171170

172171
// Test that appendFile accepts file descriptors (promises API).
173172
{
174-
const filename = join(tmpdir.path, 'append-descriptors-promises.txt');
173+
const filename = tmpdir.resolve('append-descriptors-promises.txt');
175174
fs.writeFileSync(filename, currentFileData);
176175

177176
let fd;
@@ -190,5 +189,5 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
190189
}
191190

192191
assert.throws(
193-
() => fs.appendFile(join(tmpdir.path, 'append6.txt'), console.log),
192+
() => fs.appendFile(tmpdir.resolve('append6.txt'), console.log),
194193
{ code: 'ERR_INVALID_ARG_TYPE' });

test/parallel/test-fs-assert-encoding-error.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
const common = require('../common');
33
const assert = require('node:assert');
44
const fs = require('node:fs');
5-
const path = require('node:path');
65
const tmpdir = require('../common/tmpdir');
76

8-
const testPath = path.join(tmpdir.path, 'assert-encoding-error');
7+
const testPath = tmpdir.resolve('assert-encoding-error');
98
const options = 'test';
109
const expectedError = {
1110
code: 'ERR_INVALID_ARG_VALUE',

test/parallel/test-fs-buffer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ const common = require('../common');
44
const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const fs = require('fs');
7-
const path = require('path');
87

98
const tmpdir = require('../common/tmpdir');
109
tmpdir.refresh();
1110

1211
fs.access(Buffer.from(tmpdir.path), common.mustSucceed());
1312

14-
const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
13+
const buf = Buffer.from(tmpdir.resolve('a.txt'));
1514
fs.open(buf, 'w+', common.mustSucceed((fd) => {
1615
assert(fd);
1716
fs.close(fd, common.mustSucceed());

test/parallel/test-fs-chmod-mask.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
const common = require('../common');
66
const assert = require('assert');
7-
const path = require('path');
87
const fs = require('fs');
98

109
let mode;
@@ -26,7 +25,7 @@ function test(mode, asString) {
2625
(mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
2726

2827
{
29-
const file = path.join(tmpdir.path, `chmod-async-${suffix}.txt`);
28+
const file = tmpdir.resolve(`chmod-async-${suffix}.txt`);
3029
fs.writeFileSync(file, 'test', 'utf-8');
3130

3231
fs.chmod(file, input, common.mustSucceed(() => {
@@ -35,15 +34,15 @@ function test(mode, asString) {
3534
}
3635

3736
{
38-
const file = path.join(tmpdir.path, `chmodSync-${suffix}.txt`);
37+
const file = tmpdir.resolve(`chmodSync-${suffix}.txt`);
3938
fs.writeFileSync(file, 'test', 'utf-8');
4039

4140
fs.chmodSync(file, input);
4241
assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
4342
}
4443

4544
{
46-
const file = path.join(tmpdir.path, `fchmod-async-${suffix}.txt`);
45+
const file = tmpdir.resolve(`fchmod-async-${suffix}.txt`);
4746
fs.writeFileSync(file, 'test', 'utf-8');
4847
fs.open(file, 'w', common.mustSucceed((fd) => {
4948
fs.fchmod(fd, input, common.mustSucceed(() => {
@@ -54,7 +53,7 @@ function test(mode, asString) {
5453
}
5554

5655
{
57-
const file = path.join(tmpdir.path, `fchmodSync-${suffix}.txt`);
56+
const file = tmpdir.resolve(`fchmodSync-${suffix}.txt`);
5857
fs.writeFileSync(file, 'test', 'utf-8');
5958
const fd = fs.openSync(file, 'w');
6059

@@ -65,8 +64,8 @@ function test(mode, asString) {
6564
}
6665

6766
if (fs.lchmod) {
68-
const link = path.join(tmpdir.path, `lchmod-src-${suffix}`);
69-
const file = path.join(tmpdir.path, `lchmod-dest-${suffix}`);
67+
const link = tmpdir.resolve(`lchmod-src-${suffix}`);
68+
const file = tmpdir.resolve(`lchmod-dest-${suffix}`);
7069
fs.writeFileSync(file, 'test', 'utf-8');
7170
fs.symlinkSync(file, link);
7271

@@ -76,8 +75,8 @@ function test(mode, asString) {
7675
}
7776

7877
if (fs.lchmodSync) {
79-
const link = path.join(tmpdir.path, `lchmodSync-src-${suffix}`);
80-
const file = path.join(tmpdir.path, `lchmodSync-dest-${suffix}`);
78+
const link = tmpdir.resolve(`lchmodSync-src-${suffix}`);
79+
const file = tmpdir.resolve(`lchmodSync-dest-${suffix}`);
8180
fs.writeFileSync(file, 'test', 'utf-8');
8281
fs.symlinkSync(file, link);
8382

test/parallel/test-fs-chmod.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'use strict';
2323
const common = require('../common');
2424
const assert = require('assert');
25-
const path = require('path');
2625
const fs = require('fs');
2726

2827
let mode_async;
@@ -74,8 +73,8 @@ if (common.isWindows) {
7473
const tmpdir = require('../common/tmpdir');
7574
tmpdir.refresh();
7675

77-
const file1 = path.join(tmpdir.path, 'a.js');
78-
const file2 = path.join(tmpdir.path, 'a1.js');
76+
const file1 = tmpdir.resolve('a.js');
77+
const file2 = tmpdir.resolve('a1.js');
7978

8079
// Create file1.
8180
fs.closeSync(fs.openSync(file1, 'w'));
@@ -123,7 +122,7 @@ fs.open(file2, 'w', common.mustSucceed((fd) => {
123122

124123
// lchmod
125124
if (fs.lchmod) {
126-
const link = path.join(tmpdir.path, 'symbolic-link');
125+
const link = tmpdir.resolve('symbolic-link');
127126

128127
fs.symlinkSync(file2, link);
129128

test/parallel/test-fs-copyfile-respect-permissions.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ tmpdir.refresh();
1616

1717
const assert = require('assert');
1818
const fs = require('fs');
19-
const path = require('path');
2019

2120
let n = 0;
2221

2322
function beforeEach() {
2423
n++;
25-
const source = path.join(tmpdir.path, `source${n}`);
26-
const dest = path.join(tmpdir.path, `dest${n}`);
24+
const source = tmpdir.resolve(`source${n}`);
25+
const dest = tmpdir.resolve(`dest${n}`);
2726
fs.writeFileSync(source, 'source');
2827
fs.writeFileSync(dest, 'dest');
2928
fs.chmodSync(dest, '444');

test/parallel/test-fs-copyfile.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ const {
1010
UV_ENOENT,
1111
UV_EEXIST
1212
} = internalBinding('uv');
13-
const path = require('path');
1413
const src = fixtures.path('a.js');
15-
const dest = path.join(tmpdir.path, 'copyfile.out');
14+
const dest = tmpdir.resolve('copyfile.out');
1615
const {
1716
COPYFILE_EXCL,
1817
COPYFILE_FICLONE,

test/parallel/test-fs-cp.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tmpdir.refresh();
2525

2626
let dirc = 0;
2727
function nextdir() {
28-
return join(tmpdir.path, `copy_${++dirc}`);
28+
return tmpdir.resolve(`copy_${++dirc}`);
2929
}
3030

3131
// Synchronous implementation of copy.

test/parallel/test-fs-error-messages.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ const fixtures = require('../common/fixtures');
2626
const tmpdir = require('../common/tmpdir');
2727
const assert = require('assert');
2828
const fs = require('fs');
29-
const path = require('path');
3029

3130
tmpdir.refresh();
3231

3332

34-
const nonexistentFile = path.join(tmpdir.path, 'non-existent');
35-
const nonexistentDir = path.join(tmpdir.path, 'non-existent', 'foo', 'bar');
36-
const existingFile = path.join(tmpdir.path, 'existingFile.js');
37-
const existingFile2 = path.join(tmpdir.path, 'existingFile2.js');
38-
const existingDir = path.join(tmpdir.path, 'dir');
33+
const nonexistentFile = tmpdir.resolve('non-existent');
34+
const nonexistentDir = tmpdir.resolve('non-existent', 'foo', 'bar');
35+
const existingFile = tmpdir.resolve('existingFile.js');
36+
const existingFile2 = tmpdir.resolve('existingFile2.js');
37+
const existingDir = tmpdir.resolve('dir');
3938
const existingDir2 = fixtures.path('keys');
4039
fs.mkdirSync(existingDir);
4140
fs.writeFileSync(existingFile, 'test', 'utf-8');
@@ -297,7 +296,7 @@ function re(literals, ...values) {
297296
return true;
298297
};
299298

300-
const destFile = path.join(tmpdir.path, 'foo');
299+
const destFile = tmpdir.resolve('foo');
301300
fs.rename(nonexistentFile, destFile, common.mustCall(validateError));
302301

303302
assert.throws(

test/parallel/test-fs-fmap.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require('../common');
33
const assert = require('assert');
44
const fs = require('fs');
5-
const join = require('path').join;
65

76
const {
87
O_CREAT = 0,
@@ -18,7 +17,7 @@ tmpdir.refresh();
1817
// Run this test on all platforms. While UV_FS_O_FILEMAP is only available on
1918
// Windows, it should be silently ignored on other platforms.
2019

21-
const filename = join(tmpdir.path, 'fmap.txt');
20+
const filename = tmpdir.resolve('fmap.txt');
2221
const text = 'Memory File Mapping Test';
2322

2423
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;

test/parallel/test-fs-fsync.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ const fixtures = require('../common/fixtures');
2626
const tmpdir = require('../common/tmpdir');
2727

2828
const fs = require('fs');
29-
const path = require('path');
3029

3130
const fileFixture = fixtures.path('a.js');
32-
const fileTemp = path.join(tmpdir.path, 'a.js');
31+
const fileTemp = tmpdir.resolve('a.js');
3332

3433
// Copy fixtures to temp.
3534
tmpdir.refresh();

test/parallel/test-fs-lchown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const { promises } = fs;
5151
});
5252

5353
if (!common.isWindows) {
54-
const testFile = path.join(tmpdir.path, path.basename(__filename));
54+
const testFile = tmpdir.resolve(path.basename(__filename));
5555
const uid = process.geteuid();
5656
const gid = process.getegid();
5757

0 commit comments

Comments
 (0)