itch-dl
Version:
Bulk download games from itch.io - TypeScript implementation
54 lines (53 loc) • 2.98 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = __importDefault(require("node:test"));
const node_assert_1 = __importDefault(require("node:assert"));
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const node_os_1 = __importDefault(require("node:os"));
const handlers_1 = require("../src/handlers");
const config_1 = require("../src/config");
class DummyClient {
async get() {
throw new Error('not used');
}
}
const dummyClient = new DummyClient();
(0, node_test_1.default)('getJobsForGameJamJson extracts urls', () => {
const data = { jam_games: [{ game: { url: 'u1' } }, { game: { url: 'u2' } }] };
node_assert_1.default.deepStrictEqual((0, handlers_1.getJobsForGameJamJson)(data), ['u1', 'u2']);
});
(0, node_test_1.default)('getJobsForPath handles jam json and url list', () => {
const tmp = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'itch-dl-test-'));
const jsonPath = node_path_1.default.join(tmp, 'jam.json');
node_fs_1.default.writeFileSync(jsonPath, JSON.stringify({ jam_games: [{ game: { url: 'u1' } }] }));
node_assert_1.default.deepStrictEqual((0, handlers_1.getJobsForPath)(jsonPath), ['u1']);
const listPath = node_path_1.default.join(tmp, 'list.txt');
node_fs_1.default.writeFileSync(listPath, 'https://a\nhttp://b');
node_assert_1.default.deepStrictEqual((0, handlers_1.getJobsForPath)(listPath), ['https://a', 'http://b']);
node_fs_1.default.rmSync(tmp, { recursive: true, force: true });
});
(0, node_test_1.default)('preprocessJobUrls filters by glob and regex', () => {
const settings = {
...config_1.DEFAULT_SETTINGS,
filterUrlsGlob: '**/*good*',
filterUrlsRegex: 'https://.*',
};
const res = (0, handlers_1.preprocessJobUrls)([' https://good.com ', 'bad', 'http://good.net'], settings);
node_assert_1.default.deepStrictEqual(new Set(res), new Set(['https://good.com']));
});
(0, node_test_1.default)('getJobsForItchUrl basic game url', async () => {
const urls = await (0, handlers_1.getJobsForItchUrl)('https://author.itch.io/game', dummyClient);
node_assert_1.default.deepStrictEqual(urls, ['https://author.itch.io/game']);
});
(0, node_test_1.default)('getJobsForUrlOrPath with path', async () => {
const tmp = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'itch-dl-test-'));
const p = node_path_1.default.join(tmp, 'urls.txt');
node_fs_1.default.writeFileSync(p, 'https://a');
const urls = await (0, handlers_1.getJobsForUrlOrPath)(p, config_1.DEFAULT_SETTINGS);
node_assert_1.default.deepStrictEqual(urls, ['https://a']);
node_fs_1.default.rmSync(tmp, { recursive: true, force: true });
});