mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-29 03:09:36 +00:00
Release v1.61.0-beta.4 candidate
This commit is contained in:
@@ -2,16 +2,24 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import {
|
||||
assertCardContract,
|
||||
GLOW_CARD_CONTRACT,
|
||||
LARGE_HOUSE_CARD_CONTRACT,
|
||||
} from '../demo/performance/card-contract.mjs';
|
||||
|
||||
const directCardMembers = (relativePath) => {
|
||||
const source = readFileSync(new URL(`../${relativePath}`, import.meta.url), 'utf8');
|
||||
return [...new Set([...source.matchAll(/\bcard\.(_[A-Za-z0-9_]+)/g)].map((match) => match[1]))].sort();
|
||||
// Runner-local names never start with one underscore. Tokenising every
|
||||
// single-underscore member also catches optional chaining, bracket/in access
|
||||
// and a future alias such as `const target = card; target._loadOk`.
|
||||
return [...new Set(
|
||||
[...source.matchAll(/\b(_(?!_)[A-Za-z0-9_]+)\b/g)].map((match) => match[1]),
|
||||
)].sort();
|
||||
};
|
||||
|
||||
const declaredMembers = (contract) => new Set([...contract.methods, ...contract.fields]);
|
||||
const declaredMembers = (contract) => new Set([
|
||||
...contract.methods, ...contract.fields, ...(contract.optionalFields || []),
|
||||
]);
|
||||
|
||||
test('large-house benchmark declares every private card member it consumes', () => {
|
||||
const declared = declaredMembers(LARGE_HOUSE_CARD_CONTRACT);
|
||||
@@ -28,3 +36,31 @@ test('Glow benchmark declares every private card member it consumes', () => {
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test('performance contracts reference real production members', () => {
|
||||
const source = readFileSync(new URL('../src/houseplan-card.ts', import.meta.url), 'utf8');
|
||||
for (const contract of [LARGE_HOUSE_CARD_CONTRACT, GLOW_CARD_CONTRACT]) {
|
||||
for (const name of declaredMembers(contract)) {
|
||||
assert.match(source, new RegExp(`\\b(?:private\\s+(?:get\\s+)?|get\\s+)${name}\\b`),
|
||||
`${contract.label} declares missing production member ${name}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('contract accepts recent optional fields only when their runtime type is valid', () => {
|
||||
const base = {
|
||||
_cleanFloorCache: new Map(), _glowClipCache: new Map(),
|
||||
_wallUnionCache: null, _openingTunnelCache: null, _openingWallIndexCache: null,
|
||||
_devices: [], _loadOk: false,
|
||||
};
|
||||
assert.doesNotThrow(() => assertCardContract(base, GLOW_CARD_CONTRACT));
|
||||
assert.doesNotThrow(() => assertCardContract({ ...base, _glowScreenBlend: false }, GLOW_CARD_CONTRACT));
|
||||
assert.throws(
|
||||
() => assertCardContract({ ...base, _glowScreenBlend: undefined }, GLOW_CARD_CONTRACT),
|
||||
/invalid private API types: _glowScreenBlend:boolean/,
|
||||
);
|
||||
assert.throws(
|
||||
() => assertCardContract({ ...base, _cleanFloorCache: {} }, GLOW_CARD_CONTRACT),
|
||||
/invalid private API types: _cleanFloorCache:map/,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user