Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions scripts/tests/ignore.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import test from "node:test";
import assert from "node:assert/strict";
import { shouldIgnoreProcess } from "../../src/process/index.js";

const ignores = {
linux: [
"/proc/123/exe",
// Important: don't confuse KDE file manager with Dolphin emulator (dolphin-emu)
"/usr/bin/dolphin",
],
win32: [
"C:\\Windows\\system32\\winedevice.exe",
"C:\\Windows\\System32\\wdhoersvc.exe",
],
};

const keeps = {
// Linux-native binaries (Steam/others)
linux: [
"/home/user/.local/share/Steam/steamapps/common/7 Days To Die/7DaysToDie.x86_64",
"/home/user/.local/share/Steam/steamapps/common/Hollow Knight/hollow_knight.x86_64",
"/home/user/.local/share/Steam/steamapps/common/Valheim/valheim.x86_64",
"/home/user/.local/share/Steam/steamapps/common/X4 Foundations/testandlaunch",
"/home/user/.local/share/Steam/steamapps/common/Factorio/bin/x64/factorio",
// Wrapper binary (no path)
"hytale-launcher-wrapper",
"/usr/bin/dolphin-emu",
"/usr/bin/obs",
"obs", // flatpak
],
// Windows executables launched via Wine/Proton/Lutris (paths live on Linux FS, but "platform" is win32)
win32: [
"/home/user/.local/share/Steam/steamapps/common/7 Days To Die/7dLauncher.exe",
"/home/user/.local/share/Steam/steamapps/common/Hollow Knight/hollow_knight.exe",
"/home/user/.local/share/Steam/steamapps/common/Valheim/valheim.exe",
"/home/user/.local/share/Steam/steamapps/common/X4 Foundations/X4.exe",
"/home/user/.local/share/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"/home/user/.local/share/Steam/steamapps/common/FINAL FANTASY XIV Online/game/ffxiv_dx11.exe",
"/home/user/.local/share/Steam/steamapps/common/Wuthering Waves/Wuthering Waves.exe",
"/home/user/Games/Lutris/arknights-endfield/drive_c/Program Files/GRYPHLINK/games/EndField Game/Endfield.exe",
"ZenlessZoneZero.exe",
"obs.exe",
"Soulframe.x64.exe",
],
};

Object.entries(ignores).forEach(([os, paths]) => {
paths.forEach((path) => {
test(`ignores (${os}): ${path}`, () => {
assert.equal(shouldIgnoreProcess(path, os), true);
});
});
});

Object.entries(keeps).forEach(([os, paths]) => {
paths.forEach((path) => {
test(`keeps (${os}): ${path}`, () => {
assert.equal(shouldIgnoreProcess(path, os), false);
});
});
});
25 changes: 25 additions & 0 deletions scripts/tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

import { glob } from "node:fs";
import { promisify } from "node:util";

const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
const log = (...args) =>
console.log(
`[${rgb(88, 101, 242, "arRPC")} > ${rgb(255, 165, 0, "tests")}]`,
...args,
);

const globAsync = promisify(glob);

log("Running test suite...\n");

const testFiles = await globAsync(
new URL("./**.test.js", import.meta.url).pathname,
);

for (const testFile of testFiles) {
await import(testFile);
}

log("\nTest suite completed");
23 changes: 23 additions & 0 deletions scripts/tests/process.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createGetProcesses } from "../../src/process/native/linux.js";

test("parses cmdline and cwd correctly", async () => {
const fakeFS = {
async readdir() {
return ["123"];
},
async readFile() {
return "game\0--foo\0";
},
async readlink() {
return "/home/user/Games";
},
};

const getProcesses = createGetProcesses(fakeFS);
const rows = await getProcesses();

assert.equal(rows[0].pid, 123);
assert.equal(rows[0].exe, "game");
});
Loading