mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-29 03:09:36 +00:00
31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
// Browser mutation witnesses are the expensive part of the registry. This
|
|
// module keeps the cap and the reviewed inventory independent from the CLI so
|
|
// inventory, --check and unit tests ask the same question (#659).
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
export const BROWSER_GUARD_LIMIT = 200;
|
|
export const BROWSER_GUARD_INVENTORY = 'docs/testing-notes/mutation-browser-guards.md';
|
|
|
|
export const isBrowserGuard = (guard) => guard.includes('demo/') || guard.includes('bundle:sync');
|
|
|
|
export function documentedBrowserGuards(markdown) {
|
|
return new Set([...markdown.matchAll(/^- `([^`]+)`$/gm)].map((match) => match[1]));
|
|
}
|
|
|
|
export function readDocumentedBrowserGuards(root = process.cwd()) {
|
|
return documentedBrowserGuards(readFileSync(join(root, BROWSER_GUARD_INVENTORY), 'utf8'));
|
|
}
|
|
|
|
export function browserGuardPolicy(mutants, documented) {
|
|
const browser = mutants.filter((mutant) => isBrowserGuard(mutant.guard));
|
|
const current = new Set(browser.map((mutant) => mutant.id));
|
|
return {
|
|
browser,
|
|
count: browser.length,
|
|
overLimit: browser.length > BROWSER_GUARD_LIMIT,
|
|
missingReasons: browser.filter((mutant) => !documented.has(mutant.id)),
|
|
staleReasons: [...documented].filter((id) => !current.has(id)),
|
|
};
|
|
}
|