Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ const { internalBinding } = require('internal/test/binding');
const { UV_ENOENT } = internalBinding('uv');

const tmpdir = require('../common/tmpdir');
const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist');
const readOnlyFile = path.join(tmpdir.path, 'read_only_file');
const readWriteFile = path.join(tmpdir.path, 'read_write_file');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unrelated whitespace change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups : fixed

const { doesNotExist, readOnlyFile, readWriteFile } = Object.assign(
...Object.entries({
doesNotExist: '__this_should_not_exist',
readOnlyFile: 'read_only_file',
readWriteFile: 'read_write_file'
}).map(([k, v]) => ({ [k]: path.join(tmpdir.path, v) })));


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups : fixed

function createFileWithPerms(file, mode) {
fs.writeFileSync(file, '');
Expand Down Expand Up @@ -59,10 +64,9 @@ if (!common.isWindows && process.getuid() === 0) {
}
}

assert.strictEqual(typeof fs.F_OK, 'number');
assert.strictEqual(typeof fs.R_OK, 'number');
assert.strictEqual(typeof fs.W_OK, 'number');
assert.strictEqual(typeof fs.X_OK, 'number');
[fs.F_OK, fs.R_OK, fs.W_OK, fs.X_OK].forEach(
(cons) => assert.strictEqual(typeof cons, 'number')
);

const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };

Expand Down
13 changes: 8 additions & 5 deletions test/parallel/test-fs-append-file-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

// test that empty file will be created and have content added
const filename = join(tmpdir.path, 'append-sync.txt');
const { filename, filename2, filename3, filename4, filename5 } =
Object.assign(...Object.entries({
filename: 'append-sync.txt',
filename2: 'append-sync2.txt',
filename3: 'append-sync3.txt',
filename4: 'append-sync4.txt',
filename5: 'append-sync5.txt'
}).map(([k, v]) => ({ [k]: join(tmpdir.path, v) })));

fs.appendFileSync(filename, data);

Expand All @@ -49,7 +56,6 @@ const fileData = fs.readFileSync(filename);
assert.strictEqual(Buffer.byteLength(data), fileData.length);

// test that appends data to a non empty file
const filename2 = join(tmpdir.path, 'append-sync2.txt');
fs.writeFileSync(filename2, currentFileData);

fs.appendFileSync(filename2, data);
Expand All @@ -60,7 +66,6 @@ assert.strictEqual(Buffer.byteLength(data) + currentFileData.length,
fileData2.length);

// test that appendFileSync accepts buffers
const filename3 = join(tmpdir.path, 'append-sync3.txt');
fs.writeFileSync(filename3, currentFileData);

const buf = Buffer.from(data, 'utf8');
Expand All @@ -71,7 +76,6 @@ const fileData3 = fs.readFileSync(filename3);
assert.strictEqual(buf.length + currentFileData.length, fileData3.length);

// test that appendFile accepts numbers.
const filename4 = join(tmpdir.path, 'append-sync4.txt');
fs.writeFileSync(filename4, currentFileData, { mode: m });

fs.appendFileSync(filename4, num, { mode: m });
Expand All @@ -88,7 +92,6 @@ assert.strictEqual(Buffer.byteLength(String(num)) + currentFileData.length,
fileData4.length);

// test that appendFile accepts file descriptors
const filename5 = join(tmpdir.path, 'append-sync5.txt');
fs.writeFileSync(filename5, currentFileData);

