Skip to content

Commit afcae59

Browse files
committed
test: add downloader test
1 parent bb99429 commit afcae59

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

packages/installer/test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { exists, remove } from "@xmcl/core/fs";
33
import { existsSync, readFileSync } from "fs";
44
import { join, normalize } from "path";
55
import { FabricInstaller, ForgeInstaller, Installer, LiteLoaderInstaller, Diagnosis, CurseforgeInstaller } from "./index";
6-
import { MultipleError } from "./util";
6+
import { MultipleError, DefaultDownloader, batchedTask } from "./util";
77
import { parseJavaVersion } from "./java";
88

99
const root = normalize(join(__dirname, "..", "..", "temp"));
@@ -87,16 +87,22 @@ describe("Install", () => {
8787
}, root);
8888
});
8989
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);
9497
});
9598
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);
100106
});
101107
});
102108

@@ -377,3 +383,15 @@ describe("JavaInstaller", () => {
377383
});
378384
});
379385

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

Comments
 (0)