Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b6e8cc

Browse filesBrowse files
humphdaddaleax
authored andcommitted
test: increase test coverage for fs/promises.js
PR-URL: #19811 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent e6c0bbe commit 2b6e8cc
Copy full SHA for 2b6e8cc

File tree

Expand file treeCollapse file tree

1 file changed

+50
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+50
-5
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises.js
+50-5Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,60 @@ function verifyStatObject(stat) {
8787
stats = await stat(dest);
8888
verifyStatObject(stats);
8989

90+
stats = await handle.stat();
91+
verifyStatObject(stats);
92+
9093
await fdatasync(handle);
94+
await handle.datasync();
9195
await fsync(handle);
96+
await handle.sync();
9297

93-
const buf = Buffer.from('hello world');
94-
98+
const buf = Buffer.from('hello fsPromises');
99+
const bufLen = buf.length;
95100
await write(handle, buf);
96-
97-
const ret = await read(handle, Buffer.alloc(11), 0, 11, 0);
98-
assert.strictEqual(ret.bytesRead, 11);
101+
const ret = await read(handle, Buffer.alloc(bufLen), 0, bufLen, 0);
102+
assert.strictEqual(ret.bytesRead, bufLen);
99103
assert.deepStrictEqual(ret.buffer, buf);
100104

105+
const buf2 = Buffer.from('hello FileHandle');
106+
const buf2Len = buf2.length;
107+
await handle.write(buf2, 0, buf2Len, 0);
108+
const ret2 = await handle.read(Buffer.alloc(buf2Len), 0, buf2Len, 0);
109+
assert.strictEqual(ret2.bytesRead, buf2Len);
110+
assert.deepStrictEqual(ret2.buffer, buf2);
111+
101112
await chmod(dest, 0o666);
102113
await fchmod(handle, 0o666);
114+
await handle.chmod(0o666);
115+
116+
// `mode` can't be > 0o777
117+
assert.rejects(
118+
async () => chmod(handle, (0o777 + 1)),
119+
{
120+
code: 'ERR_INVALID_ARG_TYPE',
121+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
122+
}
123+
);
124+
assert.rejects(
125+
async () => fchmod(handle, (0o777 + 1)),
126+
{
127+
code: 'ERR_OUT_OF_RANGE',
128+
name: 'RangeError [ERR_OUT_OF_RANGE]'
129+
}
130+
);
131+
assert.rejects(
132+
async () => handle.chmod(handle, (0o777 + 1)),
133+
{
134+
code: 'ERR_INVALID_ARG_TYPE',
135+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
136+
}
137+
);
103138

104139
await utimes(dest, new Date(), new Date());
105140

106141
try {
107142
await futimes(handle, new Date(), new Date());
143+
await handle.utimes(new Date(), new Date());
108144
} catch (err) {
109145
// Some systems do not have futimes. If there is an error,
110146
// expect it to be ENOSYS
@@ -152,6 +188,15 @@ function verifyStatObject(stat) {
152188
await rmdir(newdir);
153189

154190
await mkdtemp(path.resolve(tmpDir, 'FOO'));
191+
assert.rejects(
192+
// mkdtemp() expects to get a string prefix.
193+
async () => mkdtemp(1),
194+
{
195+
code: 'ERR_INVALID_ARG_TYPE',
196+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
197+
}
198+
);
199+
155200
}
156201

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.