Skip to content

Commit

Permalink
test: use tmpdir.resolve() in fs tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
LiviaMedeiros authored and RafaelGSS committed Aug 15, 2023
1 parent daadf53 commit 50007d8
Show file tree
Hide file tree
Showing 58 changed files with 95 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
// The following tests validate aggregate errors are thrown correctly
// when both an operation and close throw.

const path = require('path');
const {
readFile,
writeFile,
Expand All @@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');

let count = 0;
async function createFile() {
const filePath = path.join(tmpdir.path, `aggregate_errors_${++count}.txt`);
const filePath = tmpdir.resolve(`aggregate_errors_${++count}.txt`);
await writeFile(filePath, 'content');
return filePath;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-close-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
// The following tests validate aggregate errors are thrown correctly
// when both an operation and close throw.

const path = require('path');
const {
readFile,
writeFile,
Expand All @@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');

let count = 0;
async function createFile() {
const filePath = path.join(tmpdir.path, `close_errors_${++count}.txt`);
const filePath = tmpdir.resolve(`close_errors_${++count}.txt`);
await writeFile(filePath, 'content');
return filePath;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-op-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const tmpdir = require('../common/tmpdir');
// The following tests validate aggregate errors are thrown correctly
// when both an operation and close throw.

const path = require('path');
const {
readFile,
writeFile,
Expand All @@ -23,7 +22,7 @@ const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');

let count = 0;
async function createFile() {
const filePath = path.join(tmpdir.path, `op_errors_${++count}.txt`);
const filePath = tmpdir.resolve(`op_errors_${++count}.txt`);
await writeFile(filePath, 'content');
return filePath;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-read-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, 'read_stream_filehandle_worker.txt');
const file = tmpdir.resolve('read_stream_filehandle_worker.txt');
const input = 'hello world';
const { Worker, isMainThread, workerData } = require('worker_threads');

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-readLines.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import tmpdir from '../common/tmpdir.js';

import assert from 'node:assert';
import { open, writeFile } from 'node:fs/promises';
import path from 'node:path';

tmpdir.refresh();

const filePath = path.join(tmpdir.path, 'file.txt');
const filePath = tmpdir.resolve('file.txt');

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

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ const common = require('../common');
// FileHandle.stat method.

const { open } = require('fs').promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

tmpdir.refresh();

async function validateStat() {
const filePath = path.resolve(tmpdir.path, 'tmp-read-file.txt');
const filePath = tmpdir.resolve('tmp-read-file.txt');
const fileHandle = await open(filePath, 'w+');
const stats = await fileHandle.stat();
assert.ok(stats.mtime instanceof Date);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');

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

async function validate() {
tmpdir.refresh();
const dest = path.resolve(tmpdir.path, 'baz.js');
const dest = tmpdir.resolve('baz.js');
await assert.rejects(
copyFile(fixtures.path('baz.js'), dest, 'r'),
{
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-file-handle-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

const common = require('../common');
const assert = require('assert');
const path = require('path');
const { open, readFile } = require('fs').promises;
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

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

const buffer = Buffer.from(text, 'utf8');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-readfile-with-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

const common = require('../common');
const assert = require('assert');
const path = require('path');
const { writeFileSync } = require('fs');
const { open } = require('fs').promises;

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

const fn = path.join(tmpdir.path, 'test.txt');
const fn = tmpdir.resolve('test.txt');
writeFileSync(fn, 'Hello World');

async function readFileTest() {
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
const common = require('../common');

const assert = require('assert');
const path = require('path');
const { writeFile, readFile } = require('fs').promises;
const tmpdir = require('../common/tmpdir');
const { internalBinding } = require('internal/test/binding');
const fsBinding = internalBinding('fs');
tmpdir.refresh();

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

// Creating large buffer with random content
const largeBuffer = Buffer.from(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-promises-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WatchTestCase {
this.field = field;
this.shouldSkip = !shouldInclude;
}
get dirPath() { return join(tmpdir.path, this.dirName); }
get dirPath() { return tmpdir.resolve(this.dirName); }
get filePath() { return join(this.dirPath, this.fileName); }
}

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-write-optional-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ const common = require('../common');

const assert = require('assert');
const fsPromises = require('fs').promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

const dest = path.resolve(tmpdir.path, 'tmp.txt');
const dest = tmpdir.resolve('tmp.txt');
const buffer = Buffer.from('zyx');

async function testInvalid(dest, expectedCode, ...params) {
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-promises-writefile-with-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

const common = require('../common');
const assert = require('assert');
const path = require('path');
const { readFileSync } = require('fs');
const { open } = require('fs').promises;

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

const fn = path.join(tmpdir.path, 'test.txt');
const fn = tmpdir.resolve('test.txt');

async function writeFileTest() {
const handle = await open(fn, 'w');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-read-stream-autoClose.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

const common = require('../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const writeFile = path.join(tmpdir.path, 'write-autoClose.txt');
const writeFile = tmpdir.resolve('write-autoClose.txt');
tmpdir.refresh();

const file = fs.createWriteStream(writeFile, { autoClose: true });
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-read-stream-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, '/read_stream_fd_test.txt');
const file = tmpdir.resolve('read_stream_fd_test.txt');
const input = 'hello world';

let output = '';
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-read-stream-file-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, 'read_stream_filehandle_test.txt');
const file = tmpdir.resolve('read_stream_filehandle_test.txt');
const input = 'hello world';

tmpdir.refresh();
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-read-stream-pos.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const assert = require('assert');
const path = require('path');

tmpdir.refresh();

const file = path.join(tmpdir.path, '/read_stream_pos_test.txt');
const file = tmpdir.resolve('read_stream_pos_test.txt');

fs.writeFileSync(file, '');

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfile-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const fn = fixtures.path('empty.txt');
const join = require('path').join;
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

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

const filename = join(tmpdir.path, 'test.txt');
const filename = tmpdir.resolve('test.txt');
fs.writeFileSync(filename, 'Hello World');

{
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-fs-readfile-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

{
const emptyFile = path.join(tmpdir.path, 'empty.txt');
const emptyFile = tmpdir.resolve('empty.txt');
fs.closeSync(fs.openSync(emptyFile, 'w'));

fs.readFile(
Expand All @@ -29,7 +28,7 @@ tmpdir.refresh();
}

{
const willBeCreated = path.join(tmpdir.path, 'will-be-created');
const willBeCreated = tmpdir.resolve('will-be-created');

fs.readFile(
willBeCreated,
Expand All @@ -40,7 +39,7 @@ tmpdir.refresh();
}

{
const willNotBeCreated = path.join(tmpdir.path, 'will-not-be-created');
const willNotBeCreated = tmpdir.resolve('will-not-be-created');

fs.readFile(
willNotBeCreated,
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfile-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (common.isWindows || common.isAIX)
common.skip(`No /dev/stdin on ${process.platform}.`);

const assert = require('assert');
const path = require('path');
const fs = require('fs');

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

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

const filename = path.join(tmpdir.path, '/readfile_pipe_large_test.txt');
const filename = tmpdir.resolve('readfile_pipe_large_test.txt');
const dataExpected = 'a'.repeat(999999);
tmpdir.refresh();
fs.writeFileSync(filename, dataExpected);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfile-unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ const common = require('../common');

const assert = require('assert');
const fs = require('fs');
const path = require('path');

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

const fileName = path.resolve(tmpdir.path, 'test.bin');
const fileName = tmpdir.resolve('test.bin');
const buf = Buffer.alloc(512 * 1024, 42);

tmpdir.refresh();
Expand Down
13 changes: 6 additions & 7 deletions test/parallel/test-fs-readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ const common = require('../common');
const tmpdir = require('../../test/common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');

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

tmpdir.refresh();

const fileInfo = [
{ name: path.join(tmpdir.path, `${prefix}-1K.txt`),
{ name: tmpdir.resolve(`${prefix}-1K.txt`),
len: 1024 },
{ name: path.join(tmpdir.path, `${prefix}-64K.txt`),
{ name: tmpdir.resolve(`${prefix}-64K.txt`),
len: 64 * 1024 },
{ name: path.join(tmpdir.path, `${prefix}-64KLessOne.txt`),
{ name: tmpdir.resolve(`${prefix}-64KLessOne.txt`),
len: (64 * 1024) - 1 },
{ name: path.join(tmpdir.path, `${prefix}-1M.txt`),
{ name: tmpdir.resolve(`${prefix}-1M.txt`),
len: 1 * 1024 * 1024 },
{ name: path.join(tmpdir.path, `${prefix}-1MPlusOne.txt`),
{ name: tmpdir.resolve(`${prefix}-1MPlusOne.txt`),
len: (1 * 1024 * 1024) + 1 },
];

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

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfilesync-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (common.isWindows || common.isAIX)
common.skip(`No /dev/stdin on ${process.platform}.`);

const assert = require('assert');
const path = require('path');
const fs = require('fs');

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

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

const filename = path.join(tmpdir.path, '/readfilesync_pipe_large_test.txt');
const filename = tmpdir.resolve('readfilesync_pipe_large_test.txt');
const dataExpected = 'a'.repeat(999999);
tmpdir.refresh();
fs.writeFileSync(filename, dataExpected);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readv-promises.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs').promises;
const tmpdir = require('../common/tmpdir');

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

let cnt = 0;
function getFileName() {
return path.join(tmpdir.path, `readv_promises_${++cnt}.txt`);
return tmpdir.resolve(`readv_promises_${++cnt}.txt`);
}

const allocateEmptyBuffers = (combinedLength) => {
Expand Down
Loading

0 comments on commit 50007d8

Please sign in to comment.