44 * @property {any } result The result of the test.
55 * @property {any } expected The expected result.
66 */
7-
87function buildTableCell ( value , tagName = 'td' ) {
98 const td = document . createElement ( tagName ) ;
109 td . textContent = value ;
@@ -58,13 +57,36 @@ const isReadyPromise = new Promise((resolve) => {
5857 isReadyPromiseResolve = resolve ;
5958} ) ;
6059const url = new URL ( window . location . href ) ;
60+ createResultsHeader ( ) ;
6161if ( url . searchParams . get ( 'automation' ) ) {
62+ createRunButton ( ) ;
6263 isInAutomation = true ;
6364 window . addEventListener ( 'content-scope-init-complete' , ( ) => {
6465 isReadyPromiseResolve ( ) ;
6566 } ) ;
6667}
6768
69+ function createResultsHeader ( ) {
70+ const summary = document . createElement ( 'summary' ) ;
71+ summary . textContent = 'Test suite status: ' ;
72+ const output = document . createElement ( 'output' ) ;
73+ output . id = 'test-status' ;
74+ output . textContent = 'pending' ;
75+ summary . appendChild ( output ) ;
76+ document . body . appendChild ( summary ) ;
77+ }
78+
79+ function createRunButton ( ) {
80+ const button = document . createElement ( 'button' ) ;
81+ button . textContent = 'Run Tests' ;
82+ button . id = 'run-tests' ;
83+ button . addEventListener ( 'click' , ( ) => {
84+ button . disabled = true ;
85+ window . dispatchEvent ( new Event ( 'content-scope-init-complete' ) ) ;
86+ } ) ;
87+ document . body . appendChild ( button ) ;
88+ }
89+
6890// @ts -expect-error - ongoingTests is not defined in the type definition
6991window . ongoingTests = [ ] ;
7092// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -73,6 +95,15 @@ function test(name, test) {
7395 window . ongoingTests . push ( { name, test } ) ;
7496}
7597
98+ function updateResultsHeader ( results ) {
99+ const totalTests = Object . values ( results ) . flat ( ) . length ;
100+ const passed = Object . values ( results )
101+ . flat ( )
102+ . filter ( ( result ) => result . result === result . expected ) . length ;
103+ const output = document . getElementById ( 'test-status' ) ;
104+ output . textContent = totalTests > 0 && passed === totalTests ? 'pass' : 'fail' ;
105+ }
106+
76107// eslint-disable-next-line @typescript-eslint/no-unused-vars
77108async function renderResults ( ) {
78109 const results = { } ;
@@ -84,6 +115,7 @@ async function renderResults() {
84115 const result = await test . test ( ) . catch ( ( e ) => console . error ( `${ test . name } threw` , e ) ) ;
85116 results [ test . name ] = result ;
86117 }
118+ updateResultsHeader ( results ) ;
87119 // @ts -expect-error - buildResultTable is not defined in the type definition
88120 document . body . appendChild ( buildResultTable ( results ) ) ;
89121 // @ts -expect-error - results is not defined in the type definition
0 commit comments