Files
meshcore-analyzer/tests/unit/test-node-reach-coverage.js
T
Alex B 893773338e chore(tests): move root test-*.js into tests/unit and tests/e2e (#2036)
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.
2026-09-17 19:06:07 +02:00

40 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const REPO_ROOT = require('path').resolve(__dirname, '..', '..');
// Unit test for node-reach-coverage.js color buckets. Loads the browser IIFE in
// a vm sandbox (pattern from test-frontend-helpers.js) and exercises the pure
// coverageColorVar mapping.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const code = fs.readFileSync(path.join(REPO_ROOT, 'public', 'node-reach-coverage.js'), 'utf8');
const sandbox = { window: {}, document: {}, getComputedStyle: function () { return { getPropertyValue: function () { return ''; } }; } };
vm.createContext(sandbox);
vm.runInContext(code, sandbox);
const { coverageColorVar } = sandbox.window.NodeReachCoverage;
// SF8 SNR thresholds: ≥ −5 strong, −9..−5 mid, < −9 weak.
assert.strictEqual(coverageColorVar({ has_sig: false }), '--nq-cov-grey', 'no-sig → grey');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: null }), '--nq-cov-grey', 'null snr → grey');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -3 }), '--nq-cov-strong', 'strong');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -5 }), '--nq-cov-strong', 'boundary strong (≥ −5)');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -6 }), '--nq-cov-mid', 'just below −5 → mid');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -9 }), '--nq-cov-mid', 'boundary mid (≥ −9)');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -10 }), '--nq-cov-weak', 'below −9 → weak');
assert.strictEqual(coverageColorVar({ has_sig: true, best_snr: -18 }), '--nq-cov-weak', 'weak');
assert.strictEqual(coverageColorVar(null), '--nq-cov-grey', 'null props → grey');
// #a11y: fill opacity is a redundant, monotonic non-hue cue for the SNR tier so
// colour-blind users can tell tiers apart. Must strictly decrease strong→grey.
const { coverageFillOpacity } = sandbox.window.NodeReachCoverage;
const oStrong = coverageFillOpacity({ has_sig: true, best_snr: -3 });
const oMid = coverageFillOpacity({ has_sig: true, best_snr: -6 });
const oWeak = coverageFillOpacity({ has_sig: true, best_snr: -10 });
const oGrey = coverageFillOpacity({ has_sig: false });
assert.ok(oStrong > oMid && oMid > oWeak && oWeak > oGrey,
'opacity must ramp strong>mid>weak>grey, got ' + [oStrong, oMid, oWeak, oGrey].join(','));
console.log('node-reach-coverage color buckets + opacity ramp OK');