@@ -126,7 +126,7 @@ describe('background.js', () => {
126
126
fs . readFileSync . mockImplementation ( ( path , encoding ) => {
127
127
// Check that utf8 encoding is set
128
128
expect ( encoding ) . toBe ( 'utf8' )
129
- // Mock existing postinstall script in app's package.json
129
+ // Mock existing scripts in app's package.json
130
130
if ( path === 'apiResolve_./package.json' ) {
131
131
return JSON . stringify ( {
132
132
scripts : { }
@@ -144,22 +144,20 @@ describe('background.js', () => {
144
144
} )
145
145
} )
146
146
147
- describe ( ' package.json' , ( ) => {
148
- test ( ' Adds electron-builder install-app-deps to postInstall' , ( ) => {
147
+ describe . each ( [ 'postinstall' , 'postuninstall' ] ) ( ' package.json (%s)' , script => {
148
+ test ( ` Adds electron-builder install-app-deps to ${ script } ` , ( ) => {
149
149
generator ( mockApi )
150
150
completionCb ( )
151
- expect ( pkg . scripts . postinstall ) . toBe ( 'electron-builder install-app-deps' )
151
+ expect ( pkg . scripts [ script ] ) . toBe ( 'electron-builder install-app-deps' )
152
152
} )
153
153
154
- test ( ' Adds on to existing postinstall script instead of replacing' , ( ) => {
154
+ test ( ` Adds on to existing ${ script } script instead of replacing` , ( ) => {
155
155
fs . readFileSync . mockImplementation ( ( path , encoding ) => {
156
156
// Check that utf8 encoding is set
157
157
expect ( encoding ) . toBe ( 'utf8' )
158
- // Mock existing postinstall script in app's package.json
158
+ // Mock existing script in app's package.json
159
159
if ( path === 'apiResolve_./package.json' ) {
160
- return JSON . stringify ( {
161
- scripts : { postinstall : 'existingTask' }
162
- } )
160
+ return `{"scripts": { "${ script } ": "existingTask" }}`
163
161
}
164
162
// return mock content
165
163
return 'existing_content'
@@ -168,7 +166,7 @@ describe('package.json', () => {
168
166
generator ( mockApi )
169
167
completionCb ( )
170
168
171
- expect ( pkg . scripts . postinstall ) . toBe (
169
+ expect ( pkg . scripts [ script ] ) . toBe (
172
170
'existingTask && electron-builder install-app-deps'
173
171
)
174
172
} )
@@ -177,13 +175,13 @@ describe('package.json', () => {
177
175
fs . readFileSync . mockImplementation ( ( path , encoding ) => {
178
176
// Check that utf8 encoding is set
179
177
expect ( encoding ) . toBe ( 'utf8' )
180
- // Mock existing postinstall script in app's package.json
178
+ // Mock existing script in app's package.json
181
179
if ( path === 'apiResolve_./package.json' ) {
182
- return JSON . stringify ( {
183
- scripts : {
184
- postinstall : ' existingTask && electron-builder install-app-deps'
180
+ return ` {
181
+ " scripts" : {
182
+ " ${ script } ": " existingTask && electron-builder install-app-deps"
185
183
}
186
- } )
184
+ }`
187
185
}
188
186
// return mock content
189
187
return 'existing_content'
@@ -192,7 +190,7 @@ describe('package.json', () => {
192
190
generator ( mockApi )
193
191
completionCb ( )
194
192
195
- expect ( pkg . scripts . postinstall ) . toBe (
193
+ expect ( pkg . scripts [ script ] ) . toBe (
196
194
'existingTask && electron-builder install-app-deps'
197
195
)
198
196
} )
0 commit comments