11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
4- var fs = require ( 'fs' ) ;
5- var path = require ( 'path' ) ;
6- var exec = require ( 'child_process' ) . exec ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const fs = require ( 'fs' ) ;
5+ const path = require ( 'path' ) ;
6+ const exec = require ( 'child_process' ) . exec ;
77var async_completed = 0 , async_expected = 0 , unlink = [ ] ;
88var skipSymlinks = false ;
99
1010common . refreshTmpDir ( ) ;
1111
1212var root = '/' ;
13- var assertEqualPath = assert . equal ;
13+ var assertEqualPath = assert . strictEqual ;
1414if ( common . isWindows ) {
1515 // something like "C:\\"
1616 root = process . cwd ( ) . substr ( 0 , 3 ) ;
1717 assertEqualPath = function ( path_left , path_right , message ) {
18- assert . equal ( path_left . toLowerCase ( ) , path_right . toLowerCase ( ) , message ) ;
18+ assert
19+ . strictEqual ( path_left . toLowerCase ( ) , path_right . toLowerCase ( ) , message ) ;
1920 } ;
2021
2122 // On Windows, creating symlinks requires admin privileges.
2223 // We'll only try to run symlink test if we have enough privileges.
2324 try {
2425 exec ( 'whoami /priv' , function ( err , o ) {
25- if ( err || o . indexOf ( 'SeCreateSymbolicLinkPrivilege' ) == - 1 ) {
26+ if ( err || ! o . includes ( 'SeCreateSymbolicLinkPrivilege' ) ) {
2627 skipSymlinks = true ;
2728 }
2829 runTest ( ) ;
@@ -41,8 +42,8 @@ function tmp(p) {
4142 return path . join ( common . tmpDir , p ) ;
4243}
4344
44- var targetsAbsDir = path . join ( common . tmpDir , 'targets' ) ;
45- var tmpAbsDir = common . tmpDir ;
45+ const targetsAbsDir = path . join ( common . tmpDir , 'targets' ) ;
46+ const tmpAbsDir = common . tmpDir ;
4647
4748// Set up targetsAbsDir and expected subdirectories
4849fs . mkdirSync ( targetsAbsDir ) ;
@@ -91,7 +92,7 @@ function test_simple_relative_symlink(callback) {
9192 fs . symlinkSync ( t [ 1 ] , t [ 0 ] , 'file' ) ;
9293 unlink . push ( t [ 0 ] ) ;
9394 } ) ;
94- var result = fs . realpathSync ( entry ) ;
95+ const result = fs . realpathSync ( entry ) ;
9596 assertEqualPath ( result , path . resolve ( expected ) ) ;
9697 asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
9798 assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -103,7 +104,7 @@ function test_simple_absolute_symlink(callback) {
103104
104105 // this one should still run, even if skipSymlinks is set,
105106 // because it uses a junction.
106- var type = skipSymlinks ? 'junction' : 'dir' ;
107+ const type = skipSymlinks ? 'junction' : 'dir' ;
107108
108109 console . log ( 'using type=%s' , type ) ;
109110
@@ -117,7 +118,7 @@ function test_simple_absolute_symlink(callback) {
117118 fs . symlinkSync ( t [ 1 ] , t [ 0 ] , type ) ;
118119 unlink . push ( t [ 0 ] ) ;
119120 } ) ;
120- var result = fs . realpathSync ( entry ) ;
121+ const result = fs . realpathSync ( entry ) ;
121122 assertEqualPath ( result , path . resolve ( expected ) ) ;
122123 asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
123124 assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -131,16 +132,17 @@ function test_deep_relative_file_symlink(callback) {
131132 return runNextTest ( ) ;
132133 }
133134
134- var expected = path . join ( common . fixturesDir , 'cycles' , 'root.js' ) ;
135- var linkData1 = path . relative ( path . join ( targetsAbsDir , 'nested-index' , 'one' ) ,
136- expected ) ;
137- var linkPath1 = path . join ( targetsAbsDir ,
135+ const expected = path . join ( common . fixturesDir , 'cycles' , 'root.js' ) ;
136+ const linkData1 = path
137+ . relative ( path . join ( targetsAbsDir , 'nested-index' , 'one' ) ,
138+ expected ) ;
139+ const linkPath1 = path . join ( targetsAbsDir ,
138140 'nested-index' , 'one' , 'symlink1.js' ) ;
139141 try { fs . unlinkSync ( linkPath1 ) ; } catch ( e ) { }
140142 fs . symlinkSync ( linkData1 , linkPath1 , 'file' ) ;
141143
142- var linkData2 = '../one/symlink1.js' ;
143- var entry = path . join ( targetsAbsDir ,
144+ const linkData2 = '../one/symlink1.js' ;
145+ const entry = path . join ( targetsAbsDir ,
144146 'nested-index' , 'two' , 'symlink1-b.js' ) ;
145147 try { fs . unlinkSync ( entry ) ; } catch ( e ) { }
146148 fs . symlinkSync ( linkData2 , entry , 'file' ) ;
@@ -159,15 +161,15 @@ function test_deep_relative_dir_symlink(callback) {
159161 common . skip ( 'symlink test (no privs)' ) ;
160162 return runNextTest ( ) ;
161163 }
162- var expected = path . join ( common . fixturesDir , 'cycles' , 'folder' ) ;
163- var path1b = path . join ( targetsAbsDir , 'nested-index' , 'one' ) ;
164- var linkPath1b = path . join ( path1b , 'symlink1-dir' ) ;
165- var linkData1b = path . relative ( path1b , expected ) ;
164+ const expected = path . join ( common . fixturesDir , 'cycles' , 'folder' ) ;
165+ const path1b = path . join ( targetsAbsDir , 'nested-index' , 'one' ) ;
166+ const linkPath1b = path . join ( path1b , 'symlink1-dir' ) ;
167+ const linkData1b = path . relative ( path1b , expected ) ;
166168 try { fs . unlinkSync ( linkPath1b ) ; } catch ( e ) { }
167169 fs . symlinkSync ( linkData1b , linkPath1b , 'dir' ) ;
168170
169- var linkData2b = '../one/symlink1-dir' ;
170- var entry = path . join ( targetsAbsDir ,
171+ const linkData2b = '../one/symlink1-dir' ;
172+ const entry = path . join ( targetsAbsDir ,
171173 'nested-index' , 'two' , 'symlink12-dir' ) ;
172174 try { fs . unlinkSync ( entry ) ; } catch ( e ) { }
173175 fs . symlinkSync ( linkData2b , entry , 'dir' ) ;
@@ -187,7 +189,7 @@ function test_cyclic_link_protection(callback) {
187189 common . skip ( 'symlink test (no privs)' ) ;
188190 return runNextTest ( ) ;
189191 }
190- var entry = common . tmpDir + '/cycles/realpath-3a' ;
192+ const entry = common . tmpDir + '/cycles/realpath-3a' ;
191193 [
192194 [ entry , '../cycles/realpath-3b' ] ,
193195 [ common . tmpDir + '/cycles/realpath-3b' , '../cycles/realpath-3c' ] ,
@@ -210,10 +212,10 @@ function test_cyclic_link_overprotection(callback) {
210212 common . skip ( 'symlink test (no privs)' ) ;
211213 return runNextTest ( ) ;
212214 }
213- var cycles = common . tmpDir + '/cycles' ;
214- var expected = fs . realpathSync ( cycles ) ;
215- var folder = cycles + '/folder' ;
216- var link = folder + '/cycles' ;
215+ const cycles = common . tmpDir + '/cycles' ;
216+ const expected = fs . realpathSync ( cycles ) ;
217+ const folder = cycles + '/folder' ;
218+ const link = folder + '/cycles' ;
217219 var testPath = cycles ;
218220 testPath += '/folder/cycles' . repeat ( 10 ) ;
219221 try { fs . unlinkSync ( link ) ; } catch ( ex ) { }
@@ -233,26 +235,26 @@ function test_relative_input_cwd(callback) {
233235 }
234236
235237 // we need to calculate the relative path to the tmp dir from cwd
236- var entrydir = process . cwd ( ) ;
237- var entry = path . relative ( entrydir ,
238+ const entrydir = process . cwd ( ) ;
239+ const entry = path . relative ( entrydir ,
238240 path . join ( common . tmpDir + '/cycles/realpath-3a' ) ) ;
239- var expected = common . tmpDir + '/cycles/root.js' ;
241+ const expected = common . tmpDir + '/cycles/root.js' ;
240242 [
241243 [ entry , '../cycles/realpath-3b' ] ,
242244 [ common . tmpDir + '/cycles/realpath-3b' , '../cycles/realpath-3c' ] ,
243245 [ common . tmpDir + '/cycles/realpath-3c' , 'root.js' ]
244246 ] . forEach ( function ( t ) {
245- var fn = t [ 0 ] ;
247+ const fn = t [ 0 ] ;
246248 console . error ( 'fn=%j' , fn ) ;
247249 try { fs . unlinkSync ( fn ) ; } catch ( e ) { }
248- var b = path . basename ( t [ 1 ] ) ;
249- var type = ( b === 'root.js' ? 'file' : 'dir' ) ;
250+ const b = path . basename ( t [ 1 ] ) ;
251+ const type = ( b === 'root.js' ? 'file' : 'dir' ) ;
250252 console . log ( 'fs.symlinkSync(%j, %j, %j)' , t [ 1 ] , fn , type ) ;
251253 fs . symlinkSync ( t [ 1 ] , fn , 'file' ) ;
252254 unlink . push ( fn ) ;
253255 } ) ;
254256
255- var origcwd = process . cwd ( ) ;
257+ const origcwd = process . cwd ( ) ;
256258 process . chdir ( entrydir ) ;
257259 assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
258260 asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
@@ -282,7 +284,7 @@ function test_deep_symlink_mix(callback) {
282284 $tmpDir/targets/nested-index/two/realpath-c -> $tmpDir/cycles/root.js
283285 $tmpDir/targets/cycles/root.js (hard)
284286 */
285- var entry = tmp ( 'node-test-realpath-f1' ) ;
287+ const entry = tmp ( 'node-test-realpath-f1' ) ;
286288 try { fs . unlinkSync ( tmp ( 'node-test-realpath-d2/foo' ) ) ; } catch ( e ) { }
287289 try { fs . rmdirSync ( tmp ( 'node-test-realpath-d2' ) ) ; } catch ( e ) { }
288290 fs . mkdirSync ( tmp ( 'node-test-realpath-d2' ) , 0o700 ) ;
@@ -306,7 +308,7 @@ function test_deep_symlink_mix(callback) {
306308 } finally {
307309 unlink . push ( tmp ( 'node-test-realpath-d2' ) ) ;
308310 }
309- var expected = tmpAbsDir + '/cycles/root.js' ;
311+ const expected = tmpAbsDir + '/cycles/root.js' ;
310312 assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
311313 asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
312314 assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -316,10 +318,10 @@ function test_deep_symlink_mix(callback) {
316318
317319function test_non_symlinks ( callback ) {
318320 console . log ( 'test_non_symlinks' ) ;
319- var entrydir = path . dirname ( tmpAbsDir ) ;
320- var entry = tmpAbsDir . substr ( entrydir . length + 1 ) + '/cycles/root.js' ;
321- var expected = tmpAbsDir + '/cycles/root.js' ;
322- var origcwd = process . cwd ( ) ;
321+ const entrydir = path . dirname ( tmpAbsDir ) ;
322+ const entry = tmpAbsDir . substr ( entrydir . length + 1 ) + '/cycles/root.js' ;
323+ const expected = tmpAbsDir + '/cycles/root.js' ;
324+ const origcwd = process . cwd ( ) ;
323325 process . chdir ( entrydir ) ;
324326 assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
325327 asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
@@ -329,7 +331,7 @@ function test_non_symlinks(callback) {
329331 } ) ;
330332}
331333
332- var upone = path . join ( process . cwd ( ) , '..' ) ;
334+ const upone = path . join ( process . cwd ( ) , '..' ) ;
333335function test_escape_cwd ( cb ) {
334336 console . log ( 'test_escape_cwd' ) ;
335337 asynctest ( fs . realpath , [ '..' ] , cb , function ( er , uponeActual ) {
@@ -338,7 +340,7 @@ function test_escape_cwd(cb) {
338340 ' actual:' + uponeActual ) ;
339341 } ) ;
340342}
341- var uponeActual = fs . realpathSync ( '..' ) ;
343+ const uponeActual = fs . realpathSync ( '..' ) ;
342344assertEqualPath ( upone , uponeActual ,
343345 'realpathSync("..") expected: ' + path . resolve ( upone ) +
344346 ' actual:' + uponeActual ) ;
@@ -375,11 +377,11 @@ function test_up_multiple(cb) {
375377 fs . symlinkSync ( '..' , tmp ( 'a/b/e' ) , 'dir' ) ;
376378 unlink . push ( tmp ( 'a/b/e' ) ) ;
377379
378- var abedabed = tmp ( 'abedabed' . split ( '' ) . join ( '/' ) ) ;
379- var abedabed_real = tmp ( '' ) ;
380+ const abedabed = tmp ( 'abedabed' . split ( '' ) . join ( '/' ) ) ;
381+ const abedabed_real = tmp ( '' ) ;
380382
381- var abedabeda = tmp ( 'abedabeda' . split ( '' ) . join ( '/' ) ) ;
382- var abedabeda_real = tmp ( 'a' ) ;
383+ const abedabeda = tmp ( 'abedabeda' . split ( '' ) . join ( '/' ) ) ;
384+ const abedabeda_real = tmp ( 'a' ) ;
383385
384386 assertEqualPath ( fs . realpathSync ( abedabeda ) , abedabeda_real ) ;
385387 assertEqualPath ( fs . realpathSync ( abedabed ) , abedabed_real ) ;
@@ -409,11 +411,11 @@ function test_abs_with_kids(cb) {
409411
410412 // this one should still run, even if skipSymlinks is set,
411413 // because it uses a junction.
412- var type = skipSymlinks ? 'junction' : 'dir' ;
414+ const type = skipSymlinks ? 'junction' : 'dir' ;
413415
414416 console . log ( 'using type=%s' , type ) ;
415417
416- var root = tmpAbsDir + '/node-test-realpath-abs-kids' ;
418+ const root = tmpAbsDir + '/node-test-realpath-abs-kids' ;
417419 function cleanup ( ) {
418420 [ '/a/b/c/x.txt' ,
419421 '/a/link'
@@ -442,9 +444,9 @@ function test_abs_with_kids(cb) {
442444 fs . symlinkSync ( root + '/a/b' , root + '/a/link' , type ) ;
443445 }
444446 setup ( ) ;
445- var linkPath = root + '/a/link/c/x.txt' ;
446- var expectPath = root + '/a/b/c/x.txt' ;
447- var actual = fs . realpathSync ( linkPath ) ;
447+ const linkPath = root + '/a/link/c/x.txt' ;
448+ const expectPath = root + '/a/b/c/x.txt' ;
449+ const actual = fs . realpathSync ( linkPath ) ;
448450 // console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
449451 assertEqualPath ( actual , path . resolve ( expectPath ) ) ;
450452 asynctest ( fs . realpath , [ linkPath ] , cb , function ( er , actual ) {
@@ -456,7 +458,7 @@ function test_abs_with_kids(cb) {
456458
457459// ----------------------------------------------------------------------------
458460
459- var tests = [
461+ const tests = [
460462 test_simple_error_callback ,
461463 test_simple_relative_symlink ,
462464 test_simple_absolute_symlink ,
@@ -471,11 +473,11 @@ var tests = [
471473 test_abs_with_kids ,
472474 test_up_multiple
473475] ;
474- var numtests = tests . length ;
476+ const numtests = tests . length ;
475477var testsRun = 0 ;
476478function runNextTest ( err ) {
477479 if ( err ) throw err ;
478- var test = tests . shift ( ) ;
480+ const test = tests . shift ( ) ;
479481 if ( ! test ) {
480482 return console . log ( numtests +
481483 ' subtests completed OK for fs.realpath' ) ;
@@ -487,13 +489,13 @@ function runNextTest(err) {
487489
488490assertEqualPath ( root , fs . realpathSync ( '/' ) ) ;
489491fs . realpath ( '/' , function ( err , result ) {
490- assert . equal ( null , err ) ;
492+ assert . ifError ( err ) ;
491493 assertEqualPath ( root , result ) ;
492494} ) ;
493495
494496
495497function runTest ( ) {
496- var tmpDirs = [ 'cycles' , 'cycles/folder' ] ;
498+ const tmpDirs = [ 'cycles' , 'cycles/folder' ] ;
497499 tmpDirs . forEach ( function ( t ) {
498500 t = tmp ( t ) ;
499501 fs . mkdirSync ( t , 0o700 ) ;
@@ -506,6 +508,5 @@ function runTest() {
506508
507509process . on ( 'exit' , function ( ) {
508510 assert . equal ( numtests , testsRun ) ;
509- unlink . forEach ( function ( path ) { try { fs . unlinkSync ( path ) ; } catch ( e ) { } } ) ;
510511 assert . equal ( async_completed , async_expected ) ;
511512} ) ;
0 commit comments