node/test/parallel/test-vfs-readfile-encoding.js
Matteo Collina c9562ddb82
vfs: add minimal node:vfs subsystem
Adds the node:vfs builtin module with VirtualFileSystem and
provider classes. No integration with fs, modules, or SEA.

Assisted-by: Claude-Opus4.7
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/63115
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2026-05-23 18:43:31 +00:00

21 lines
603 B
JavaScript

// Flags: --experimental-vfs
'use strict';
// readFileSync with invalid encoding must throw.
require('../common');
const assert = require('assert');
const vfs = require('node:vfs');
const myVfs = vfs.create();
myVfs.writeFileSync('/file.txt', 'x');
assert.throws(
() => myVfs.readFileSync('/file.txt', { encoding: 'bogus' }),
/encoding/i,
);
// Valid encodings should work
assert.strictEqual(myVfs.readFileSync('/file.txt', 'utf8'), 'x');
assert.strictEqual(myVfs.readFileSync('/file.txt', { encoding: 'utf8' }), 'x');
assert.deepStrictEqual(myVfs.readFileSync('/file.txt'), Buffer.from('x'));