Skip to content

Commit d6db585

Browse files
committed
vfs: add test for symlink target creation after symlink
Addresses @jasnell's review feedback to test that a symlink can be created before its target exists, and once the target is created, the symlink starts working correctly.
1 parent 51def85 commit d6db585

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/parallel/test-vfs-symlinks.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,37 @@ const vfs = require('node:vfs');
316316
myVfs.unmount();
317317
}
318318

319+
// Test symlink target created after symlink (dangling symlink becomes valid)
320+
{
321+
const myVfs = vfs.create();
322+
myVfs.mkdirSync('/dir');
323+
324+
// Create symlink pointing to non-existent target
325+
myVfs.symlinkSync('/dir/target.txt', '/dir/link');
326+
myVfs.mount('/virtual');
327+
328+
// Initially the symlink is broken
329+
assert.throws(() => {
330+
myVfs.statSync('/virtual/dir/link');
331+
}, { code: 'ENOENT' });
332+
333+
// lstatSync works (symlink itself exists)
334+
assert.strictEqual(myVfs.lstatSync('/virtual/dir/link').isSymbolicLink(), true);
335+
336+
// Now create the target file
337+
myVfs.writeFileSync('/virtual/dir/target.txt', 'created after symlink');
338+
339+
// Now the symlink should work
340+
const content = myVfs.readFileSync('/virtual/dir/link', 'utf8');
341+
assert.strictEqual(content, 'created after symlink');
342+
343+
// Stat should also work now
344+
const stats = myVfs.statSync('/virtual/dir/link');
345+
assert.strictEqual(stats.isFile(), true);
346+
347+
myVfs.unmount();
348+
}
349+
319350
// Test symlink with parent traversal (..)
320351
{
321352
const myVfs = vfs.create();

0 commit comments

Comments
 (0)