Skip to content
Closed
Changes from 1 commit
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
Next Next commit
test: add fs/promises filehandle sync() and datasync() tests.
To increase test coverage for fs/promises,
added tests for filehandle.sync and filehandle.datasync.
  • Loading branch information
Masashi Hirano committed Jun 10, 2018
commit 05d5a1b5a4aac211b830a2587a52fef817e1f7d2
27 changes: 27 additions & 0 deletions test/parallel/test-fs-promises-file-handle-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');

const { access, copyFile, open, read, write } = require('fs/promises');
const path = require('path');

common.crashOnUnhandledRejection();

async function validateSync() {
tmpdir.refresh();
const dest = path.resolve(tmpdir.path, 'baz.js');
await copyFile(fixtures.path('baz.js'), dest);
await access(dest, 'r');
const handle = await open(dest, 'r+');
await handle.datasync();
await handle.sync();
const buf = Buffer.from('hello world');
await write(handle, buf);
Copy link
Copy Markdown
Member

@ChALkeR ChALkeR May 6, 2018

Choose a reason for hiding this comment

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

handle.write(buf)?
Same results and coverage, also see #20559.

const ret = await read(handle, Buffer.alloc(11), 0, 11, 0);
Copy link
Copy Markdown
Member

@ChALkeR ChALkeR May 6, 2018

Choose a reason for hiding this comment

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

read(handlehandle.read(? See the comment above.

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.

@ChALkeR Fixed them. Thanks.

assert.strictEqual(ret.bytesRead, 11);
assert.deepStrictEqual(ret.buffer, buf);
}

validateSync().then(common.mustCall());
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.

common.mustCall() here seems unnecessary. If anything, common.crashOnUnhandledRejection() above gives a better hint about why it fails.

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.

@joyeecheung Thanks. Removed common.mustCall().