1- import { useState , useEffect , useLayoutEffect , useRef } from 'react' ;
2- import { BenchmarkTable } from './components/BenchmarkTable' ;
3- import { CapabilitiesComparison } from './components/CapabilitiesComparison' ;
4- import { SelectorComparison } from './components/SelectorComparison' ;
5- import { runBenchmark , type BenchmarkResults , type BenchmarkProgress } from './utils/benchmark' ;
6- import simpleHtml from './data/simple.html?raw' ;
7- import complexHtml from './data/complex.html?raw' ;
8-
9- type HtmlPreset = 'simple' | 'complex' ;
1+ import { useState , useEffect , useLayoutEffect , useRef } from "react" ;
2+ import { BenchmarkTable } from "./components/BenchmarkTable" ;
3+ import { CapabilitiesComparison } from "./components/CapabilitiesComparison" ;
4+ import { SelectorComparison } from "./components/SelectorComparison" ;
5+ import { ScenarioConformance } from "./components/ScenarioConformance" ;
6+ import {
7+ runBenchmark ,
8+ type BenchmarkResults ,
9+ type BenchmarkProgress ,
10+ } from "./utils/benchmark" ;
11+ import {
12+ runScenarioConformance ,
13+ type ConformanceProgress ,
14+ type LibraryConformance ,
15+ } from "./utils/scenarioConformance" ;
16+ import simpleHtml from "./data/simple.html?raw" ;
17+ import complexHtml from "./data/complex.html?raw" ;
18+
19+ type HtmlPreset = "simple" | "complex" ;
1020
1121const HTML_PRESETS : Record < HtmlPreset , string > = {
1222 simple : simpleHtml ,
@@ -17,6 +27,11 @@ function App() {
1727 const [ results , setResults ] = useState < BenchmarkResults | null > ( null ) ;
1828 const [ isRunning , setIsRunning ] = useState ( false ) ;
1929 const [ progress , setProgress ] = useState < BenchmarkProgress | null > ( null ) ;
30+ const [ conformance , setConformance ] = useState < LibraryConformance [ ] | null > (
31+ null ,
32+ ) ;
33+ const [ conformanceProgress , setConformanceProgress ] =
34+ useState < ConformanceProgress | null > ( null ) ;
2035 const htmlContentRef = useRef ( simpleHtml ) ;
2136 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
2237 const [ isHtmlEditorExpanded , setIsHtmlEditorExpanded ] = useState ( false ) ;
@@ -25,9 +40,11 @@ function App() {
2540 const el = textareaRef . current ;
2641 if ( ! el ) return ;
2742 el . value = htmlContentRef . current ;
28- const handleInput = ( ) => { htmlContentRef . current = el . value ; } ;
29- el . addEventListener ( 'input' , handleInput ) ;
30- return ( ) => el . removeEventListener ( 'input' , handleInput ) ;
43+ const handleInput = ( ) => {
44+ htmlContentRef . current = el . value ;
45+ } ;
46+ el . addEventListener ( "input" , handleInput ) ;
47+ return ( ) => el . removeEventListener ( "input" , handleInput ) ;
3148 } , [ isHtmlEditorExpanded ] ) ;
3249
3350 const handlePresetChange = ( preset : HtmlPreset ) => {
@@ -41,18 +58,25 @@ function App() {
4158 setIsRunning ( true ) ;
4259 setResults ( null ) ;
4360 setProgress ( null ) ;
61+ setConformance ( null ) ;
4462
4563 // Use setTimeout to allow UI to update before heavy computation
4664 setTimeout ( async ( ) => {
4765 const benchmarkResults = await runBenchmark (
4866 textareaRef . current ?. value ?? htmlContentRef . current ,
4967 ( prog ) => {
5068 setProgress ( prog ) ;
51- }
69+ } ,
5270 ) ;
5371 setResults ( benchmarkResults ) ;
54- setIsRunning ( false ) ;
5572 setProgress ( null ) ;
73+
74+ const conformanceResults = await runScenarioConformance ( ( prog ) => {
75+ setConformanceProgress ( prog ) ;
76+ } ) ;
77+ setConformance ( conformanceResults ) ;
78+ setConformanceProgress ( null ) ;
79+ setIsRunning ( false ) ;
5680 } , 100 ) ;
5781 } ;
5882
@@ -67,6 +91,7 @@ function App() {
6791 < h1 > CSS Selector Generator Benchmark</ h1 >
6892 < nav className = "header-nav" >
6993 < a href = "#benchmark-results" > Benchmark Results</ a >
94+ < a href = "#scenario-conformance" > Scenario Conformance</ a >
7095 < a href = "#library-capabilities" > Library Capabilities Comparison</ a >
7196 </ nav >
7297 </ header >
@@ -77,21 +102,21 @@ function App() {
77102 className = "html-editor-toggle"
78103 onClick = { ( ) => setIsHtmlEditorExpanded ( ! isHtmlEditorExpanded ) }
79104 >
80- { isHtmlEditorExpanded ? '▼' : '▶' } Custom HTML
105+ { isHtmlEditorExpanded ? "▼" : "▶" } Custom HTML
81106 </ button >
82107 { isHtmlEditorExpanded && (
83108 < >
84109 < div className = "html-presets" >
85110 < span > Load preset:</ span >
86111 < button
87112 className = "preset-button"
88- onClick = { ( ) => handlePresetChange ( ' simple' ) }
113+ onClick = { ( ) => handlePresetChange ( " simple" ) }
89114 >
90115 Simple
91116 </ button >
92117 < button
93118 className = "preset-button"
94- onClick = { ( ) => handlePresetChange ( ' complex' ) }
119+ onClick = { ( ) => handlePresetChange ( " complex" ) }
95120 >
96121 Complex
97122 </ button >
@@ -110,14 +135,26 @@ function App() {
110135 </ div >
111136
112137 < div className = "controls" >
113- < button className = "button" onClick = { handleRunBenchmark } disabled = { isRunning } >
114- { isRunning ? 'Running benchmark...' : 'Re-run Benchmark' }
138+ < button
139+ className = "button"
140+ onClick = { handleRunBenchmark }
141+ disabled = { isRunning }
142+ >
143+ { isRunning ? "Running benchmark..." : "Re-run Benchmark" }
115144 </ button >
116145 </ div >
117146
118147 { isRunning && progress && (
119148 < div className = "loading" >
120- Testing { progress . libraryName } : { progress . currentElement } /{ progress . totalElements } elements
149+ Testing { progress . libraryName } : { progress . currentElement } /
150+ { progress . totalElements } elements
151+ </ div >
152+ ) }
153+
154+ { isRunning && conformanceProgress && (
155+ < div className = "loading" >
156+ Checking scenario { conformanceProgress . current } /
157+ { conformanceProgress . total } : { conformanceProgress . scenarioId }
121158 </ div >
122159 ) }
123160
@@ -129,6 +166,12 @@ function App() {
129166 </ div >
130167 ) }
131168
169+ { conformance && (
170+ < div id = "scenario-conformance" >
171+ < ScenarioConformance results = { conformance } />
172+ </ div >
173+ ) }
174+
132175 < div id = "library-capabilities" >
133176 < CapabilitiesComparison />
134177 </ div >
0 commit comments