4
4
* @property {any } result The result of the test.
5
5
* @property {any } expected The expected result.
6
6
*/
7
-
8
7
function buildTableCell ( value , tagName = 'td' ) {
9
8
const td = document . createElement ( tagName ) ;
10
9
td . textContent = value ;
@@ -58,13 +57,36 @@ const isReadyPromise = new Promise((resolve) => {
58
57
isReadyPromiseResolve = resolve ;
59
58
} ) ;
60
59
const url = new URL ( window . location . href ) ;
60
+ createResultsHeader ( ) ;
61
61
if ( url . searchParams . get ( 'automation' ) ) {
62
+ createRunButton ( ) ;
62
63
isInAutomation = true ;
63
64
window . addEventListener ( 'content-scope-init-complete' , ( ) => {
64
65
isReadyPromiseResolve ( ) ;
65
66
} ) ;
66
67
}
67
68
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
+
68
90
// @ts -expect-error - ongoingTests is not defined in the type definition
69
91
window . ongoingTests = [ ] ;
70
92
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -73,6 +95,15 @@ function test(name, test) {
73
95
window . ongoingTests . push ( { name, test } ) ;
74
96
}
75
97
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
+
76
107
// eslint-disable-next-line @typescript-eslint/no-unused-vars
77
108
async function renderResults ( ) {
78
109
const results = { } ;
@@ -84,6 +115,7 @@ async function renderResults() {
84
115
const result = await test . test ( ) . catch ( ( e ) => console . error ( `${ test . name } threw` , e ) ) ;
85
116
results [ test . name ] = result ;
86
117
}
118
+ updateResultsHeader ( results ) ;
87
119
// @ts -expect-error - buildResultTable is not defined in the type definition
88
120
document . body . appendChild ( buildResultTable ( results ) ) ;
89
121
// @ts -expect-error - results is not defined in the type definition
0 commit comments