mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-09-25 23:33:35 +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.
67 lines
3.0 KiB
JavaScript
67 lines
3.0 KiB
JavaScript
'use strict';
|
|
const REPO_ROOT = require('path').resolve(__dirname, '..', '..');
|
|
// Unit test for the client-RX coverage frontend gate (SP2).
|
|
//
|
|
// The coverage toggle (#nqCoverage) and its legend (#nqCovLegend) are built
|
|
// inline inside node-reach.js's load() — a large async function that depends on
|
|
// api()/Leaflet, so it can't be invoked headless. Instead we extract the exact
|
|
// actions-HTML concatenation block from the real source and evaluate it in a vm
|
|
// sandbox with both values of window.MC_CLIENT_RX_COVERAGE. This exercises the
|
|
// real source markup logic (no hand-copied duplicate) for the gate.
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const vm = require('vm');
|
|
|
|
const src = fs.readFileSync(path.join(REPO_ROOT, 'public', 'node-reach.js'), 'utf8');
|
|
|
|
// Slice the actions-HTML expression: from the '<div class="nq-actions ...' line
|
|
// through the table that closes the block (ends with '</div></div>';).
|
|
const startMarker = "'<div class=\"nq-actions nq-noprint\">'";
|
|
const startIdx = src.indexOf(startMarker);
|
|
assert.ok(startIdx >= 0, 'could not locate nq-actions block start in node-reach.js');
|
|
const endMarker = "'</div></div>';";
|
|
const endIdx = src.indexOf(endMarker, startIdx);
|
|
assert.ok(endIdx >= 0, 'could not locate nq-actions block end in node-reach.js');
|
|
// Drop the trailing ";" so we can wrap the concatenation as a single expression.
|
|
let block = src.slice(startIdx, endIdx + endMarker.length).replace(/;\s*$/, '');
|
|
|
|
// Render the actions HTML for a given flag value via a controlled sandbox.
|
|
function renderActions(flag) {
|
|
const sandbox = {
|
|
window: { MC_CLIENT_RX_COVERAGE: flag },
|
|
coverageOn: false,
|
|
statsHtml: '',
|
|
};
|
|
vm.createContext(sandbox);
|
|
return vm.runInContext('(' + block + ')', sandbox);
|
|
}
|
|
|
|
// Flag OFF ⇒ no coverage checkbox, no legend.
|
|
const off = renderActions(false);
|
|
assert.ok(!off.includes('id="nqCoverage"'),
|
|
'flag false: actions HTML must NOT contain id="nqCoverage"');
|
|
assert.ok(!off.includes('id="nqCovLegend"'),
|
|
'flag false: actions HTML must NOT contain id="nqCovLegend"');
|
|
|
|
// Flag ON ⇒ coverage checkbox and legend present.
|
|
const on = renderActions(true);
|
|
assert.ok(on.includes('id="nqCoverage"'),
|
|
'flag true: actions HTML MUST contain id="nqCoverage"');
|
|
assert.ok(on.includes('id="nqCovLegend"'),
|
|
'flag true: actions HTML MUST contain id="nqCovLegend"');
|
|
|
|
// #19: the legend visibility is class-driven (.is-hidden), not an inline
|
|
// style="display:..." that CSS can't override. coverageOn is false in this
|
|
// sandbox, so the legend must carry is-hidden and no inline display style.
|
|
assert.ok(/class="nq-cov-legend[^"]*\bis-hidden\b/.test(on),
|
|
'flag true + coverage off: legend must use the is-hidden class');
|
|
assert.ok(!on.includes('style="display:'),
|
|
'legend must not use an inline display style (#19)');
|
|
|
|
// Sanity: the non-gated controls render regardless of the flag.
|
|
assert.ok(off.includes('id="nqIncoming"') && on.includes('id="nqIncoming"'),
|
|
'incoming filter must render irrespective of the coverage flag');
|
|
|
|
console.log('coverage gate (node-reach actions HTML) OK');
|