mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-10-10 18:17:31 +00:00
Moves 290 root test-*.js into tests/unit (177, listed in test-all.sh) and tests/e2e (113, classified in scripts/non-unit-tests.json), per #1981 and PR-D of #1385. Root goes from 348 entries to 48. test-all.sh and test-fixtures/ stay put. The inventory guard now fails if a test reappears in the root or sits in the wrong folder.
Verified independently of the diff: the invoked sets are unchanged (test-all.sh 177 before and after, deploy.yml 96 before and after, both identical as sets), and a full local run of test-all.sh on master and on the branch produced 4702 output lines each whose only differences are absolute paths, stack-trace line numbers shifted by the REPO_ROOT line, the inventory wording and two perf ratios. The guard was mutation-checked: a test back in the root, a unit suite in tests/e2e, and a suite dropped from test-all.sh each make it exit 1. CI run 35246304316 ran 97 suites from tests/e2e and is green.
Follow-up 9335c51d finished the instruction files: no bare root test command is left in AGENTS.md, the squad charters, .github or docs, and every tests/ path they name resolves.
Merged by the interim maintainer without a second human reviewer: CI and the local runs above are the independent checks.
Known and deliberately out of scope: 18 of the 113 files in tests/e2e are invoked by no runner at all, and one of them cannot run anywhere because it requires jsdom, which is not a declared dependency. Tracked separately.
58 lines
2.6 KiB
JavaScript
58 lines
2.6 KiB
JavaScript
/**
|
|
* Wiring tests for the Nodes JSON export: index.html loads nodes-export.js,
|
|
* and nodes.js renders an Export JSON button in the topbar that hands the
|
|
* currently filtered node list + active area key to NodesExport.download().
|
|
*
|
|
* Pure source-string assertions (no browser); behavior lives in
|
|
* test-nodes-export.js, DOM behavior in test-nodes-export-e2e.js.
|
|
*/
|
|
'use strict';
|
|
const REPO_ROOT = require('path').resolve(__dirname, '..', '..');
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
function assert(cond, msg) {
|
|
if (cond) { passed++; console.log(' ✓ ' + msg); }
|
|
else { failed++; console.error(' ✗ ' + msg); }
|
|
}
|
|
|
|
const html = fs.readFileSync(path.join(REPO_ROOT, 'public/index.html'), 'utf8');
|
|
const src = fs.readFileSync(path.join(REPO_ROOT, 'public/nodes.js'), 'utf8');
|
|
|
|
console.log('\n=== nodes-export.js is loaded by the SPA shell ===');
|
|
assert(/<script src="nodes-export\.js\?v=__BUST__"/.test(html),
|
|
'index.html loads nodes-export.js with the __BUST__ cache buster');
|
|
const exportTagIdx = html.indexOf('src="nodes-export.js');
|
|
const nodesTagIdx = html.indexOf('src="nodes.js');
|
|
assert(exportTagIdx > 0 && nodesTagIdx > 0 && exportTagIdx < nodesTagIdx,
|
|
'nodes-export.js is loaded before nodes.js');
|
|
|
|
console.log('\n=== Nodes topbar renders the export button ===');
|
|
assert(/id="nodesExportBtn"/.test(src), 'nodes.js renders an element with id nodesExportBtn');
|
|
const topbarIdx = src.indexOf('nodes-topbar');
|
|
const topbarBlock = src.substring(topbarIdx, src.indexOf('</div>', src.indexOf('nodesAreaFilter')));
|
|
assert(topbarIdx > 0 && /nodesExportBtn/.test(topbarBlock),
|
|
'the export button sits in the nodes topbar');
|
|
|
|
console.log('\n=== Click handler exports the visible list for the active area ===');
|
|
const handlerIdx = src.indexOf("getElementById('nodesExportBtn')");
|
|
assert(handlerIdx > 0, 'found the nodesExportBtn handler block');
|
|
const handlerBlock = src.substring(handlerIdx, handlerIdx + 600);
|
|
assert(/NodesExport\.download\s*\(/.test(handlerBlock),
|
|
'handler calls NodesExport.download(...)');
|
|
assert(/NodesExport\.download\(\s*nodes\s*,/.test(handlerBlock),
|
|
'handler passes the filtered `nodes` array (WYSIWYG), not _allNodes');
|
|
assert(/AreaFilter\.getSelected\(\)/.test(handlerBlock),
|
|
'handler passes the active area key from AreaFilter.getSelected()');
|
|
|
|
console.log('\n=== Empty list disables the button ===');
|
|
assert(/nodesExportBtn[\s\S]{0,400}?\.disabled\s*=/.test(src) ||
|
|
/exportBtn\.disabled\s*=/.test(src),
|
|
'the export button is disabled when there is nothing to export');
|
|
|
|
console.log('\n' + passed + ' passed, ' + failed + ' failed');
|
|
process.exit(failed ? 1 : 0);
|