Skip to content

Commit b3c56d2

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
test: use tmpdir.resolve() in fs tests
PR-URL: #49125 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 4439327 commit b3c56d2

File tree

58 files changed

+95
-155
lines changed

Some content is hidden

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

58 files changed

+95
-155
lines changed

test/parallel/test-fs-promises-file-handle-aggregate-errors.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
77
// The following tests validate aggregate errors are thrown correctly
88
// when both an operation and close throw.
99

10-
const path = require('path');
1110
const {
1211
readFile,
1312
writeFile,
@@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');
2322

2423
let count = 0;
2524
async function createFile() {
26-
const filePath = path.join(tmpdir.path, `aggregate_errors_${++count}.txt`);
25+
const filePath = tmpdir.resolve(`aggregate_errors_${++count}.txt`);
2726
await writeFile(filePath, 'content');
2827
return filePath;
2928
}

test/parallel/test-fs-promises-file-handle-close-errors.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
77
// The following tests validate aggregate errors are thrown correctly
88
// when both an operation and close throw.
99

10-
const path = require('path');
1110
const {
1211
readFile,
1312
writeFile,
@@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');
2322

2423
let count = 0;
2524
async function createFile() {
26-
const filePath = path.join(tmpdir.path, `close_errors_${++count}.txt`);
25+
const filePath = tmpdir.resolve(`close_errors_${++count}.txt`);
2726
await writeFile(filePath, 'content');
2827
return filePath;
2928
}

test/parallel/test-fs-promises-file-handle-op-errors.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
77
// The following tests validate aggregate errors are thrown correctly
88
// when both an operation and close throw.
99

10-
const path = require('path');
1110
const {
1211
readFile,
1312
writeFile,
@@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');
2322

2423
let count = 0;
2524
async function createFile() {
26-
const filePath = path.join(tmpdir.path, `op_errors_${++count}.txt`);
25+
const filePath = tmpdir.resolve(`op_errors_${++count}.txt`);
2726
await writeFile(filePath, 'content');
2827
return filePath;
2928
}

test/parallel/test-fs-promises-file-handle-read-worker.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
const common = require('../common');
33
const fs = require('fs');
44
const assert = require('assert');
5-
const path = require('path');
65
const tmpdir = require('../common/tmpdir');
7-
const file = path.join(tmpdir.path, 'read_stream_filehandle_worker.txt');
6+
const file = tmpdir.resolve('read_stream_filehandle_worker.txt');
87
const input = 'hello world';
98
const { Worker, isMainThread, workerData } = require('worker_threads');
109

test/parallel/test-fs-promises-file-handle-readLines.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import tmpdir from '../common/tmpdir.js';
33

44
import assert from 'node:assert';
55
import { open, writeFile } from 'node:fs/promises';
6-
import path from 'node:path';
76

87
tmpdir.refresh();
98

10-
const filePath = path.join(tmpdir.path, 'file.txt');
9+
const filePath = tmpdir.resolve('file.txt');
1110

1211
await writeFile(filePath, '1\n\n2\n');
1312

test/parallel/test-fs-promises-file-handle-stat.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ const common = require('../common');
66
// FileHandle.stat method.
77

88
const { open } = require('fs').promises;
9-
const path = require('path');
109
const tmpdir = require('../common/tmpdir');
1110
const assert = require('assert');
1211

1312
tmpdir.refresh();
1413

1514
async function validateStat() {
16-
const filePath = path.resolve(tmpdir.path, 'tmp-read-file.txt');
15+
const filePath = tmpdir.resolve('tmp-read-file.txt');
1716
const fileHandle = await open(filePath, 'w+');
1817
const stats = await fileHandle.stat();
1918
assert.ok(stats.mtime instanceof Date);

test/parallel/test-fs-promises-file-handle-sync.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ const fixtures = require('../common/fixtures');
55
const tmpdir = require('../common/tmpdir');
66

77
const { access, copyFile, open } = require('fs').promises;
8-
const path = require('path');
98

109
async function validate() {
1110
tmpdir.refresh();
12-
const dest = path.resolve(tmpdir.path, 'baz.js');
11+
const dest = tmpdir.resolve('baz.js');
1312
await assert.rejects(
1413
copyFile(fixtures.path('baz.js'), dest, 'r'),
1514
{

test/parallel/test-fs-promises-file-handle-truncate.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const path = require('path');
65
const { open, readFile } = require('fs').promises;
76
const tmpdir = require('../common/tmpdir');
87

98
tmpdir.refresh();
109

1110
async function validateTruncate() {
1211
const text = 'Hello world';
13-
const filename = path.resolve(tmpdir.path, 'truncate-file.txt');
12+
const filename = tmpdir.resolve('truncate-file.txt');
1413
const fileHandle = await open(filename, 'w+');
1514

1615
const buffer = Buffer.from(text, 'utf8');

test/parallel/test-fs-promises-readfile-with-fd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
const common = require('../common');
77
const assert = require('assert');
8-
const path = require('path');
98
const { writeFileSync } = require('fs');
109
const { open } = require('fs').promises;
1110

1211
const tmpdir = require('../common/tmpdir');
1312
tmpdir.refresh();
1413

15-
const fn = path.join(tmpdir.path, 'test.txt');
14+
const fn = tmpdir.resolve('test.txt');
1615
writeFileSync(fn, 'Hello World');
1716

1817
async function readFileTest() {

test/parallel/test-fs-promises-readfile.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
const common = require('../common');
55

66
const assert = require('assert');
7-
const path = require('path');
87
const { writeFile, readFile } = require('fs').promises;
98
const tmpdir = require('../common/tmpdir');
109
const { internalBinding } = require('internal/test/binding');
1110
const fsBinding = internalBinding('fs');
1211
tmpdir.refresh();
1312

14-
const fn = path.join(tmpdir.path, 'large-file');
13+
const fn = tmpdir.resolve('large-file');
1514

1615
// Creating large buffer with random content
1716
const largeBuffer = Buffer.from(

test/parallel/test-fs-promises-watch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WatchTestCase {
1717
this.field = field;
1818
this.shouldSkip = !shouldInclude;
1919
}
20-
get dirPath() { return join(tmpdir.path, this.dirName); }
20+
get dirPath() { return tmpdir.resolve(this.dirName); }
2121
get filePath() { return join(this.dirPath, this.fileName); }
2222
}
2323

test/parallel/test-fs-promises-write-optional-params.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ const common = require('../common');
77

88
const assert = require('assert');
99
const fsPromises = require('fs').promises;
10-
const path = require('path');
1110
const tmpdir = require('../common/tmpdir');
1211

1312
tmpdir.refresh();
1413

15-
const dest = path.resolve(tmpdir.path, 'tmp.txt');
14+
const dest = tmpdir.resolve('tmp.txt');
1615
const buffer = Buffer.from('zyx');
1716

1817
async function testInvalid(dest, expectedCode, ...params) {

test/parallel/test-fs-promises-writefile-with-fd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
const common = require('../common');
77
const assert = require('assert');
8-
const path = require('path');
98
const { readFileSync } = require('fs');
109
const { open } = require('fs').promises;
1110

1211
const tmpdir = require('../common/tmpdir');
1312
tmpdir.refresh();
1413

15-
const fn = path.join(tmpdir.path, 'test.txt');
14+
const fn = tmpdir.resolve('test.txt');
1615

1716
async function writeFileTest() {
1817
const handle = await open(fn, 'w');

test/parallel/test-fs-read-stream-autoClose.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
const common = require('../common');
44
const fs = require('fs');
5-
const path = require('path');
65
const assert = require('assert');
76
const tmpdir = require('../common/tmpdir');
8-
const writeFile = path.join(tmpdir.path, 'write-autoClose.txt');
7+
const writeFile = tmpdir.resolve('write-autoClose.txt');
98
tmpdir.refresh();
109

1110
const file = fs.createWriteStream(writeFile, { autoClose: true });

test/parallel/test-fs-read-stream-fd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
const common = require('../common');
2424
const fs = require('fs');
2525
const assert = require('assert');
26-
const path = require('path');
2726
const tmpdir = require('../common/tmpdir');
28-
const file = path.join(tmpdir.path, '/read_stream_fd_test.txt');
27+
const file = tmpdir.resolve('read_stream_fd_test.txt');
2928
const input = 'hello world';
3029

3130
let output = '';

test/parallel/test-fs-read-stream-file-handle.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
const common = require('../common');
33
const fs = require('fs');
44
const assert = require('assert');
5-
const path = require('path');
65
const tmpdir = require('../common/tmpdir');
7-
const file = path.join(tmpdir.path, 'read_stream_filehandle_test.txt');
6+
const file = tmpdir.resolve('read_stream_filehandle_test.txt');
87
const input = 'hello world';
98

109
tmpdir.refresh();

test/parallel/test-fs-read-stream-pos.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ const common = require('../common');
66
const tmpdir = require('../common/tmpdir');
77
const fs = require('fs');
88
const assert = require('assert');
9-
const path = require('path');
109

1110
tmpdir.refresh();
1211

13-
const file = path.join(tmpdir.path, '/read_stream_pos_test.txt');
12+
const file = tmpdir.resolve('read_stream_pos_test.txt');
1413

1514
fs.writeFileSync(file, '');
1615

test/parallel/test-fs-readfile-fd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const fixtures = require('../common/fixtures');
77
const assert = require('assert');
88
const fs = require('fs');
99
const fn = fixtures.path('empty.txt');
10-
const join = require('path').join;
1110
const tmpdir = require('../common/tmpdir');
1211
tmpdir.refresh();
1312

@@ -55,7 +54,7 @@ function tempFdSync(callback) {
5554
// position of the file, instead of reading from the beginning of the file,
5655
// when used with file descriptors.
5756

58-
const filename = join(tmpdir.path, 'test.txt');
57+
const filename = tmpdir.resolve('test.txt');
5958
fs.writeFileSync(filename, 'Hello World');
6059

6160
{

test/parallel/test-fs-readfile-flags.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
const common = require('../common');
55
const fs = require('fs');
66
const assert = require('assert');
7-
const path = require('path');
87
const tmpdir = require('../common/tmpdir');
98

109
tmpdir.refresh();
1110

1211
{
13-
const emptyFile = path.join(tmpdir.path, 'empty.txt');
12+
const emptyFile = tmpdir.resolve('empty.txt');
1413
fs.closeSync(fs.openSync(emptyFile, 'w'));
1514

1615
fs.readFile(
@@ -29,7 +28,7 @@ tmpdir.refresh();
2928
}
3029

3130
{
32-
const willBeCreated = path.join(tmpdir.path, 'will-be-created');
31+
const willBeCreated = tmpdir.resolve('will-be-created');
3332

3433
fs.readFile(
3534
willBeCreated,
@@ -40,7 +39,7 @@ tmpdir.refresh();
4039
}
4140

4241
{
43-
const willNotBeCreated = path.join(tmpdir.path, 'will-not-be-created');
42+
const willNotBeCreated = tmpdir.resolve('will-not-be-created');
4443

4544
fs.readFile(
4645
willNotBeCreated,

test/parallel/test-fs-readfile-pipe-large.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (common.isWindows || common.isAIX)
77
common.skip(`No /dev/stdin on ${process.platform}.`);
88

99
const assert = require('assert');
10-
const path = require('path');
1110
const fs = require('fs');
1211

1312
if (process.argv[2] === 'child') {
@@ -20,7 +19,7 @@ if (process.argv[2] === 'child') {
2019

2120
const tmpdir = require('../common/tmpdir');
2221

23-
const filename = path.join(tmpdir.path, '/readfile_pipe_large_test.txt');
22+
const filename = tmpdir.resolve('readfile_pipe_large_test.txt');
2423
const dataExpected = 'a'.repeat(999999);
2524
tmpdir.refresh();
2625
fs.writeFileSync(filename, dataExpected);

test/parallel/test-fs-readfile-unlink.js

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

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

3130
const tmpdir = require('../common/tmpdir');
3231

33-
const fileName = path.resolve(tmpdir.path, 'test.bin');
32+
const fileName = tmpdir.resolve('test.bin');
3433
const buf = Buffer.alloc(512 * 1024, 42);
3534

3635
tmpdir.refresh();

test/parallel/test-fs-readfile.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@ const common = require('../common');
77
const tmpdir = require('../../test/common/tmpdir');
88
const assert = require('assert');
99
const fs = require('fs');
10-
const path = require('path');
1110

1211
const prefix = `.removeme-fs-readfile-${process.pid}`;
1312

1413
tmpdir.refresh();
1514

1615
const fileInfo = [
17-
{ name: path.join(tmpdir.path, `${prefix}-1K.txt`),
16+
{ name: tmpdir.resolve(`${prefix}-1K.txt`),
1817
len: 1024 },
19-
{ name: path.join(tmpdir.path, `${prefix}-64K.txt`),
18+
{ name: tmpdir.resolve(`${prefix}-64K.txt`),
2019
len: 64 * 1024 },
21-
{ name: path.join(tmpdir.path, `${prefix}-64KLessOne.txt`),
20+
{ name: tmpdir.resolve(`${prefix}-64KLessOne.txt`),
2221
len: (64 * 1024) - 1 },
23-
{ name: path.join(tmpdir.path, `${prefix}-1M.txt`),
22+
{ name: tmpdir.resolve(`${prefix}-1M.txt`),
2423
len: 1 * 1024 * 1024 },
25-
{ name: path.join(tmpdir.path, `${prefix}-1MPlusOne.txt`),
24+
{ name: tmpdir.resolve(`${prefix}-1MPlusOne.txt`),
2625
len: (1 * 1024 * 1024) + 1 },
2726
];
2827

@@ -61,7 +60,7 @@ for (const e of fileInfo) {
6160
// truncateSync() will fail with ENOSPC if there is not enough space.
6261
common.printSkipMessage(`Not enough space in ${tmpdir.path}`);
6362
} else {
64-
const file = path.join(tmpdir.path, `${prefix}-too-large.txt`);
63+
const file = tmpdir.resolve(`${prefix}-too-large.txt`);
6564
fs.writeFileSync(file, Buffer.from('0'));
6665
fs.truncateSync(file, kIoMaxLength + 1);
6766

test/parallel/test-fs-readfilesync-pipe-large.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (common.isWindows || common.isAIX)
77
common.skip(`No /dev/stdin on ${process.platform}.`);
88

99
const assert = require('assert');
10-
const path = require('path');
1110
const fs = require('fs');
1211

1312
if (process.argv[2] === 'child') {
@@ -17,7 +16,7 @@ if (process.argv[2] === 'child') {
1716

1817
const tmpdir = require('../common/tmpdir');
1918

20-
const filename = path.join(tmpdir.path, '/readfilesync_pipe_large_test.txt');
19+
const filename = tmpdir.resolve('readfilesync_pipe_large_test.txt');
2120
const dataExpected = 'a'.repeat(999999);
2221
tmpdir.refresh();
2322
fs.writeFileSync(filename, dataExpected);

test/parallel/test-fs-readv-promises.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
const common = require('../common');
33
const assert = require('assert');
4-
const path = require('path');
54
const fs = require('fs').promises;
65
const tmpdir = require('../common/tmpdir');
76

@@ -12,7 +11,7 @@ const exptectedBuff = Buffer.from(expected);
1211

1312
let cnt = 0;
1413
function getFileName() {
15-
return path.join(tmpdir.path, `readv_promises_${++cnt}.txt`);
14+
return tmpdir.resolve(`readv_promises_${++cnt}.txt`);
1615
}
1716

1817
const allocateEmptyBuffers = (combinedLength) => {

0 commit comments

Comments
 (0)