28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
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');
|
|
});
|