@@ -3,33 +3,39 @@ import path from 'path';
33import { createTempDir } from '../src/temp-utils' ;
44import fs from 'fs-extra' ;
55import { createWindowsInstaller } from '../src' ;
6+ import spawn from '../src/spawn-promise' ;
67
78const log = require ( 'debug' ) ( 'electron-windows-installer:spec' ) ;
89
9- const appDirectory = path . join ( __dirname , 'fixtures/app' ) ;
10+ const fixtureAppDirectory = path . join ( __dirname , 'fixtures/app' ) ;
1011
11- test . beforeEach ( async ( ) : Promise < void > => {
12- const updateExePath = path . join ( appDirectory , 'Squirrel.exe' ) ;
12+ function spawn7z ( args : string [ ] ) : Promise < string > {
13+ const sevenZipPath = path . join ( __dirname , '..' , 'vendor' , '7z.exe' ) ;
14+ const wineExe = process . arch === 'x64' ? 'wine64' : 'wine' ;
15+ return process . platform !== 'win32'
16+ ? spawn ( wineExe , [ sevenZipPath , ...args ] )
17+ : spawn ( sevenZipPath , args ) ;
18+ }
1319
14- if ( await fs . pathExists ( updateExePath ) ) {
15- await fs . unlink ( updateExePath ) ;
16- }
17- } ) ;
20+ async function createTempAppDirectory ( ) : Promise < string > {
21+ const appDirectory = await createTempDir ( 'electron-winstaller-ad-' ) ;
22+ await fs . copy ( fixtureAppDirectory , appDirectory ) ;
23+ return appDirectory ;
24+ }
1825
1926test ( 'creates a nuget package and installer' , async ( t ) : Promise < void > => {
2027 const outputDirectory = await createTempDir ( 'ei-' ) ;
21-
22- const options = {
23- appDirectory : appDirectory ,
24- outputDirectory : outputDirectory
25- } ;
28+ const appDirectory = await createTempAppDirectory ( ) ;
29+ const options = { appDirectory, outputDirectory } ;
2630
2731 await createWindowsInstaller ( options ) ;
2832
2933 log ( `Verifying assertions on ${ outputDirectory } ` ) ;
3034 log ( JSON . stringify ( await fs . readdir ( outputDirectory ) ) ) ;
3135
32- t . true ( await fs . pathExists ( path . join ( outputDirectory , 'myapp-1.0.0-full.nupkg' ) ) ) ;
36+ const nupkgPath = path . join ( outputDirectory , 'myapp-1.0.0-full.nupkg' ) ;
37+
38+ t . true ( await fs . pathExists ( nupkgPath ) ) ;
3339 t . true ( await fs . pathExists ( path . join ( outputDirectory , 'MyAppSetup.exe' ) ) ) ;
3440
3541 if ( process . platform === 'win32' ) {
@@ -38,4 +44,33 @@ test('creates a nuget package and installer', async (t): Promise<void> => {
3844
3945 log ( 'Verifying Update.exe' ) ;
4046 t . true ( await fs . pathExists ( path . join ( appDirectory , 'Squirrel.exe' ) ) ) ;
47+
48+ log ( 'Verifying contents of .nupkg' ) ;
49+
50+ const packageContents = await spawn7z ( [ 'l' , nupkgPath ] ) ;
51+
52+ t . true ( packageContents . includes ( 'lib\\net45\\vk_swiftshader_icd.json' ) ) ;
53+ t . true ( packageContents . includes ( 'lib\\net45\\swiftshader\\libEGL.dll' ) ) ;
54+ } ) ;
55+
56+ test ( 'creates an installer when swiftshader files are missing' , async ( t ) : Promise < void > => {
57+ const appDirectory = await createTempAppDirectory ( ) ;
58+ const outputDirectory = await createTempDir ( 'electron-winstaller-test-' ) ;
59+ const options = { appDirectory, outputDirectory } ;
60+
61+ // Remove swiftshader folder and swiftshader json file, simulating Electron < 10.0
62+ await fs . remove ( path . join ( appDirectory , 'swiftshader' , 'libEGL.dll' ) ) ;
63+ await fs . remove ( path . join ( appDirectory , 'swiftshader' , 'libGLESv2.dll' ) ) ;
64+ await fs . rmdir ( path . join ( appDirectory , 'swiftshader' ) ) ;
65+ await fs . remove ( path . join ( appDirectory , 'vk_swiftshader_icd.json' ) ) ;
66+
67+ await createWindowsInstaller ( options ) ;
68+
69+ const nupkgPath = path . join ( outputDirectory , 'myapp-1.0.0-full.nupkg' ) ;
70+
71+ log ( 'Verifying contents of .nupkg' ) ;
72+
73+ const packageContents = await spawn7z ( [ 'l' , nupkgPath ] ) ;
74+ t . false ( packageContents . includes ( 'vk_swiftshader_icd.json' ) ) ;
75+ t . false ( packageContents . includes ( 'swiftshader\\' ) ) ;
4176} ) ;
0 commit comments