0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-promisified.js
Livia Medeiros 6a68794577
test: use tmpdir.resolve() in fs tests
PR-URL: https://github.com/nodejs/node/pull/49126
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-08-15 13:45:24 +00:00

37 lines
981 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const { promisify } = require('util');
const read = promisify(fs.read);
const write = promisify(fs.write);
const exists = promisify(fs.exists);
{
const fd = fs.openSync(__filename, 'r');
read(fd, Buffer.alloc(1024), 0, 1024, null).then(common.mustCall((obj) => {
assert.strictEqual(typeof obj.bytesRead, 'number');
assert(obj.buffer instanceof Buffer);
fs.closeSync(fd);
}));
}
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
const filename = tmpdir.resolve('write-promise.txt');
const fd = fs.openSync(filename, 'w');
write(fd, Buffer.from('foobar')).then(common.mustCall((obj) => {
assert.strictEqual(typeof obj.bytesWritten, 'number');
assert.strictEqual(obj.buffer.toString(), 'foobar');
fs.closeSync(fd);
}));
}
{
exists(__filename).then(common.mustCall((x) => {
assert.strictEqual(x, true);
}));
}