+9
-13
@@ -5,18 +5,14 @@ import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
import { download } from "../dist/lib/index.mjs";
|
||||
|
||||
const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
|
||||
|
||||
const TEST_DATA = {
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-win.zip": "haxe.exe",
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-linux64.tar.gz": "haxe",
|
||||
"https://home.shmyga.ru/public/test.txt": "test.txt",
|
||||
const testUrl = async (url, file) => {
|
||||
const target = mkdtempSync(join(tmpdir(), "test-"));
|
||||
await download(url, target);
|
||||
assert(existsSync(join(target, file)));
|
||||
};
|
||||
|
||||
for (const [url, file] of Object.entries(TEST_DATA)) {
|
||||
test(`Test download: ${url}`, async () => {
|
||||
const target = resolveTargetDir();
|
||||
await download(url, target);
|
||||
assert(existsSync(join(target, file)));
|
||||
});
|
||||
}
|
||||
test("zip", async () => await testUrl("https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-win.zip", "haxe.exe"));
|
||||
|
||||
test("tar.gz", async () => await testUrl("https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-linux64.tar.gz", "haxe"));
|
||||
|
||||
test("plain", async () => await testUrl("https://home.shmyga.ru/public/test.txt", "test.txt"));
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { AndroidLink, FlashplayerLink, HaxeLink, NekoLink, resolveLink } from "../dist/lib/index.mjs";
|
||||
|
||||
const testLink = (link, args) => {
|
||||
for (const [params, targetUrl] of args) {
|
||||
const url = resolveLink(link, params);
|
||||
assert.equal(url, targetUrl);
|
||||
}
|
||||
};
|
||||
|
||||
test("neko", () =>
|
||||
testLink(NekoLink, [
|
||||
[{ os_name: "linux" }, "https://github.com/HaxeFoundation/neko/releases/download/v2-4-1/neko-2.4.1-linux64.tar.gz"],
|
||||
[{ os_name: "win" }, "https://github.com/HaxeFoundation/neko/releases/download/v2-4-1/neko-2.4.1-win64.zip"],
|
||||
]));
|
||||
|
||||
test("haxe", () =>
|
||||
testLink(HaxeLink, [
|
||||
[{ os_name: "linux" }, "https://github.com/HaxeFoundation/haxe/releases/download/3.4.2/haxe-3.4.2-linux64.tar.gz"],
|
||||
[{ os_name: "win" }, "https://github.com/HaxeFoundation/haxe/releases/download/3.4.2/haxe-3.4.2-win64.zip"],
|
||||
]));
|
||||
|
||||
test("flashplayer", () =>
|
||||
testLink(FlashplayerLink, [
|
||||
[
|
||||
{ os_name: "linux" },
|
||||
"https://fpdownload.macromedia.com/pub/flashplayer/updaters/32/flash_player_sa_linux.x86_64.tar.gz",
|
||||
],
|
||||
[{ os_name: "win" }, "https://fpdownload.macromedia.com/pub/flashplayer/updaters/32/flashplayer_32_sa.exe"],
|
||||
]));
|
||||
|
||||
test("android", () =>
|
||||
testLink(AndroidLink, [
|
||||
[{ os_name: "linux" }, "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip"],
|
||||
[{ os_name: "win" }, "https://dl.google.com/android/repository/commandlinetools-win-7302050_latest.zip"],
|
||||
]));
|
||||
Reference in New Issue
Block a user