@@ -5,7 +5,7 @@ import { parse as parsePlist } from "plist"
5
5
import { CSC_LINK , CSC_KEY_PASSWORD } from "./codeSignData"
6
6
import { expectedLinuxContents } from "./expectedContents"
7
7
import { readText } from "out/promisifed-fs"
8
- import { Packager , PackagerOptions , Platform , getProductName } from "out"
8
+ import { Packager , PackagerOptions , Platform , getProductName , ArtifactCreated } from "out"
9
9
import { normalizePlatforms } from "out/packager"
10
10
import { exec } from "out/util"
11
11
import pathSorter = require( "path-sort" )
@@ -73,15 +73,15 @@ export async function assertPack(fixtureName: string,
73
73
async function packAndCheck ( projectDir : string , packagerOptions : PackagerOptions ) : Promise < void > {
74
74
const packager = new Packager ( packagerOptions )
75
75
76
- const artifacts : Map < Platform , Array < string > > = new Map ( )
77
- packager . artifactCreated ( ( file , platform ) => {
78
- assertThat ( path . isAbsolute ( file ) ) . true ( )
79
- let list = artifacts . get ( platform )
76
+ const artifacts : Map < Platform , Array < ArtifactCreated > > = new Map ( )
77
+ packager . artifactCreated ( event => {
78
+ assertThat ( path . isAbsolute ( event . file ) ) . true ( )
79
+ let list = artifacts . get ( event . platform )
80
80
if ( list == null ) {
81
81
list = [ ]
82
- artifacts . set ( platform , list )
82
+ artifacts . set ( event . platform , list )
83
83
}
84
- list . push ( file )
84
+ list . push ( event )
85
85
} )
86
86
87
87
await packager . build ( )
@@ -90,44 +90,41 @@ async function packAndCheck(projectDir: string, packagerOptions: PackagerOptions
90
90
return
91
91
}
92
92
93
- for ( let key of artifacts . keys ( ) ) {
94
- artifacts . set ( key , pathSorter ( artifacts . get ( key ) ) )
95
- }
96
-
97
- const expandedPlatforms = normalizePlatforms ( packagerOptions . platform )
98
- if ( expandedPlatforms . includes ( "darwin" ) ) {
99
- await checkOsXResult ( packager , artifacts . get ( Platform . OSX ) )
100
- }
101
- else if ( expandedPlatforms . includes ( "linux" ) ) {
102
- const productName = getProductName ( packager . metadata , packager . devMetadata )
103
- const expectedContents = expectedLinuxContents . map ( it => {
104
- if ( it === "/opt/TestApp/TestApp" ) {
105
- return "/opt/" + productName + "/" + productName
106
- }
107
- else if ( it === "/usr/share/applications/TestApp.desktop" ) {
108
- return `/usr/share/applications/${ productName } .desktop`
109
- }
110
- else {
111
- return it . replace ( new RegExp ( "/opt/TestApp/" , "g" ) , `/opt/${ productName } /` )
93
+ for ( let platform of normalizePlatforms ( packagerOptions . platform ) ) {
94
+ if ( platform === "darwin" ) {
95
+ await checkOsXResult ( packager , artifacts . get ( Platform . OSX ) )
96
+ }
97
+ else if ( platform === "linux" ) {
98
+ const productName = getProductName ( packager . metadata , packager . devMetadata )
99
+ const expectedContents = expectedLinuxContents . map ( it => {
100
+ if ( it === "/opt/TestApp/TestApp" ) {
101
+ return "/opt/" + productName + "/" + productName
102
+ }
103
+ else if ( it === "/usr/share/applications/TestApp.desktop" ) {
104
+ return `/usr/share/applications/${ productName } .desktop`
105
+ }
106
+ else {
107
+ return it . replace ( new RegExp ( "/opt/TestApp/" , "g" ) , `/opt/${ productName } /` )
108
+ }
109
+ } )
110
+
111
+ // console.log(JSON.stringify(await getContents(projectDir + "/dist/TestApp-1.0.0-amd64.deb", productName), null, 2))
112
+ // console.log(JSON.stringify(await getContents(projectDir + "/dist/TestApp-1.0.0-i386.deb", productName), null, 2))
113
+
114
+ assertThat ( await getContents ( projectDir + "/dist/TestApp-1.0.0-amd64.deb" , productName ) ) . deepEqual ( expectedContents )
115
+ if ( packagerOptions == null || packagerOptions . arch === null || packagerOptions . arch === "ia32" ) {
116
+ assertThat ( await getContents ( projectDir + "/dist/TestApp-1.0.0-i386.deb" , productName ) ) . deepEqual ( expectedContents )
112
117
}
113
- } )
114
-
115
- // console.log(JSON.stringify(await getContents(projectDir + "/dist/TestApp-1.0.0-amd64.deb", productName), null, 2))
116
- // console.log(JSON.stringify(await getContents(projectDir + "/dist/TestApp-1.0.0-i386.deb", productName), null, 2))
117
-
118
- assertThat ( await getContents ( projectDir + "/dist/TestApp-1.0.0-amd64.deb" , productName ) ) . deepEqual ( expectedContents )
119
- if ( packagerOptions == null || packagerOptions . arch === null || packagerOptions . arch === "ia32" ) {
120
- assertThat ( await getContents ( projectDir + "/dist/TestApp-1.0.0-i386.deb" , productName ) ) . deepEqual ( expectedContents )
121
118
}
122
- }
123
- else if ( expandedPlatforms . includes ( "win32" ) && ( packagerOptions == null || packagerOptions . target == null ) ) {
124
- await checkWindowsResult ( packagerOptions , artifacts . get ( Platform . WINDOWS ) )
119
+ else if ( platform === "win32" && ( packagerOptions == null || packagerOptions . target == null ) ) {
120
+ await checkWindowsResult ( packager , packagerOptions , artifacts . get ( Platform . WINDOWS ) )
121
+ }
125
122
}
126
123
}
127
124
128
- async function checkOsXResult ( packager : Packager , artifacts : Array < string > ) {
125
+ async function checkOsXResult ( packager : Packager , artifacts : Array < ArtifactCreated > ) {
129
126
const productName = getProductName ( packager . metadata , packager . devMetadata )
130
- const packedAppDir = path . join ( path . dirname ( artifacts [ 0 ] ) , ( productName || packager . metadata . name ) + ".app" )
127
+ const packedAppDir = path . join ( path . dirname ( artifacts [ 0 ] . file ) , ( productName || packager . metadata . name ) + ".app" )
131
128
const info = parsePlist ( await readText ( path . join ( packedAppDir , "Contents" , "Info.plist" ) ) )
132
129
assertThat ( info ) . has . properties ( {
133
130
CFBundleDisplayName : productName ,
@@ -139,30 +136,43 @@ async function checkOsXResult(packager: Packager, artifacts: Array<string>) {
139
136
const result = await exec ( "codesign" , [ "--verify" , packedAppDir ] )
140
137
assertThat ( result [ 0 ] . toString ( ) ) . not . match ( / i s n o t s i g n e d a t a l l / )
141
138
142
- assertThat ( artifacts . map ( it => path . basename ( ( it ) ) ) . sort ( ) ) . deepEqual ( [
139
+ assertThat ( artifacts . map ( it => path . basename ( it . file ) ) . sort ( ) ) . deepEqual ( [
140
+ `${ productName } -1.0.0-mac.zip` ,
141
+ `${ productName } -1.0.0.dmg` ,
142
+ ] . sort ( ) )
143
+
144
+ assertThat ( artifacts . map ( it => it . artifactName ) . sort ( ) ) . deepEqual ( [
143
145
"TestApp-1.0.0-mac.zip" ,
144
- "TestApp-1.0.0.dmg"
146
+ "TestApp-1.0.0.dmg" ,
145
147
] . sort ( ) )
146
148
}
147
149
148
- async function checkWindowsResult ( packagerOptions : PackagerOptions , artifacts : Array < string > ) {
149
- const expected32 = [
150
- "RELEASES-ia32" ,
151
- "TestAppSetup-1.0.0-ia32.exe" ,
152
- "TestApp-1.0.0-ia32-full.nupkg" ,
153
- ]
154
- const expected64 = [
155
- "RELEASES" ,
156
- "TestAppSetup-1.0.0.exe" ,
157
- "TestApp-1.0.0-full.nupkg" ,
158
- ]
159
- const expected = packagerOptions != null && packagerOptions . arch === "x64" ? expected64 : expected32 . concat ( expected64 )
160
- const filenames = artifacts . map ( it => path . basename ( ( it ) ) )
161
- assertThat ( filenames . slice ( ) . sort ( ) ) . deepEqual ( expected . sort ( ) )
150
+ async function checkWindowsResult ( packager : Packager , packagerOptions : PackagerOptions , artifacts : Array < ArtifactCreated > ) {
151
+ const productName = getProductName ( packager . metadata , packager . devMetadata )
152
+
153
+ function getWinExpected ( archSuffix : string ) {
154
+ return [
155
+ `RELEASES${ archSuffix } ` ,
156
+ `${ productName } Setup-1.0.0${ archSuffix } .exe` ,
157
+ `TestApp-1.0.0${ archSuffix } -full.nupkg` ,
158
+ ]
159
+ }
160
+
161
+ const archSuffix = packagerOptions != null && packagerOptions . arch === "x64" ? "" : "-ia32"
162
+ const expected = archSuffix == "" ? getWinExpected ( archSuffix ) : getWinExpected ( archSuffix ) . concat ( getWinExpected ( "" ) )
163
+
164
+ const filenames = artifacts . map ( it => path . basename ( it . file ) )
165
+ assertThat ( filenames . slice ( ) . sort ( ) ) . deepEqual ( expected . slice ( ) . sort ( ) )
162
166
163
167
let i = filenames . indexOf ( "RELEASES-ia32" )
164
168
if ( i !== - 1 ) {
165
- assertThat ( ( await readText ( artifacts [ i ] ) ) . indexOf ( "ia32" ) ) . not . equal ( - 1 )
169
+ assertThat ( ( await readText ( artifacts [ i ] . file ) ) . indexOf ( "ia32" ) ) . not . equal ( - 1 )
170
+ }
171
+
172
+ if ( archSuffix == "" ) {
173
+ const expectedArtifactNames = expected . slice ( )
174
+ expectedArtifactNames [ 1 ] = `TestAppSetup-1.0.0${ archSuffix } .exe`
175
+ assertThat ( artifacts . map ( it => it . artifactName ) . filter ( it => it != null ) ) . deepEqual ( [ `TestAppSetup-1.0.0${ archSuffix } .exe` ] )
166
176
}
167
177
}
168
178
0 commit comments