itch-dl
Version:
Bulk download games from itch.io - TypeScript implementation
80 lines (79 loc) • 3.75 kB
JavaScript
;
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 config_1 = require("../src/config");
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const node_os_1 = __importDefault(require("node:os"));
function setEqual(arr, expected) {
if (arr === undefined || expected === undefined) {
node_assert_1.default.strictEqual(arr, expected);
}
else {
node_assert_1.default.deepStrictEqual(new Set(arr), new Set(expected));
}
}
(0, node_test_1.default)('processPlatformTraits basic', () => {
setEqual((0, config_1.processPlatformTraits)(['win']), ['p_windows']);
setEqual((0, config_1.processPlatformTraits)(['win', 'mac']), ['p_windows', 'p_osx']);
setEqual((0, config_1.processPlatformTraits)([]), undefined);
});
(0, node_test_1.default)('processPlatformTraits native', () => {
const sys = process.platform;
let expected;
if (sys.endsWith('bsd')) {
expected = ['p_linux'];
}
else if (sys === 'darwin') {
expected = ['p_osx'];
}
else if (sys === 'win32') {
expected = ['p_windows'];
}
else {
expected = [`p_${sys}`];
}
setEqual((0, config_1.processPlatformTraits)(['native']), expected);
});
(0, node_test_1.default)('createAndGetConfigPath uses XDG_CONFIG_HOME on Linux', () => {
// Skip this test on non-Linux platforms since XDG_CONFIG_HOME behavior is Linux-specific
if (process.platform !== 'linux') {
return;
}
const tmp = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'itch-dl-test-'));
const old = process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = tmp;
const cfgPath = (0, config_1.createAndGetConfigPath)();
node_assert_1.default.strictEqual(cfgPath, node_path_1.default.join(tmp, 'itch-dl'));
process.env.XDG_CONFIG_HOME = old;
node_fs_1.default.rmSync(tmp, { recursive: true, force: true });
});
(0, node_test_1.default)('loadConfig merges config and overrides with CLI', () => {
const tmp = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'itch-dl-test-'));
const old = process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = tmp;
const cfgDir = (0, config_1.createAndGetConfigPath)();
node_fs_1.default.mkdirSync(cfgDir, { recursive: true });
node_fs_1.default.writeFileSync(node_path_1.default.join(cfgDir, 'config.json'), JSON.stringify({ parallel: 2 }));
const settings = (0, config_1.loadConfig)({ parallel: 3 });
node_assert_1.default.strictEqual(settings.parallel, 3);
process.env.XDG_CONFIG_HOME = old;
node_fs_1.default.rmSync(tmp, { recursive: true, force: true });
});
(0, node_test_1.default)('loadConfig uses ITCH_API_KEY when unset elsewhere', () => {
const tmp = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'itch-dl-test-'));
const oldCfg = process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = tmp;
const cfgDir = (0, config_1.createAndGetConfigPath)();
node_fs_1.default.mkdirSync(cfgDir, { recursive: true });
process.env.ITCH_API_KEY = 'envkey';
const settings = (0, config_1.loadConfig)();
node_assert_1.default.strictEqual(settings.apiKey, 'envkey');
delete process.env.ITCH_API_KEY;
process.env.XDG_CONFIG_HOME = oldCfg;
node_fs_1.default.rmSync(tmp, { recursive: true, force: true });
});