0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-write-stream-file-handle-2.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

33 lines
943 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const file = tmpdir.resolve('write_stream_filehandle_test.txt');
const input = 'hello world';
tmpdir.refresh();
fs.promises.open(file, 'w+').then((handle) => {
let calls = 0;
const {
write: originalWriteFunction,
writev: originalWritevFunction
} = handle;
handle.write = function write() {
calls++;
return Reflect.apply(originalWriteFunction, this, arguments);
};
handle.writev = function writev() {
calls++;
return Reflect.apply(originalWritevFunction, this, arguments);
};
const stream = fs.createWriteStream(null, { fd: handle });
stream.end(input);
stream.on('close', common.mustCall(() => {
assert(calls > 0, 'expected at least one call to fileHandle.write or ' +
'fileHandle.writev, got 0');
}));
}).then(common.mustCall());