Skip to content

Commit 678313d

Browse files
Masashi Hiranotargos
authored andcommitted
test: add filehandle sync() and datasync() tests
To increase test coverage for fs.promises, added tests for filehandle.sync and filehandle.datasync. PR-URL: #20530 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent ca8c960 commit 678313d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constfixtures=require('../common/fixtures');
5+
consttmpdir=require('../common/tmpdir');
6+
7+
const{ access, copyFile, open }=require('fs').promises;
8+
constpath=require('path');
9+
10+
common.crashOnUnhandledRejection();
11+
12+
asyncfunctionvalidateSync(){
13+
tmpdir.refresh();
14+
constdest=path.resolve(tmpdir.path,'baz.js');
15+
awaitcopyFile(fixtures.path('baz.js'),dest);
16+
awaitaccess(dest,'r');
17+
consthandle=awaitopen(dest,'r+');
18+
awaithandle.datasync();
19+
awaithandle.sync();
20+
constbuf=Buffer.from('hello world');
21+
awaithandle.write(buf);
22+
constret=awaithandle.read(Buffer.alloc(11),0,11,0);
23+
assert.strictEqual(ret.bytesRead,11);
24+
assert.deepStrictEqual(ret.buffer,buf);
25+
}
26+
27+
validateSync();

0 commit comments

Comments
(0)