@@ -8,7 +8,7 @@ const path = require('path')
8
8
const execa = require ( 'execa' )
9
9
const portfinder = require ( 'portfinder' )
10
10
const Application = require ( 'spectron' ) . Application
11
- const { chainWebpack } = require ( '../lib/webpackConfig' )
11
+ const { chainWebpack, getExternals } = require ( '../lib/webpackConfig' )
12
12
// #endregion
13
13
14
14
// #region Mocks
@@ -47,6 +47,12 @@ jest.mock('@vue/cli-service/lib/commands/serve', () => ({
47
47
serve : jest . fn ( ) . mockResolvedValue ( { url : 'serveUrl' } )
48
48
} ) )
49
49
jest . mock ( 'electron-builder' , ( ) => ( { build : jest . fn ( ) . mockResolvedValue ( ) } ) )
50
+ // Mock package.json
51
+ fs . readFileSync . mockReturnValue (
52
+ JSON . stringify ( {
53
+ dependencies : { }
54
+ } )
55
+ )
50
56
const mockWait = jest . fn ( ) . mockResolvedValue ( )
51
57
const mockStart = jest . fn ( )
52
58
jest . mock ( 'spectron' , ( ) => ( {
@@ -204,14 +210,12 @@ describe('electron:build', () => {
204
210
fs . existsSync . mockReturnValueOnce ( true )
205
211
await runCommand ( 'electron:build' )
206
212
// css/fonts folder was created
207
- expect ( fs . ensureDirSync . mock . calls [ 2 ] [ 0 ] ) . toBe (
213
+ expect ( fs . ensureDirSync ) . toBeCalledWith (
208
214
'projectPath/dist_electron/bundled/css/fonts'
209
215
)
210
216
// fonts was copied to css/fonts
211
- expect ( fs . copySync . mock . calls [ 1 ] [ 0 ] ) . toBe (
212
- 'projectPath/dist_electron/bundled/fonts'
213
- )
214
- expect ( fs . copySync . mock . calls [ 1 ] [ 1 ] ) . toBe (
217
+ expect ( fs . copySync ) . toBeCalledWith (
218
+ 'projectPath/dist_electron/bundled/fonts' ,
215
219
'projectPath/dist_electron/bundled/css/fonts'
216
220
)
217
221
} )
@@ -337,15 +341,42 @@ describe('electron:build', () => {
337
341
}
338
342
} )
339
343
expect ( fs . writeFileSync ) . toBeCalledWith (
340
- `dist_electron${ path . sep } bundled${ path . sep } legacy-assets-index.html.json` ,
344
+ `dist_electron${ path . sep } bundled${
345
+ path . sep
346
+ } legacy-assets-index.html.json`,
341
347
'[]'
342
348
)
343
349
expect ( fs . writeFileSync ) . toBeCalledWith (
344
- `dist_electron${ path . sep } bundled${ path . sep } legacy-assets-subpage.html.json` ,
350
+ `dist_electron${ path . sep } bundled${
351
+ path . sep
352
+ } legacy-assets-subpage.html.json`,
345
353
'[]'
346
354
)
347
355
}
348
356
)
357
+
358
+ test ( 'Only external deps are included in the package.json' , async ( ) => {
359
+ fs . readFileSync . mockReturnValueOnce (
360
+ JSON . stringify ( {
361
+ dependencies : {
362
+ nonExternal : '^0.0.1' ,
363
+ external : '^0.0.1'
364
+ }
365
+ } )
366
+ )
367
+ getExternals . mockReturnValueOnce ( { external : 'require("external")' } )
368
+
369
+ await runCommand ( 'electron:build' )
370
+
371
+ expect ( fs . writeFileSync ) . toBeCalledWith (
372
+ `dist_electron${ path . sep } bundled${ path . sep } package.json` ,
373
+ JSON . stringify ( {
374
+ dependencies : {
375
+ external : '^0.0.1'
376
+ }
377
+ } )
378
+ )
379
+ } )
349
380
} )
350
381
351
382
describe ( 'electron:serve' , ( ) => {
0 commit comments