const filename5fd = fs.openSync(filename5, 'a+', 0o600);
Expand Down
9 changes: 3 additions & 6 deletions test/parallel/test-fs-copyfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ function verify(src, dest) {
tmpdir.refresh();

// Verify that flags are defined.
assert.strictEqual(typeof COPYFILE_EXCL, 'number');
assert.strictEqual(typeof COPYFILE_FICLONE, 'number');
assert.strictEqual(typeof COPYFILE_FICLONE_FORCE, 'number');
assert.strictEqual(typeof UV_FS_COPYFILE_EXCL, 'number');
assert.strictEqual(typeof UV_FS_COPYFILE_FICLONE, 'number');
assert.strictEqual(typeof UV_FS_COPYFILE_FICLONE_FORCE, 'number');
[COPYFILE_EXCL, COPYFILE_FICLONE, COPYFILE_FICLONE_FORCE, UV_FS_COPYFILE_EXCL,
UV_FS_COPYFILE_FICLONE, UV_FS_COPYFILE_FICLONE_FORCE]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same that above : I will change

.forEach((cons) => assert.strictEqual(typeof cons, 'number'));
assert.strictEqual(COPYFILE_EXCL, UV_FS_COPYFILE_EXCL);
assert.strictEqual(COPYFILE_FICLONE, UV_FS_COPYFILE_FICLONE);
assert.strictEqual(COPYFILE_FICLONE_FORCE, UV_FS_COPYFILE_FICLONE_FORCE);
Expand Down
12 changes: 3 additions & 9 deletions test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const O_APPEND = fs.constants.O_APPEND || 0;
const O_CREAT = fs.constants.O_CREAT || 0;
const O_EXCL = fs.constants.O_EXCL || 0;
const O_RDONLY = fs.constants.O_RDONLY || 0;
const O_RDWR = fs.constants.O_RDWR || 0;
const O_SYNC = fs.constants.O_SYNC || 0;
const O_DSYNC = fs.constants.O_DSYNC || 0;
const O_TRUNC = fs.constants.O_TRUNC || 0;
const O_WRONLY = fs.constants.O_WRONLY || 0;
// 0 if not found in fs.constants
const { O_APPEND = 0, O_CREAT = 0, O_EXCL = 0, O_RDONLY = 0, O_RDWR = 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep these each on separate lines?

const {
  O_APPEND = 0,
  O_CREAT = 0,
  ...
} = fs.constants;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for readability : I will change

O_SYNC = 0, O_DSYNC = 0, O_TRUNC = 0, O_WRONLY = 0 } = fs.constants;

const { stringToFlags } = require('internal/fs/utils');

Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-fs-open-mode-mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ const assert = require('assert');
const path = require('path');
const fs = require('fs');

let mode;
const mode = (common.isWindows) ? 0o444 : 0o644;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Parentheses unnecessary.

Copy link
Copy Markdown
Contributor Author

@jy95 jy95 Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that they are not necessary for simple case (like this one). ESLint didn't remove them


if (common.isWindows) {
mode = 0o444;
} else {
mode = 0o644;
}

const maskToIgnore = 0o10000;

Expand Down
32 changes: 4 additions & 28 deletions test/parallel/test-fs-stat-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,10 @@ function verifyStats(bigintStats, numStats) {
`Number version ${time}, BigInt version ${time2}n`);
} else if (key === 'mode') {
assert.strictEqual(bigintStats[key], BigInt(val));
assert.strictEqual(
bigintStats.isBlockDevice(),
numStats.isBlockDevice()
);
assert.strictEqual(
bigintStats.isCharacterDevice(),
numStats.isCharacterDevice()
);
assert.strictEqual(
bigintStats.isDirectory(),
numStats.isDirectory()
);
assert.strictEqual(
bigintStats.isFIFO(),
numStats.isFIFO()
);
assert.strictEqual(
bigintStats.isFile(),
numStats.isFile()
);
assert.strictEqual(
bigintStats.isSocket(),
numStats.isSocket()
);
assert.strictEqual(
bigintStats.isSymbolicLink(),
numStats.isSymbolicLink()
);
['isBlockDevice', 'isCharacterDevice', 'isDirectory', 'isFIFO', 'isFile',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean one line for each item of the array ? Sure if you want

'isFile', 'isSocket', 'isSymbolicLink' ].forEach(
(fct) => assert.strictEqual(bigintStats[fct](), numStats[fct]()));

} else if (common.isWindows && (key === 'blksize' || key === 'blocks')) {
assert.strictEqual(bigintStats[key], undefined);
assert.strictEqual(numStats[key], undefined);
Expand Down