11const t = require ( 'tap' )
2+ const fs = require ( 'fs' )
23const path = require ( 'path' )
34const tspawk = require ( '../../fixtures/tspawk' )
45const { load : loadMockNpm } = require ( '../../fixtures/mock-npm' )
@@ -45,7 +46,14 @@ t.test('npm edit', async t => {
4546 spawk . spawn ( 'testeditor' , [ semverPath ] )
4647 spawk . spawn (
4748 scriptShell ,
48- args => args . includes ( 'testinstall' ) ,
49+ args => {
50+ const lastArg = args [ args . length - 1 ]
51+ const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
52+ const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
53+ const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
54+ . trim ( ) . endsWith ( 'testinstall' )
55+ return rightExtension && rightFilename && rightContents
56+ } ,
4957 { cwd : semverPath }
5058 )
5159 await npm . exec ( 'edit' , [ 'semver' ] )
@@ -62,7 +70,14 @@ t.test('rebuild failure', async t => {
6270 spawk . spawn ( 'testeditor' , [ semverPath ] )
6371 spawk . spawn (
6472 scriptShell ,
65- args => args . includes ( 'testinstall' ) ,
73+ args => {
74+ const lastArg = args [ args . length - 1 ]
75+ const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
76+ const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
77+ const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
78+ . trim ( ) . endsWith ( 'testinstall' )
79+ return rightExtension && rightFilename && rightContents
80+ } ,
6681 { cwd : semverPath }
6782 ) . exit ( 1 ) . stdout ( 'test error' )
6883 await t . rejects (
@@ -98,7 +113,14 @@ t.test('npm edit editor has flags', async t => {
98113 spawk . spawn ( 'testeditor' , [ '--flag' , semverPath ] )
99114 spawk . spawn (
100115 scriptShell ,
101- args => args . includes ( 'testinstall' ) ,
116+ args => {
117+ const lastArg = args [ args . length - 1 ]
118+ const rightExtension = lastArg . endsWith ( '.cmd' ) || lastArg . endsWith ( '.sh' )
119+ const rightFilename = path . basename ( lastArg ) . startsWith ( 'install' )
120+ const rightContents = fs . readFileSync ( lastArg , { encoding : 'utf8' } )
121+ . trim ( ) . endsWith ( 'testinstall' )
122+ return rightExtension && rightFilename && rightContents
123+ } ,
102124 { cwd : semverPath }
103125 )
104126 await npm . exec ( 'edit' , [ 'semver' ] )
0 commit comments