0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-promises-file-handle-sync.js
Livia Medeiros 74e0ca3f49
test: use tmpdir.resolve() in fs tests
PR-URL: https://github.com/nodejs/node/pull/49125
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-08-15 13:45:14 +00:00

36 lines
960 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { access, copyFile, open } = require('fs').promises;
async function validate() {
tmpdir.refresh();
const dest = tmpdir.resolve('baz.js');
await assert.rejects(
copyFile(fixtures.path('baz.js'), dest, 'r'),
{
code: 'ERR_INVALID_ARG_TYPE',
}
);
await copyFile(fixtures.path('baz.js'), dest);
await assert.rejects(
access(dest, 'r'),
{ code: 'ERR_INVALID_ARG_TYPE', message: /mode/ }
);
await access(dest);
const handle = await open(dest, 'r+');
await handle.datasync();
await handle.sync();
const buf = Buffer.from('hello world');
await handle.write(buf);
const ret = await handle.read(Buffer.alloc(11), 0, 11, 0);
assert.strictEqual(ret.bytesRead, 11);
assert.deepStrictEqual(ret.buffer, buf);
await handle.close();
}
validate();