Skip to content

Commit 31f3e67

Browse files
committed
test: add Windows symlink error handling test
Add test case to verify symlink creation handles stat() errors gracefully on Windows when resolving absolute target paths.
1 parent 78dee76 commit 31f3e67

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Test for Windows symlink error handling when stat() fails
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
// This test is specifically for Windows symlink behavior
7+
if (!common.isWindows) {
8+
common.skip('Windows-specific test');
9+
}
10+
11+
if (!common.canCreateSymLink()) {
12+
common.skip('insufficient privileges');
13+
}
14+
15+
const assert = require('assert');
16+
const fs = require('fs');
17+
const path = require('path');
18+
const tmpdir = require('../common/tmpdir');
19+
20+
tmpdir.refresh();
21+
22+
// Test that symlink creation doesn't crash when stat() fails on absoluteTarget
23+
// This tests the try-catch error handling added around stat() call
24+
const target = './nonexistent-target';
25+
const linkPath = tmpdir.resolve('test-symlink');
26+
27+
// Create a symlink with a relative target that would cause stat() to fail
28+
// when resolving the absolute target path
29+
fs.symlink(target, linkPath, common.mustSucceed(() => {
30+
// Verify the symlink was created successfully despite stat() error
31+
fs.lstat(linkPath, common.mustSucceed((stats) => {
32+
assert(stats.isSymbolicLink());
33+
}));
34+
35+
fs.readlink(linkPath, common.mustSucceed((destination) => {
36+
assert.strictEqual(destination, target);
37+
}));
38+
}));

0 commit comments

Comments
 (0)