test(build): verify userscript bundle embeds pure functions and self-test

This commit is contained in:
dev
2026-06-01 17:31:24 -05:00
parent 75f10126d2
commit 62fe86a71f
+27
View File
@@ -0,0 +1,27 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const here = dirname(fileURLToPath(import.meta.url));
const root = join(here, '..');
test('userscript embeds a copy of src/pure.js that is present and parseable', () => {
const bundle = readFileSync(join(root, 'torn-attribute-tracker.user.js'), 'utf8');
// The bundle must reference all four pure function names.
for (const name of ['parseTarget', 'computeEstimate', 'pruneHistory', 'summary']) {
assert.ok(bundle.includes('function ' + name), 'missing ' + name + ' in bundle');
}
// The bundle must include the Tampermonkey header.
assert.ok(bundle.includes('// ==UserScript=='), 'missing Tampermonkey header');
// The bundle must include the @match directive.
assert.ok(bundle.includes('@match'), 'missing @match');
assert.ok(bundle.includes('torn.com/gym.php'), 'missing torn.com/gym.php match');
});
test('userscript self-test block is wired to #tat-test', () => {
const bundle = readFileSync(join(root, 'torn-attribute-tracker.user.js'), 'utf8');
assert.ok(bundle.includes("location.hash === '#tat-test'"), 'self-test guard missing');
assert.ok(bundle.includes('runSelfTest'), 'runSelfTest function missing');
});