@@ -6,29 +6,29 @@ import {npmRunPath, npmRunPathEnv} from './index.js';
6
6
7
7
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
8
8
9
- const testLocalDir = ( t , addExecPath , preferLocal , expectedResult ) => {
9
+ const testLocalDirectory = ( t , addExecPath , preferLocal , expectedResult ) => {
10
10
t . is (
11
11
npmRunPath ( { path : '' , addExecPath, preferLocal} ) . split ( path . delimiter ) [ 0 ] === path . join ( __dirname , 'node_modules/.bin' ) ,
12
12
expectedResult ,
13
13
) ;
14
14
} ;
15
15
16
- test ( 'Adds node_modules/.bin - npmRunPath()' , testLocalDir , undefined , undefined , true ) ;
17
- test ( '"addExecPath: false" still adds node_modules/.bin - npmRunPath()' , testLocalDir , false , undefined , true ) ;
18
- test ( '"preferLocal: false" does not add node_modules/.bin - npmRunPath()' , testLocalDir , undefined , false , false ) ;
19
- test ( '"preferLocal: false", "addExecPath: false" does not add node_modules/.bin - npmRunPath()' , testLocalDir , false , false , false ) ;
16
+ test ( 'Adds node_modules/.bin - npmRunPath()' , testLocalDirectory , undefined , undefined , true ) ;
17
+ test ( '"addExecPath: false" still adds node_modules/.bin - npmRunPath()' , testLocalDirectory , false , undefined , true ) ;
18
+ test ( '"preferLocal: false" does not add node_modules/.bin - npmRunPath()' , testLocalDirectory , undefined , false , false ) ;
19
+ test ( '"preferLocal: false", "addExecPath: false" does not add node_modules/.bin - npmRunPath()' , testLocalDirectory , false , false , false ) ;
20
20
21
- const testLocalDirEnv = ( t , addExecPath , preferLocal , expectedResult ) => {
21
+ const testLocalDirectoryEnv = ( t , addExecPath , preferLocal , expectedResult ) => {
22
22
t . is (
23
23
npmRunPathEnv ( { env : { PATH : 'foo' } , addExecPath, preferLocal} ) . PATH . split ( path . delimiter ) [ 0 ] === path . join ( __dirname , 'node_modules/.bin' ) ,
24
24
expectedResult ,
25
25
) ;
26
26
} ;
27
27
28
- test ( 'Adds node_modules/.bin - npmRunPathEnv()' , testLocalDirEnv , undefined , undefined , true ) ;
29
- test ( '"addExecPath: false" still adds node_modules/.bin - npmRunPathEnv()' , testLocalDirEnv , false , undefined , true ) ;
30
- test ( '"preferLocal: false" does not add node_modules/.bin - npmRunPathEnv()' , testLocalDirEnv , undefined , false , false ) ;
31
- test ( '"preferLocal: false", "addExecPath: false" does not add node_modules/.bin - npmRunPathEnv()' , testLocalDirEnv , false , false , false ) ;
28
+ test ( 'Adds node_modules/.bin - npmRunPathEnv()' , testLocalDirectoryEnv , undefined , undefined , true ) ;
29
+ test ( '"addExecPath: false" still adds node_modules/.bin - npmRunPathEnv()' , testLocalDirectoryEnv , false , undefined , true ) ;
30
+ test ( '"preferLocal: false" does not add node_modules/.bin - npmRunPathEnv()' , testLocalDirectoryEnv , undefined , false , false ) ;
31
+ test ( '"preferLocal: false", "addExecPath: false" does not add node_modules/.bin - npmRunPathEnv()' , testLocalDirectoryEnv , false , false , false ) ;
32
32
33
33
test ( 'the `cwd` option changes the current directory' , t => {
34
34
t . is (
@@ -46,12 +46,17 @@ test('the `cwd` option can be a file URL', t => {
46
46
47
47
test ( 'push `execPath` later in the PATH' , t => {
48
48
const pathEnv = npmRunPath ( { path : '' } ) . split ( path . delimiter ) ;
49
- t . is ( pathEnv [ pathEnv . length - 2 ] , path . dirname ( process . execPath ) ) ;
49
+ t . is ( pathEnv . at ( - 2 ) , path . dirname ( process . execPath ) ) ;
50
50
} ) ;
51
51
52
52
const testExecPath = ( t , preferLocal , addExecPath , expectedResult ) => {
53
- const pathEnv = npmRunPath ( { path : '' , execPath : 'test/test' , preferLocal, addExecPath} ) . split ( path . delimiter ) ;
54
- t . is ( pathEnv [ pathEnv . length - 2 ] === path . resolve ( 'test' ) , expectedResult ) ;
53
+ const pathEnv = npmRunPath ( {
54
+ path : '' ,
55
+ execPath : 'test/test' ,
56
+ preferLocal,
57
+ addExecPath,
58
+ } ) . split ( path . delimiter ) ;
59
+ t . is ( pathEnv . at ( - 2 ) === path . resolve ( 'test' ) , expectedResult ) ;
55
60
} ;
56
61
57
62
test ( 'can change `execPath` with the `execPath` option - npmRunPath()' , testExecPath , undefined , undefined , true ) ;
@@ -60,8 +65,13 @@ test('"addExecPath: false" does not add execPath - npmRunPath()', testExecPath,
60
65
test ( '"addExecPath: false", "preferLocal: false" does not add execPath - npmRunPath()' , testExecPath , false , false , false ) ;
61
66
62
67
const testExecPathEnv = ( t , preferLocal , addExecPath , expectedResult ) => {
63
- const pathEnv = npmRunPathEnv ( { env : { PATH : 'foo' } , execPath : 'test/test' , preferLocal, addExecPath} ) . PATH . split ( path . delimiter ) ;
64
- t . is ( pathEnv [ pathEnv . length - 2 ] === path . resolve ( 'test' ) , expectedResult ) ;
68
+ const pathEnv = npmRunPathEnv ( {
69
+ env : { PATH : 'foo' } ,
70
+ execPath : 'test/test' ,
71
+ preferLocal,
72
+ addExecPath,
73
+ } ) . PATH . split ( path . delimiter ) ;
74
+ t . is ( pathEnv . at ( - 2 ) === path . resolve ( 'test' ) , expectedResult ) ;
65
75
} ;
66
76
67
77
test ( 'can change `execPath` with the `execPath` option - npmRunPathEnv()' , testExecPathEnv , undefined , undefined , true ) ;
@@ -71,7 +81,7 @@ test('"addExecPath: false", "preferLocal: false" does not add execPath - npmRunP
71
81
72
82
test ( 'the `execPath` option can be a file URL' , t => {
73
83
const pathEnv = npmRunPath ( { path : '' , execPath : pathToFileURL ( 'test/test' ) } ) . split ( path . delimiter ) ;
74
- t . is ( pathEnv [ pathEnv . length - 2 ] , path . resolve ( 'test' ) ) ;
84
+ t . is ( pathEnv . at ( - 2 ) , path . resolve ( 'test' ) ) ;
75
85
} ) ;
76
86
77
87
test ( 'the `execPath` option is relative to the `cwd` option' , t => {
@@ -80,5 +90,5 @@ test('the `execPath` option is relative to the `cwd` option', t => {
80
90
execPath : 'test/test' ,
81
91
cwd : '/dir' ,
82
92
} ) . split ( path . delimiter ) ;
83
- t . is ( pathEnv [ pathEnv . length - 2 ] , path . normalize ( '/dir/test' ) ) ;
93
+ t . is ( pathEnv . at ( - 2 ) , path . normalize ( '/dir/test' ) ) ;
84
94
} ) ;
0 commit comments