Skip to content

Commit 678313d

Browse files
Masashi Hiranotargos
Masashi Hirano
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fixtures = require('../common/fixtures');
5+
const tmpdir = require('../common/tmpdir');
6+
7+
const { access, copyFile, open } = require('fs').promises;
8+
const path = require('path');
9+
10+
common.crashOnUnhandledRejection();
11+
12+
async function validateSync() {
13+
tmpdir.refresh();
14+
const dest = path.resolve(tmpdir.path, 'baz.js');
15+
await copyFile(fixtures.path('baz.js'), dest);
16+
await access(dest, 'r');
17+
const handle = await open(dest, 'r+');
18+
await handle.datasync();
19+
await handle.sync();
20+
const buf = Buffer.from('hello world');
21+
await handle.write(buf);
22+
const ret = await handle.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)