@@ -12,8 +12,6 @@ if (process.env.ELECTRON_BUILDER_OFFLINE === "true") {
12
12
} )
13
13
}
14
14
15
- const NsisUpdaterClass = require ( "../../packages/electron-auto-updater/out/NsisUpdater" ) . NsisUpdater
16
-
17
15
const g = ( < any > global )
18
16
g . __test_app = {
19
17
getVersion : function ( ) {
@@ -26,17 +24,17 @@ g.__test_app = {
26
24
}
27
25
28
26
test ( "check updates - no versions at all" , async ( ) => {
29
- const updater : NsisUpdater = new NsisUpdaterClass ( {
30
- provider : "bintray" ,
31
- owner : "actperepo" ,
32
- package : "no-versions" ,
33
- } )
27
+ const updater = new NsisUpdater ( {
28
+ provider : "bintray" ,
29
+ owner : "actperepo" ,
30
+ package : "no-versions" ,
31
+ } )
34
32
35
33
await assertThat ( updater . checkForUpdates ( ) ) . throws ( / N o l a t e s t v e r s i o n , p l e a s e e n s u r e t h a t / )
36
34
} )
37
35
38
36
test ( "cannot find suitable file for version" , async ( ) => {
39
- const updater : NsisUpdater = new NsisUpdaterClass ( {
37
+ const updater = new NsisUpdater ( {
40
38
provider : "bintray" ,
41
39
owner : "actperepo" ,
42
40
package : "incorrect-file-version" ,
@@ -54,7 +52,7 @@ test("file url", async () => {
54
52
package : "TestApp" ,
55
53
} ) )
56
54
g . __test_resourcesPath = testResourcesPath
57
- const updater : NsisUpdater = new NsisUpdaterClass ( )
55
+ const updater = new NsisUpdater ( )
58
56
59
57
const actualEvents : Array < string > = [ ]
60
58
const expectedEvents = [ "checking-for-update" , "update-available" , "update-downloaded" ]
@@ -79,7 +77,7 @@ test("file url generic", async () => {
79
77
url : "https://develar.s3.amazonaws.com/test" ,
80
78
} ) )
81
79
g . __test_resourcesPath = testResourcesPath
82
- const updater : NsisUpdater = new NsisUpdaterClass ( )
80
+ const updater = new NsisUpdater ( )
83
81
84
82
const actualEvents = trackEvents ( updater )
85
83
@@ -90,6 +88,26 @@ test("file url generic", async () => {
90
88
expect ( actualEvents ) . toMatchSnapshot ( )
91
89
} )
92
90
91
+ test ( "sha2 mismatch error event" , async ( ) => {
92
+ const tmpDir = new TmpDir ( )
93
+ const testResourcesPath = await tmpDir . getTempFile ( "update-config" )
94
+ await outputFile ( path . join ( testResourcesPath , "app-update.yml" ) , safeDump ( < GenericServerOptions > {
95
+ provider : "generic" ,
96
+ url : "https://develar.s3.amazonaws.com/test" ,
97
+ channel : "beta" ,
98
+ } ) )
99
+ g . __test_resourcesPath = testResourcesPath
100
+ const updater = new NsisUpdater ( )
101
+
102
+ const actualEvents = trackEvents ( updater )
103
+
104
+ const updateCheckResult = await updater . checkForUpdates ( )
105
+ expect ( updateCheckResult . fileInfo ) . toMatchSnapshot ( )
106
+ await assertThat ( updateCheckResult . downloadPromise ) . throws ( / S H A 2 c h e c k s u m m i s m a t c h , / )
107
+
108
+ expect ( actualEvents ) . toMatchSnapshot ( )
109
+ } )
110
+
93
111
test ( "file url generic - manual download" , async ( ) => {
94
112
const tmpDir = new TmpDir ( )
95
113
const testResourcesPath = await tmpDir . getTempFile ( "update-config" )
@@ -98,7 +116,7 @@ test("file url generic - manual download", async () => {
98
116
url : "https://develar.s3.amazonaws.com/test" ,
99
117
} ) )
100
118
g . __test_resourcesPath = testResourcesPath
101
- const updater : NsisUpdater = new NsisUpdaterClass ( )
119
+ const updater = new NsisUpdater ( )
102
120
updater . autoDownload = false
103
121
104
122
const actualEvents = trackEvents ( updater )
@@ -120,7 +138,7 @@ test("checkForUpdates several times", async () => {
120
138
url : "https://develar.s3.amazonaws.com/test" ,
121
139
} ) )
122
140
g . __test_resourcesPath = testResourcesPath
123
- const updater : NsisUpdater = new NsisUpdaterClass ( )
141
+ const updater : NsisUpdater = new NsisUpdater ( )
124
142
125
143
const actualEvents = trackEvents ( updater )
126
144
@@ -144,7 +162,7 @@ test("file url github", async () => {
144
162
repo : "__test_nsis_release" ,
145
163
} ) )
146
164
g . __test_resourcesPath = testResourcesPath
147
- const updater : NsisUpdater = new NsisUpdaterClass ( )
165
+ const updater : NsisUpdater = new NsisUpdater ( )
148
166
149
167
const actualEvents : Array < string > = [ ]
150
168
const expectedEvents = [ "checking-for-update" , "update-available" , "update-downloaded" ]
@@ -163,7 +181,7 @@ test("file url github", async () => {
163
181
164
182
test ( "test error" , async ( ) => {
165
183
g . __test_resourcesPath = null
166
- const updater : NsisUpdater = new NsisUpdaterClass ( )
184
+ const updater : NsisUpdater = new NsisUpdater ( )
167
185
168
186
const actualEvents = trackEvents ( updater )
169
187
@@ -179,14 +197,12 @@ test("test download progress", async () => {
179
197
url : "https://develar.s3.amazonaws.com/test" ,
180
198
} ) )
181
199
g . __test_resourcesPath = testResourcesPath
182
- const updater : NsisUpdater = new NsisUpdaterClass ( )
200
+ const updater = new NsisUpdater ( )
183
201
updater . autoDownload = false
184
202
185
203
const progressEvents : Array < any > = [ ]
186
204
187
- updater . addListener ( "download-progress" , ( e : any , progress : any ) => {
188
- progressEvents . push ( progress )
189
- } )
205
+ updater . signals . progress ( it => progressEvents . push ( it ) )
190
206
191
207
await updater . checkForUpdates ( )
192
208
await updater . downloadUpdate ( )
@@ -195,7 +211,7 @@ test("test download progress", async () => {
195
211
196
212
const lastEvent = progressEvents . pop ( )
197
213
198
- expect ( parseInt ( lastEvent . percent , 10 ) ) . toBe ( 100 )
214
+ expect ( lastEvent . percent ) . toBe ( 100 )
199
215
expect ( lastEvent . bytesPerSecond ) . toBeGreaterThan ( 1 )
200
216
expect ( lastEvent . transferred ) . toBe ( lastEvent . total )
201
217
} )
0 commit comments