@ciberus/find-steam-app
Version:
Find location of an installed Steam app
203 lines • 11.4 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var mock_fs_1 = __importDefault(require("mock-fs"));
var index_1 = require("../index");
var steam_1 = require("../steam");
var utils_1 = require("../utils");
var utils_2 = require("./utils");
jest.mock("../steam", function () {
var originalModule = jest.requireActual("../steam");
return __assign(__assign({}, originalModule), { findSteamPath: jest.fn().mockImplementation(function () { return utils_2.steamPath; }) });
});
describe("SteamLibraries v1", function () {
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
(0, mock_fs_1.default)({
c: {
"Program Files (x86)": {
Steam: {
steamapps: {
common: (0, utils_2.mockLoad)("../../__data__/c/Program Files (x86)/Steam/steamapps/common"),
"appmanifest_228980.acf": (0, utils_2.mockLoad)("../../__data__/c/Program Files (x86)/Steam/steamapps/appmanifest_228980.acf"),
"libraryfolders.vdf": (0, utils_2.mockLoad)("../../__data__/v1/libraryfolders.vdf"),
},
},
},
},
d: (0, utils_2.mockLoad)("../../__data__/d"),
e: (0, utils_2.mockLoad)("../../__data__/e"),
f: (0, utils_2.mockLoad)("../../__data__/f"),
});
return [2 /*return*/];
});
}); });
afterAll(function () {
mock_fs_1.default.restore();
});
test("findSteamPath", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, steam_1.findSteamPath)()];
case 1:
result = _a.sent();
expect(result).toBeTruthy();
expect(result).toBe(utils_2.steamPath);
return [2 /*return*/];
}
});
}); });
test("findSteamLibrariesPaths", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, index_1.findSteamLibrariesPaths)()];
case 1:
result = _a.sent();
expect(result).toBeTruthy();
expect(result).toEqual([
(0, utils_1.joinAndNormalize)(utils_2.steamPath),
(0, utils_1.joinAndNormalize)("d/SteamLibrary"),
(0, utils_1.joinAndNormalize)("e/SteamLibrary"),
(0, utils_1.joinAndNormalize)("f/SteamLibrary"),
]);
return [2 /*return*/];
}
});
}); });
test("findSteamLibraries", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, index_1.findSteamLibraries)()];
case 1:
result = _a.sent();
expect(result).toBeTruthy();
expect(result).toEqual({
version: "v1",
libraries: [
{
path: (0, utils_1.joinAndNormalize)("c/Program Files (x86)/Steam"),
},
{
path: (0, utils_1.joinAndNormalize)("d/SteamLibrary"),
},
{
path: (0, utils_1.joinAndNormalize)("e/SteamLibrary"),
},
{
path: (0, utils_1.joinAndNormalize)("f/SteamLibrary"),
},
],
});
return [2 /*return*/];
}
});
}); });
test("findSteamAppById", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, index_1.findSteamAppById)(570)];
case 1:
result = _a.sent();
expect(result).toBeTruthy();
expect(result).toBe((0, utils_1.joinAndNormalize)("f/SteamLibrary/steamapps/common/dota 2 beta"));
return [2 /*return*/];
}
});
}); });
test("findSteamAppByName", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, index_1.findSteamAppByName)("dota 2 beta")];
case 1:
result = _a.sent();
expect(result).toBeTruthy();
expect(result).toBe((0, utils_1.joinAndNormalize)("f/SteamLibrary/steamapps/common/dota 2 beta"));
return [2 /*return*/];
}
});
}); });
test("findSteam", function () { return __awaiter(void 0, void 0, void 0, function () {
var result;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
return __generator(this, function (_y) {
switch (_y.label) {
case 0: return [4 /*yield*/, (0, index_1.findSteam)()];
case 1:
result = _y.sent();
expect(result).toBeTruthy();
expect(result.version).toBe("v1");
expect(result.steamPath).toBe(utils_2.steamPath);
expect(result.libraries).toHaveLength(4);
expect(result.librariesVdfFilePath).toBe((0, utils_1.joinAndNormalize)(utils_2.steamPath, "steamapps", "libraryfolders.vdf"));
expect((_a = result.libraries) === null || _a === void 0 ? void 0 : _a[0].apps).toHaveLength(1);
expect((_b = result.libraries) === null || _b === void 0 ? void 0 : _b[0].path).toBe(utils_2.steamPath);
expect((_e = (_d = (_c = result.libraries) === null || _c === void 0 ? void 0 : _c[0].apps) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.appId).toBe(228980);
expect((_h = (_g = (_f = result.libraries) === null || _f === void 0 ? void 0 : _f[0].apps) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.manifestPath).toBeDefined();
expect((_l = (_k = (_j = result.libraries) === null || _j === void 0 ? void 0 : _j[0].apps) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.manifest.Universe).toBeDefined();
expect((_p = (_o = (_m = result.libraries) === null || _m === void 0 ? void 0 : _m[0].apps) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.manifest.StateFlags).toBeDefined();
expect((_q = result.libraries) === null || _q === void 0 ? void 0 : _q[0].totalsize).toBeUndefined();
expect((_r = result.libraries) === null || _r === void 0 ? void 0 : _r[0].update_clean_bytes_tally).toBeUndefined();
expect((_s = result.libraries) === null || _s === void 0 ? void 0 : _s[1].apps).toHaveLength(2);
expect((_t = result.libraries) === null || _t === void 0 ? void 0 : _t[2].apps).toHaveLength(9);
expect((_u = result.libraries) === null || _u === void 0 ? void 0 : _u[3].apps).toHaveLength(1);
expect((_x = (_w = (_v = result.libraries) === null || _v === void 0 ? void 0 : _v[3].apps) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.appId).toBe(570);
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=steamLibrariesV1.js.map