11const t = require ( 'tap' )
2- const fs = require ( 'fs' )
32const path = require ( 'path' )
43const tspawk = require ( '../../fixtures/tspawk' )
54const { load : loadMockNpm } = require ( '../../fixtures/mock-npm' )
@@ -39,49 +38,27 @@ t.test('npm edit', async t => {
3938 const { npm, joinedOutput } = await loadMockNpm ( t , npmConfig )
4039
4140 const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
42- const [ scriptShell ] = makeSpawnArgs ( {
41+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
4342 event : 'install' ,
4443 path : npm . prefix ,
4544 cmd : 'testinstall' ,
4645 } )
4746 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 } )
6048 await npm . exec ( 'edit' , [ 'semver' ] )
6149 t . match ( joinedOutput ( ) , 'rebuilt dependencies successfully' )
6250} )
6351
6452t . test ( 'rebuild failure' , async t => {
6553 const { npm } = await loadMockNpm ( t , npmConfig )
6654 const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
67- const [ scriptShell ] = makeSpawnArgs ( {
55+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
6856 event : 'install' ,
6957 path : npm . prefix ,
7058 cmd : 'testinstall' ,
7159 } )
7260 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' )
8562 await t . rejects (
8663 npm . exec ( 'edit' , [ 'semver' ] ) ,
8764 { message : 'command failed' }
@@ -108,24 +85,13 @@ t.test('npm edit editor has flags', async t => {
10885 } )
10986
11087 const semverPath = path . resolve ( npm . prefix , 'node_modules' , 'semver' )
111- const [ scriptShell ] = makeSpawnArgs ( {
88+ const [ scriptShell , scriptArgs ] = makeSpawnArgs ( {
11289 event : 'install' ,
11390 path : npm . prefix ,
11491 cmd : 'testinstall' ,
11592 } )
11693 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 } )
12995 await npm . exec ( 'edit' , [ 'semver' ] )
13096} )
13197
0 commit comments