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