mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Enable node:vfs by default. --no-experimental-vfs disables node:vfs exposure and --vfs-load. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/66318 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
// fs.opendir callback dispatches through VFS, both via readSync() iteration
|
|
// and via async iteration.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const vfs = require('node:vfs');
|
|
|
|
function mounted() {
|
|
const myVfs = vfs.create();
|
|
myVfs.mkdirSync('/src', { recursive: true });
|
|
myVfs.writeFileSync('/src/hello.txt', 'hello');
|
|
myVfs.writeFileSync('/src/data.json', '{}');
|
|
const mountPoint = myVfs.mount();
|
|
return { myVfs, mountPoint };
|
|
}
|
|
|
|
// readSync() iteration
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.opendir(path.join(mountPoint, 'src'),
|
|
common.mustSucceed((dir) => {
|
|
const names = [];
|
|
let entry;
|
|
while ((entry = dir.readSync()) !== null) names.push(entry.name);
|
|
dir.closeSync();
|
|
assert.ok(names.includes('hello.txt'));
|
|
myVfs.unmount();
|
|
}));
|
|
}
|
|
|
|
// for-await-of iteration
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.opendir(path.join(mountPoint, 'src'),
|
|
common.mustSucceed(async (dir) => {
|
|
const names = [];
|
|
for await (const entry of dir) names.push(entry.name);
|
|
assert.ok(names.includes('hello.txt'));
|
|
assert.ok(names.includes('data.json'));
|
|
myVfs.unmount();
|
|
}));
|
|
}
|