From 62fe86a71f896feee614922a027418633b9f907f Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 1 Jun 2026 17:31:24 -0500 Subject: [PATCH] test(build): verify userscript bundle embeds pure functions and self-test --- tests/build.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/build.test.js diff --git a/tests/build.test.js b/tests/build.test.js new file mode 100644 index 0000000..4c5b53b --- /dev/null +++ b/tests/build.test.js @@ -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'); +});