Skip to content

Commit 4d70a36

Browse files
committed
Show tests & test results in web view
1 parent ebe1c31 commit 4d70a36

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"package": "bun run build && bun run vsce-package",
4444
"publish": "bun run package && bun run vsce-publish",
4545
"clean": "rm -r ./dist",
46-
"web": "bun run --cwd ./src/frontend/ vite",
46+
"web": "bun run ./scripts/collect-comment-tests.ts && bun run --cwd ./src/frontend/ vite",
4747
"demo": "bun run --cwd ./src/demo/ vite",
4848
"build-demo": "bun run --cwd ./src/demo/ vite build --outDir ../../dist/demo --base '/function-graph-overview/'",
4949
"format": "bun prettier . --write --log-level silent",

src/frontend/src/lib/TestGraph.svelte

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
import { Graphviz } from "@hpcc-js/wasm-graphviz";
77
import { getFirstFunction, initializeParsers, type Parsers } from "./utils";
88
import { type TestFuncRecord } from "../../../test/commentTestUtils";
9+
import { type TestFunction } from "../../../test/commentTestTypes";
10+
import { requirementTests } from "../../../test/commentTestHandlers";
911
1012
let parsers: Parsers;
1113
let graphviz: Graphviz;
1214
let ast: string = "";
1315
let dot: string = "";
16+
let visibleTestResults: string = "";
17+
export let failed: boolean = false;
1418
export let record: TestFuncRecord;
1519
export let verbose: boolean = false;
1620
export let simplify: boolean = true;
@@ -25,6 +29,29 @@
2529
return {};
2630
}
2731
32+
function runTest(record: TestFuncRecord) {
33+
const tree = parsers[record.language].parse(record.code);
34+
const testFunc: TestFunction = {
35+
function: getFirstFunction(tree),
36+
language: record.language,
37+
name: record.name,
38+
reqs: record.reqs,
39+
};
40+
const testResults = [];
41+
for (const [key, value] of Object.entries(testFunc.reqs)) {
42+
const reqHandler = requirementTests[key];
43+
if (!reqHandler) {
44+
continue;
45+
}
46+
testResults.push({
47+
reqName: key,
48+
reqValue: value,
49+
failure: reqHandler(testFunc),
50+
});
51+
}
52+
return testResults;
53+
}
54+
2855
interface RenderOptions {
2956
readonly simplify: boolean;
3057
readonly verbose: boolean;
@@ -56,6 +83,10 @@
5683
if (trim) cfg = trimFor(cfg);
5784
if (simplify) cfg = simplifyCFG(cfg, mergeNodeAttrs);
5885
86+
const testResults = runTest(record);
87+
visibleTestResults = JSON.stringify(testResults);
88+
failed = !!testResults.filter((result) => result.failure).length;
89+
console.log(failed);
5990
dot = graphToDot(cfg, verbose);
6091
ast = formatAST(functionSyntax.toString());
6192
@@ -71,12 +102,15 @@
71102
}
72103
</script>
73104

74-
<div class="results">
105+
<div class="results" class:failed class:passed={!failed}>
75106
{#await initialize() then}
76107
<div class="graph">
77108
{@html renderWrapper(record, { simplify, verbose, trim, flatSwitch })}
78109
</div>
79110
{/await}
111+
<p>
112+
{visibleTestResults}
113+
</p>
80114
{#if showAST}
81115
<br />
82116
<details>
@@ -100,4 +134,7 @@
100134
justify-content: center;
101135
padding: 1em;
102136
}
137+
.failed {
138+
background-color: #fdd;
139+
}
103140
</style>

0 commit comments

Comments
 (0)