nodejs/test/parallel/test-fs-write-stream-patch-open.js
James M Snell a273674dee
fs: move fs stream open method to eol
The `open()` method on fs read and write streams has been
deprecated for many years. It's time to remove it while
still allowing the open method to be monkeypatched since
that's still apparently a thing.

PR-URL: https://github.com/nodejs/node/pull/58529
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
2025-06-02 16:54:31 +00:00

28 lines
680 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
// Run in a child process because 'out' is opened twice, blocking the tmpdir
// and preventing cleanup.
if (process.argv[2] !== 'child') {
// Parent
const assert = require('assert');
const { fork } = require('child_process');
tmpdir.refresh();
// Run test
const child = fork(__filename, ['child'], { stdio: 'inherit' });
child.on('exit', common.mustCall(function(code) {
assert.strictEqual(code, 0);
}));
return;
}
// Child
// Allow overriding open().
fs.WriteStream.prototype.open = common.mustCall();
fs.createWriteStream('asd');