@@ -5,15 +5,11 @@ const { load: loadMockNpm } = require('../../fixtures/mock-npm')
5
5
6
6
const spawk = tspawk ( t )
7
7
8
- // TODO this ... smells. npm "script-shell" config mentions defaults but those
9
- // are handled by run-script, not npm. So for now we have to tie tests to some
10
- // pretty specific internals of runScript
11
- const makeSpawnArgs = require ( '@npmcli/run-script/lib/make-spawn-args.js' )
12
-
13
8
const npmConfig = {
14
9
config : {
15
10
'ignore-scripts' : false ,
16
11
editor : 'testeditor' ,
12
+ scriptShell : process . platform === 'win32' ? process . env . COMSPEC : 'sh' ,
17
13
} ,
18
14
prefixDir : {
19
15
node_modules : {
@@ -34,30 +30,34 @@ const npmConfig = {
34
30
} ,
35
31
}
36
32
33
+ const isCmdRe = / (?: ^ | \\ ) c m d (?: \. e x e ) ? $ / i
34
+
37
35
t . test ( 'npm edit' , async t => {
38
36
const { npm, joinedOutput } = await loadMockNpm ( t , npmConfig )
39
37
40
38
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
41
- const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
42
- event : 'install' ,
43
- path : npm . prefix ,
44
- cmd : 'testinstall' ,
45
- } )
46
39
spawk . spawn ( 'testeditor' , [ semverPath ] )
40
+
41
+ const scriptShell = npm . config . get ( 'scriptShell' )
42
+ const scriptArgs = isCmdRe . test ( scriptShell )
43
+ ? [ '/d' , '/s' , '/c' , 'testinstall' ]
44
+ : [ '-c' , 'testinstall' ]
47
45
spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } )
46
+
48
47
await npm . exec ( 'edit' , [ 'semver' ] )
49
48
t . match ( joinedOutput ( ) , 'rebuilt dependencies successfully' )
50
49
} )
51
50
52
51
t . test ( 'rebuild failure' , async t => {
53
52
const { npm } = await loadMockNpm ( t , npmConfig )
53
+
54
54
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
55
- const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
56
- event : 'install' ,
57
- path : npm . prefix ,
58
- cmd : 'testinstall' ,
59
- } )
60
55
spawk . spawn ( 'testeditor' , [ semverPath ] )
56
+
57
+ const scriptShell = npm . config . get ( 'scriptShell' )
58
+ const scriptArgs = isCmdRe . test ( scriptShell )
59
+ ? [ '/d' , '/s' , '/c' , 'testinstall' ]
60
+ : [ '-c' , 'testinstall' ]
61
61
spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } ) . exit ( 1 ) . stdout ( 'test error' )
62
62
await t . rejects (
63
63
npm . exec ( 'edit' , [ 'semver' ] ) ,
@@ -67,8 +67,10 @@ t.test('rebuild failure', async t => {
67
67
68
68
t . test ( 'editor failure' , async t => {
69
69
const { npm } = await loadMockNpm ( t , npmConfig )
70
+
70
71
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
71
72
spawk . spawn ( 'testeditor' , [ semverPath ] ) . exit ( 1 ) . stdout ( 'test editor failure' )
73
+
72
74
await t . rejects (
73
75
npm . exec ( 'edit' , [ 'semver' ] ) ,
74
76
{ message : 'editor process exited with code: 1' }
@@ -85,13 +87,14 @@ t.test('npm edit editor has flags', async t => {
85
87
} )
86
88
87
89
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
88
- const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
89
- event : 'install' ,
90
- path : npm . prefix ,
91
- cmd : 'testinstall' ,
92
- } )
93
90
spawk . spawn ( 'testeditor' , [ '--flag' , semverPath ] )
91
+
92
+ const scriptShell = npm . config . get ( 'scriptShell' )
93
+ const scriptArgs = isCmdRe . test ( scriptShell )
94
+ ? [ '/d' , '/s' , '/c' , 'testinstall' ]
95
+ : [ '-c' , 'testinstall' ]
94
96
spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } )
97
+
95
98
await npm . exec ( 'edit' , [ 'semver' ] )
96
99
} )
97
100
0 commit comments