mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 00:02:25 +00:00
Build test engines from the shared fake instead of literals
Tests that made their own engine object now use createFakeEngine() with its scripting hooks or an override of the one member under test, so they follow the contract when it changes. 125 such literals in 74 test files go down to two that are not globe engines on purpose; report-qa-harness counts them, and the baseline keeps the number from growing.
This commit is contained in:
1 parent
3c304502a0
commit
225c1c25c7
76 files changed
+668
-564
No files matched your search
@@ -2,17 +2,19 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
QA_HARNESS_METRICS,
|
||||
engineLiteralLines,
|
||||
harnessGrowth,
|
||||
measureQaHarness,
|
||||
readBaseline,
|
||||
readQaSources,
|
||||
readTestSources,
|
||||
} from './report-qa-harness.mjs';
|
||||
|
||||
test('QA harness duplication does not grow past the baseline', () => {
|
||||
assert.deepEqual(
|
||||
harnessGrowth(measureQaHarness(), readBaseline().metrics),
|
||||
[],
|
||||
'QA harness duplication grew; use scripts/qa-strict-harness.mjs helpers for browser launch, engine readiness and camera waits instead.',
|
||||
'QA duplication grew; use the shared browser harness and src/globe/testing/fakeEngine.js for test engines.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -43,6 +45,83 @@ test('QA sources include the harness and exclude tests and other reports', () =>
|
||||
assert.ok(!names.includes('scripts/report-qa-harness.mjs'));
|
||||
});
|
||||
|
||||
test('test sources include nested tests and exclude runtime files', () => {
|
||||
const names = readTestSources().map(({ file }) => file);
|
||||
assert.ok(names.includes('src/globe/testing/fakeEngine.test.mjs'));
|
||||
assert.ok(names.includes('scripts/qaHarness.test.mjs'));
|
||||
assert.ok(names.every((name) => name.endsWith('.test.mjs')));
|
||||
});
|
||||
|
||||
test('engine literals include assignments, inline options and factory returns', () => {
|
||||
for (const source of [
|
||||
'const engine = {};',
|
||||
'let engine; engine = { camera: {} };',
|
||||
'scene.engine = { host: {} };',
|
||||
"scene['engine'] = {};",
|
||||
'init({ engine: {} });',
|
||||
'const state = { _engine: {} };',
|
||||
'const engineB = {}, trafficEngine = {};',
|
||||
"function createEngine() { return { kind: 'cesium' }; }",
|
||||
'const engine = () => ({ camera: {} });',
|
||||
'const fakeEngine = () => { return { host: {} }; };',
|
||||
'const factory = { createEngine() { return { render: {} }; } };',
|
||||
'inspect({ host: { size() {} }, camera: {} });',
|
||||
"const navara = { kind: 'navara', render: {} };",
|
||||
])
|
||||
assert.ok(engineLiteralLines(source).length > 0, source);
|
||||
assert.deepEqual(
|
||||
engineLiteralLines('const engine = {};\ninit({ engine: {} });'),
|
||||
[1, 2],
|
||||
);
|
||||
});
|
||||
|
||||
test('engine literal counting ignores source text, options and harness observations', () => {
|
||||
for (const source of [
|
||||
'// const engine = {};',
|
||||
"const source = 'const engine = {};';",
|
||||
'const source = `init({ engine: {} });`;',
|
||||
'const engine = createFakeEngine();',
|
||||
'init({ engine: createFakeEngine() });',
|
||||
'const options = { engineOptions: {} };',
|
||||
'const engineOptions = { canvas: {}, width: 800 };',
|
||||
"const headers = { host: 'localhost' };",
|
||||
'const overlay = { host: { setEntries() {} } };',
|
||||
'result[engine] = { camera: {} };',
|
||||
'function observedEngine() { return { engine, camera }; }',
|
||||
'function observedEngine() { return { snapshots: [] }; }',
|
||||
'function observedEngine() { return records.map(() => ({ camera: {} })); }',
|
||||
])
|
||||
assert.deepEqual(engineLiteralLines(source), [], source);
|
||||
});
|
||||
|
||||
test('engine literal metric counts test files once and rejects baseline growth', () => {
|
||||
const metric = QA_HARNESS_METRICS.find(
|
||||
({ id }) => id === 'testEngineLiterals',
|
||||
);
|
||||
const measured = metric.measure([
|
||||
{
|
||||
file: 'src/one.test.mjs',
|
||||
text: 'const engine = {}; init({ engine: {} });',
|
||||
},
|
||||
{
|
||||
file: 'scripts/two.test.mjs',
|
||||
text: 'const engine = () => ({ host: {} });',
|
||||
},
|
||||
{ file: 'src/three.test.mjs', text: 'const engine = createFakeEngine();' },
|
||||
{ file: 'src/runtime.js', text: 'const engine = {};' },
|
||||
]);
|
||||
assert.equal(measured, 2);
|
||||
const baseline = Object.fromEntries(
|
||||
QA_HARNESS_METRICS.map(({ id }) => [id, 0]),
|
||||
);
|
||||
assert.deepEqual(
|
||||
harnessGrowth({ ...baseline, testEngineLiterals: measured }, baseline).map(
|
||||
({ id }) => id,
|
||||
),
|
||||
['testEngineLiterals'],
|
||||
);
|
||||
});
|
||||
|
||||
test('metrics count scripts once and distinguish helpers from their callers', () => {
|
||||
const measure = (id, ...sources) =>
|
||||
QA_HARNESS_METRICS.find((metric) => metric.id === id).measure(
|
||||
|
||||
Reference in new issue
Block a user