@@ -9,6 +9,10 @@ const fs = require('fs-extra')
9
9
const execa = require ( 'execa' )
10
10
const portfinder = require ( 'portfinder' )
11
11
const Application = require ( 'spectron' ) . Application
12
+ // const {command} = require('yargs')
13
+ const mockYargsParse = jest . fn ( )
14
+ const mockYargsCommand = jest . fn ( ( ) => ( { parse : mockYargsParse } ) )
15
+ jest . mock ( 'yargs' , ( ) => ( { command : mockYargsCommand } ) )
12
16
jest . mock ( '@vue/cli-service/lib/commands/build' )
13
17
jest . mock ( 'fs-extra' )
14
18
jest . mock ( 'electron-builder' )
@@ -35,7 +39,7 @@ console.log = jest.fn()
35
39
beforeEach ( ( ) => {
36
40
jest . clearAllMocks ( )
37
41
} )
38
- const runCommand = async ( command , options = { } , args = { } ) => {
42
+ const runCommand = async ( command , options = { } , args = { } , rawArgs = [ ] ) => {
39
43
if ( ! args . _ ) args . _ = [ ]
40
44
const renderConfig = new Config ( )
41
45
// Command expects define plugin to exist
@@ -53,7 +57,8 @@ const runCommand = async (command, options = {}, args = {}) => {
53
57
resolve : jest . fn ( path => 'projectPath/' + path )
54
58
}
55
59
pluginIndex ( api , options )
56
- await commands [ command ] ( args , [ ] )
60
+
61
+ await commands [ command ] ( args , rawArgs )
57
62
}
58
63
59
64
describe ( 'build:electron' , ( ) => {
@@ -182,6 +187,44 @@ describe('build:electron', () => {
182
187
// Both .js and .ts are resolved
183
188
expect ( mainConfig . resolve . extensions ) . toEqual ( [ '.js' , '.ts' ] )
184
189
} )
190
+ test ( '--mode argument is removed from electron-builder args' , async ( ) => {
191
+ await runCommand ( 'build:electron' , { } , { } , [
192
+ '--keep1' ,
193
+ '--mode' ,
194
+ 'buildMode' ,
195
+ '--keep2'
196
+ ] )
197
+ // --mode and buildMode should have been removed
198
+ expect ( mockYargsParse ) . toBeCalledWith ( [ '--keep1' , '--keep2' ] )
199
+ mockYargsParse . mockClear ( )
200
+
201
+ await runCommand ( 'build:electron' , { } , { } , [
202
+ '--mode' ,
203
+ 'buildMode' ,
204
+ '--keep2'
205
+ ] )
206
+ // --mode and buildMode should have been removed
207
+ expect ( mockYargsParse ) . toBeCalledWith ( [ '--keep2' ] )
208
+ mockYargsParse . mockClear ( )
209
+
210
+ await runCommand ( 'build:electron' , { } , { } , [
211
+ '--keep1' ,
212
+ '--mode' ,
213
+ 'buildMode'
214
+ ] )
215
+ // --mode and buildMode should have been removed
216
+ expect ( mockYargsParse ) . toBeCalledWith ( [ '--keep1' ] )
217
+ mockYargsParse . mockClear ( )
218
+
219
+ await runCommand ( 'build:electron' , { } , { } , [ '--mode' , 'buildMode' ] )
220
+ // --mode and buildMode should have been removed
221
+ expect ( mockYargsParse ) . toBeCalledWith ( [ ] )
222
+ mockYargsParse . mockClear ( )
223
+
224
+ await runCommand ( 'build:electron' , { } , { } , [ '--keep1' , '--keep2' ] )
225
+ // --mode and buildMode should have been removed
226
+ expect ( mockYargsParse ) . toBeCalledWith ( [ '--keep1' , '--keep2' ] )
227
+ } )
185
228
} )
186
229
187
230
describe ( 'serve:electron' , ( ) => {
0 commit comments