Skip to content

Commit d20bde9

Browse files
committed
Address review comments
1 parent fffdce1 commit d20bde9

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

test/parallel/test-fs-promises.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,46 @@ function verifyStatObject(stat) {
9090
await fsync(handle);
9191
await handle.sync();
9292

93-
const buf = Buffer.from('hello world');
93+
const buf = Buffer.from('hello fsPromises');
94+
const bufLen = buf.length;
9495
await write(handle, buf);
95-
const ret = await read(handle, Buffer.alloc(11), 0, 11, 0);
96-
assert.strictEqual(ret.bytesRead, 11);
96+
const ret = await read(handle, Buffer.alloc(bufLen), 0, bufLen, 0);
97+
assert.strictEqual(ret.bytesRead, bufLen);
9798
assert.deepStrictEqual(ret.buffer, buf);
9899

99-
const buf2 = Buffer.from('HELLO WORLD');
100-
await handle.write(buf2);
101-
const ret2 = await handle.read(Buffer.alloc(11), 0, 11, 0);
102-
assert.strictEqual(ret2.bytesRead, 11);
103-
assert.deepStrictEqual(ret2.buffer, buf);
100+
const buf2 = Buffer.from('hello FileHandle');
101+
const buf2Len = buf2.length;
102+
await handle.write(buf2, 0, buf2Len, 0);
103+
const ret2 = await handle.read(Buffer.alloc(buf2Len), 0, buf2Len, 0);
104+
assert.strictEqual(ret2.bytesRead, buf2Len);
105+
assert.deepStrictEqual(ret2.buffer, buf2);
104106

105107
await chmod(dest, 0o666);
106108
await fchmod(handle, 0o666);
107109
handle.chmod(0o666);
108-
try {
109-
await fchmod(handle, (0o777 + 1));
110-
} catch (err) {
111-
// mode can't be > 0o777
112-
common.expectsError({
110+
111+
// `mode` can't be > 0o777
112+
assert.rejects(
113+
() => chmod(handle, (0o777 + 1)),
114+
{
115+
code: 'ERR_INVALID_ARG_TYPE',
116+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
117+
}
118+
);
119+
assert.rejects(
120+
() => fchmod(handle, (0o777 + 1)),
121+
{
113122
code: 'ERR_OUT_OF_RANGE',
114-
type: RangeError
115-
})(err);
116-
}
123+
name: 'RangeError [ERR_OUT_OF_RANGE]'
124+
}
125+
);
126+
assert.rejects(
127+
() => handle.chmod(handle, (0o777 + 1)),
128+
{
129+
code: 'ERR_INVALID_ARG_TYPE',
130+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
131+
}
132+
);
117133

118134
await utimes(dest, new Date(), new Date());
119135

@@ -167,16 +183,15 @@ function verifyStatObject(stat) {
167183
await rmdir(newdir);
168184

169185
await mkdtemp(path.resolve(tmpDir, 'FOO'));
170-
try {
171-
await mkdtemp(1);
172-
} catch (err) {
186+
assert.rejects(
173187
// mkdtemp() expects to get a string prefix.
174-
console.log('err', err);
175-
common.expectsError({
188+
async () => mkdtemp(1),
189+
{
176190
code: 'ERR_INVALID_ARG_TYPE',
177-
type: TypeError
178-
})(err);
179-
}
191+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
192+
}
193+
);
194+
180195
}
181196

182197
doTest().then(common.mustCall());

0 commit comments

Comments
 (0)