@@ -3,7 +3,7 @@ import { exists, remove } from "@xmcl/core/fs";
3
3
import { existsSync , readFileSync } from "fs" ;
4
4
import { join , normalize } from "path" ;
5
5
import { FabricInstaller , ForgeInstaller , Installer , LiteLoaderInstaller , Diagnosis , CurseforgeInstaller } from "./index" ;
6
- import { MultipleError } from "./util" ;
6
+ import { MultipleError , DefaultDownloader , batchedTask } from "./util" ;
7
7
import { parseJavaVersion } from "./java" ;
8
8
9
9
const root = normalize ( join ( __dirname , ".." , ".." , "temp" ) ) ;
@@ -87,16 +87,22 @@ describe("Install", () => {
87
87
} , root ) ;
88
88
} ) ;
89
89
test ( "should throw immediately if throwErrorImmediately is enabled" , async ( ) => {
90
- await expect ( Installer . installAssets ( await Version . parse ( mockRoot , "1.14.4" ) , {
91
- assetsHost : "no-op" ,
92
- throwErrorImmediately : true ,
93
- } ) ) . rejects . not . toBeInstanceOf ( MultipleError ) ;
90
+ let task = batchedTask ( {
91
+ execute ( ) {
92
+ throw new Error ( ) ;
93
+ } ,
94
+ update ( ) { } ,
95
+ } as any , [ 0 as any ] , [ 1 ] , 1 , true ) ;
96
+ await expect ( task ) . rejects . not . toBeInstanceOf ( MultipleError ) ;
94
97
} ) ;
95
98
test ( "should throw all event if throwErrorImmediately is disabled" , async ( ) => {
96
- await expect ( Installer . installAssets ( await Version . parse ( mockRoot , "1.14.4" ) , {
97
- assetsHost : "no-op" ,
98
- throwErrorImmediately : false ,
99
- } ) ) . rejects . toBeInstanceOf ( MultipleError ) ;
99
+ let task = batchedTask ( {
100
+ execute ( ) {
101
+ throw new Error ( ) ;
102
+ } ,
103
+ update ( ) { } ,
104
+ } as any , [ 0 as any ] , [ 1 ] ) ;
105
+ await expect ( task ) . rejects . toBeInstanceOf ( MultipleError ) ;
100
106
} ) ;
101
107
} ) ;
102
108
@@ -377,3 +383,15 @@ describe("JavaInstaller", () => {
377
383
} ) ;
378
384
} ) ;
379
385
386
+ describe ( "DefaultDownloader" , ( ) => {
387
+ describe ( "download" , ( ) => {
388
+ test ( "should use fallback urls" , async ( ) => {
389
+ let downloader = new DefaultDownloader ( ) ;
390
+ try {
391
+ await downloader . downloadFile ( { destination : root + "/temp" , url : [ "h/abc" , "z/abc" ] } ) ;
392
+ } catch ( e ) {
393
+ expect ( e . message ) . toEqual ( "Invalid URL: z/abc" ) ;
394
+ }
395
+ } ) ;
396
+ } ) ;
397
+ } ) ;
0 commit comments