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>
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
// fs.mkdir, fs.rmdir, fs.rm, and fs.unlink callbacks dispatch through VFS.
|
|
|
|
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');
|
|
const mountPoint = myVfs.mount();
|
|
return { myVfs, mountPoint };
|
|
}
|
|
|
|
// mkdir (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.mkdir(path.join(mountPoint, 'src/cb-d'), common.mustSucceed(() => {
|
|
assert.strictEqual(
|
|
fs.statSync(path.join(mountPoint, 'src/cb-d')).isDirectory(), true,
|
|
);
|
|
myVfs.unmount();
|
|
}));
|
|
}
|
|
|
|
// rmdir (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.mkdirSync(path.join(mountPoint, 'src/empty'));
|
|
fs.rmdir(path.join(mountPoint, 'src/empty'), common.mustSucceed(() => {
|
|
assert.strictEqual(fs.existsSync(path.join(mountPoint, 'src/empty')),
|
|
false);
|
|
myVfs.unmount();
|
|
}));
|
|
}
|
|
|
|
// rm (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.rm(path.join(mountPoint, 'src/hello.txt'),
|
|
common.mustSucceed(() => {
|
|
assert.strictEqual(fs.existsSync(path.join(mountPoint, 'src/hello.txt')),
|
|
false);
|
|
myVfs.unmount();
|
|
}));
|
|
}
|
|
|
|
// unlink (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
fs.unlink(path.join(mountPoint, 'src/hello.txt'),
|
|
common.mustSucceed(() => {
|
|
assert.strictEqual(
|
|
fs.existsSync(path.join(mountPoint, 'src/hello.txt')), false,
|
|
);
|
|
myVfs.unmount();
|
|
}));
|
|
}
|