1
1
const t = require ( 'tap' )
2
+ const fs = require ( 'fs' )
2
3
const path = require ( 'path' )
3
4
const tspawk = require ( '../../fixtures/tspawk' )
4
5
const { load : loadMockNpm } = require ( '../../fixtures/mock-npm' )
@@ -45,7 +46,14 @@ t.test('npm edit', async t => {
45
46
spawk . spawn ( 'testeditor' , [ semverPath ] )
46
47
spawk . spawn (
47
48
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
+ } ,
49
57
{ cwd : semverPath }
50
58
)
51
59
await npm . exec ( 'edit' , [ 'semver' ] )
@@ -62,7 +70,14 @@ t.test('rebuild failure', async t => {
62
70
spawk . spawn ( 'testeditor' , [ semverPath ] )
63
71
spawk . spawn (
64
72
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
+ } ,
66
81
{ cwd : semverPath }
67
82
) . exit ( 1 ) . stdout ( 'test error' )
68
83
await t . rejects (
@@ -98,7 +113,14 @@ t.test('npm edit editor has flags', async t => {
98
113
spawk . spawn ( 'testeditor' , [ '--flag' , semverPath ] )
99
114
spawk . spawn (
100
115
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
+ } ,
102
124
{ cwd : semverPath }
103
125
)
104
126
await npm . exec ( 'edit' , [ 'semver' ] )
0 commit comments