1
1
const t = require ( 'tap' )
2
- const fs = require ( 'fs' )
3
2
const path = require ( 'path' )
4
3
const tspawk = require ( '../../fixtures/tspawk' )
5
4
const { load : loadMockNpm } = require ( '../../fixtures/mock-npm' )
@@ -39,49 +38,27 @@ t.test('npm edit', async t => {
39
38
const { npm, joinedOutput } = await loadMockNpm ( t , npmConfig )
40
39
41
40
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
42
- const [ scriptShell ] = makeSpawnArgs ( {
41
+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
43
42
event : 'install' ,
44
43
path : npm . prefix ,
45
44
cmd : 'testinstall' ,
46
45
} )
47
46
spawk . spawn ( 'testeditor' , [ semverPath ] )
48
- spawk . spawn (
49
- scriptShell ,
50
- args => {
51
- const lastArg = args [ args . length - 1 ]
52
- const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
53
- const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
54
- const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
55
- . trim ( ) . endsWith ( 'testinstall' )
56
- return rightExtension && rightFilename && rightContents
57
- } ,
58
- { cwd : semverPath }
59
- )
47
+ spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } )
60
48
await npm . exec ( 'edit' , [ 'semver' ] )
61
49
t . match ( joinedOutput ( ) , 'rebuilt dependencies successfully' )
62
50
} )
63
51
64
52
t . test ( 'rebuild failure' , async t => {
65
53
const { npm } = await loadMockNpm ( t , npmConfig )
66
54
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
67
- const [ scriptShell ] = makeSpawnArgs ( {
55
+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
68
56
event : 'install' ,
69
57
path : npm . prefix ,
70
58
cmd : 'testinstall' ,
71
59
} )
72
60
spawk . spawn ( 'testeditor' , [ semverPath ] )
73
- spawk . spawn (
74
- scriptShell ,
75
- args => {
76
- const lastArg = args [ args . length - 1 ]
77
- const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
78
- const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
79
- const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
80
- . trim ( ) . endsWith ( 'testinstall' )
81
- return rightExtension && rightFilename && rightContents
82
- } ,
83
- { cwd : semverPath }
84
- ) . exit ( 1 ) . stdout ( 'test error' )
61
+ spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } ) . exit ( 1 ) . stdout ( 'test error' )
85
62
await t . rejects (
86
63
npm . exec ( 'edit' , [ 'semver' ] ) ,
87
64
{ message : 'command failed' }
@@ -108,24 +85,13 @@ t.test('npm edit editor has flags', async t => {
108
85
} )
109
86
110
87
const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
111
- const [ scriptShell ] = makeSpawnArgs ( {
88
+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
112
89
event : 'install' ,
113
90
path : npm . prefix ,
114
91
cmd : 'testinstall' ,
115
92
} )
116
93
spawk . spawn ( 'testeditor' , [ '--flag' , semverPath ] )
117
- spawk . spawn (
118
- scriptShell ,
119
- args => {
120
- const lastArg = args [ args . length - 1 ]
121
- const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
122
- const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
123
- const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
124
- . trim ( ) . endsWith ( 'testinstall' )
125
- return rightExtension && rightFilename && rightContents
126
- } ,
127
- { cwd : semverPath }
128
- )
94
+ spawk . spawn ( scriptShell , scriptArgs , { cwd : semverPath } )
129
95
await npm . exec ( 'edit' , [ 'semver' ] )
130
96
} )
131
97
0 commit comments