repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/signal-handlers.test.mjs
Rawimport assert from 'node:assert/strict';
import { readdirSync, readFileSync } from 'node:fs';
// `function onExited()` declared in an object is a plain method that no signal
// ever calls; only `Connections` turns that spelling into a handler.
const root = new URL('.', import.meta.url).pathname;
const files = readdirSync(root, { recursive: true }).filter(file => file.endsWith('.qml') && !/(^|\/)(node_modules|target)\//.test(file));
assert.ok(files.includes('features/connectivity/Network.qml'), 'feature sources found');
const strays = [];
for (const file of files) {
const lines = readFileSync(root + file, 'utf8').split('\n');
lines.forEach((line, index) => {
const handler = /^(\s+)function on[A-Z]\w*\(/.exec(line);
if (!handler)
return;
let owner = index - 1;
while (owner >= 0 && !(lines[owner].trim() && lines[owner].search(/\S/) < handler[1].length))
owner--;
if (owner < 0 || !/\bConnections \{$/.test(lines[owner]))
strays.push(`${file}:${index + 1}`);
});
}
assert.deepEqual(strays, [], 'signal handlers written as methods outside Connections never run');
console.log('signal-handlers.test.mjs: ALL PASS');