@@ -11,8 +11,7 @@ class WPTTestRunner {
1111 const wptApiKey = process . env . WPT_API_KEY ;
1212 this . wpt = new WebPageTest ( this . wptServer , wptApiKey ) ;
1313 this . testResultsFile = 'comment.md' ;
14- this . artifactFile = 'artifact.md' ;
15- this . uploadArtifact = false ;
14+ this . commentSizeLimitHit = false ;
1615 }
1716
1817 /**
@@ -41,21 +40,15 @@ class WPTTestRunner {
4140 * Check if the test results are too big for a comment
4241 * @param {number } stringLength Length of the test results string
4342 */
44- commentSizeLimitHit ( stringLength ) {
45- let commentSize = 0 ;
46- try {
47- commentSize = fs . statSync ( this . testResultsFile ) . size ;
48- } catch ( err ) { }
49-
50- if ( commentSize + stringLength > 65536 ) {
51- this . uploadArtifact = true ;
52- fs . appendFileSync ( this . testResultsFile , `
53- Next WebPageTest results are too big for a comment - [download them as an artifact]({artifact-url}).
54- ` ) ;
55- return true ;
56- } else {
57- return false ;
43+ checkCommentSizeLimit ( stringLength ) {
44+ let commentSize = fs . statSync ( this . testResultsFile , throwIfNoEntry = false ) ?
45+ fs . statSync ( this . testResultsFile , throwIfNoEntry = false ) ?. size : 0 ;
46+
47+ if ( commentSize + stringLength > 64500 ) {
48+ this . commentSizeLimitHit = true ;
5849 }
50+
51+ return this . commentSizeLimitHit ;
5952 }
6053
6154 /**
@@ -102,27 +95,24 @@ Next WebPageTest results are too big for a comment - [download them as an artifa
10295 const metricsToLogObject = this . extractLogMetrics ( metricsObject , metricsToLog ) ;
10396 const metricsToLogString = JSON . stringify ( metricsToLogObject , null , 2 ) ;
10497
105- let WPTResults = `<details>
106- <summary><strong>Custom metrics for ${ url } </strong></summary>
98+ let WPTResults = `<details><summary>${ url } </summary>
10799
108- WPT test run results: ${ response . data . summary }
109- ` ,
100+ [WPT test results](${ response . data . summary } )\n` ,
110101 metricsObjectResult = `
111102Changed custom metrics values:
112103\`\`\`json
113104${ metricsToLogString }
114105\`\`\`
106+ </details>\n\n` ,
107+ metricsObjectJSON = `
108+ Cannot display changed custom metrics due to comment size limits, \
109+ use [test JSON](https://webpagetest.httparchive.org/jsonResult.php?test=${ response . data . id } &pretty=1) instead.
115110</details>\n\n` ;
116111
117- if ( ! this . uploadArtifact && ! this . commentSizeLimitHit ( metricsToLogString . length ) ) {
112+ if ( ! this . commentSizeLimitHit && ! this . checkCommentSizeLimit ( metricsToLogString . length ) ) {
118113 fs . appendFileSync ( this . testResultsFile , WPTResults + metricsObjectResult ) ;
119114 } else {
120- fs . appendFileSync ( this . testResultsFile , `
121- <summary><strong>Custom metrics for ${ url } </strong></summary>
122-
123- WPT test run results: ${ response . data . summary }
124- ` ) ;
125- fs . appendFileSync ( this . artifactFile , WPTResults + metricsObjectResult ) ;
115+ fs . appendFileSync ( this . testResultsFile , WPTResults + metricsObjectJSON ) ;
126116 }
127117
128118 console . log ( '::endgroup::' ) ;
0 commit comments