Files
meshcore-analyzer/tests/unit/test-rx-coverage-config-race.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

45 lines
2.1 KiB
JavaScript

'use strict';
const REPO_ROOT = require('path').resolve(__dirname, '..', '..');
// Unit test for #13: a direct land on #/rx-coverage must not read the coverage
// feature flag before MeshConfigReady resolves. init() should defer its
// enabled/disabled decision until the config promise settles, instead of
// synchronously rendering "not enabled" when the flag is still undefined.
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', 'rx-coverage.js'), 'utf8');
let page = null;
let resolveConfig;
const sandbox = {
window: { MeshConfigReady: new Promise(function (r) { resolveConfig = r; }) }, // MC_CLIENT_RX_COVERAGE undefined for now
document: { getElementById: function () { return null; } },
registerPage: function (name, obj) { page = obj; },
console: { warn: function () {} },
Promise: Promise,
setTimeout: function () {}, clearTimeout: function () {},
fetch: function () { var c = { then: function () { return c; }, catch: function () { return c; } }; return c; },
L: {}, getComputedStyle: function () { return { getPropertyValue: function () { return ''; } }; },
};
vm.createContext(sandbox);
vm.runInContext(code, sandbox);
assert.ok(page && typeof page.init === 'function', 'registerPage should expose init');
(async function () {
const container = { innerHTML: '' };
page.init(container);
// Before MeshConfigReady resolves, init must NOT have decided yet. The old
// code read the (undefined) flag synchronously and rendered "not enabled".
assert.strictEqual(container.innerHTML, '', 'init must defer until MeshConfigReady resolves');
// Resolve config with the feature OFF → only now should it render not-enabled.
sandbox.window.MC_CLIENT_RX_COVERAGE = false;
resolveConfig();
await new Promise(function (r) { setTimeout(r, 10); });
assert.ok(/not enabled/i.test(container.innerHTML), 'after config (off) resolves, shows not-enabled');
console.log('rx-coverage config race OK');
})().catch(function (e) { console.error(e); process.exit(1); });