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>
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
// fs.writeFile and fs.appendFile 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 });
|
|
const mountPoint = myVfs.mount();
|
|
return { myVfs, mountPoint };
|
|
}
|
|
|
|
// writeFile (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
const target = path.join(mountPoint, 'src/cb-w.txt');
|
|
fs.writeFile(target, 'cbw', common.mustSucceed(() => {
|
|
assert.strictEqual(fs.readFileSync(target, 'utf8'), 'cbw');
|
|
myVfs.unmount();
|
|
}));
|
|
}
|
|
|
|
// appendFile (cb)
|
|
{
|
|
const { myVfs, mountPoint } = mounted();
|
|
const target = path.join(mountPoint, 'src/cb-a.txt');
|
|
fs.writeFileSync(target, 'base');
|
|
fs.appendFile(target, ' more', common.mustSucceed(() => {
|
|
assert.strictEqual(fs.readFileSync(target, 'utf8'), 'base more');
|
|
myVfs.unmount();
|
|
}));
|
|
}
|