@@ -8,7 +8,7 @@ const path = require('path')
88const execa = require ( 'execa' )
99const portfinder = require ( 'portfinder' )
1010const Application = require ( 'spectron' ) . Application
11- const { chainWebpack } = require ( '../lib/webpackConfig' )
11+ const { chainWebpack, getExternals } = require ( '../lib/webpackConfig' )
1212// #endregion
1313
1414// #region Mocks
@@ -47,6 +47,12 @@ jest.mock('@vue/cli-service/lib/commands/serve', () => ({
4747 serve : jest . fn ( ) . mockResolvedValue ( { url : 'serveUrl' } )
4848} ) )
4949jest . mock ( 'electron-builder' , ( ) => ( { build : jest . fn ( ) . mockResolvedValue ( ) } ) )
50+ // Mock package.json
51+ fs . readFileSync . mockReturnValue (
52+ JSON . stringify ( {
53+ dependencies : { }
54+ } )
55+ )
5056const mockWait = jest . fn ( ) . mockResolvedValue ( )
5157const mockStart = jest . fn ( )
5258jest . mock ( 'spectron' , ( ) => ( {
@@ -204,14 +210,12 @@ describe('electron:build', () => {
204210 fs . existsSync . mockReturnValueOnce ( true )
205211 await runCommand ( 'electron:build' )
206212 // css/fonts folder was created
207- expect ( fs . ensureDirSync . mock . calls [ 2 ] [ 0 ] ) . toBe (
213+ expect ( fs . ensureDirSync ) . toBeCalledWith (
208214 'projectPath/dist_electron/bundled/css/fonts'
209215 )
210216 // 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' ,
215219 'projectPath/dist_electron/bundled/css/fonts'
216220 )
217221 } )
@@ -337,15 +341,42 @@ describe('electron:build', () => {
337341 }
338342 } )
339343 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`,
341347 '[]'
342348 )
343349 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`,
345353 '[]'
346354 )
347355 }
348356 )
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+ } )
349380} )
350381
351382describe ( 'electron:serve' , ( ) => {
0 commit comments