2024-04-25 17:32:09 +01:00
import dedent from 'dedent'
2025-01-14 16:03:32 -05:00
import { describe , expect , it } from '@jest/globals'
2024-04-25 17:32:09 +01:00
2025-01-14 16:03:32 -05:00
import { BuildResult } from '../../src/build-results'
import { renderSummaryTable } from '../../src/job-summary'
2024-04-25 17:32:09 +01:00
const successfulHelpBuild : BuildResult = {
rootProjectName : 'root' ,
rootProjectDir : '/' ,
requestedTasks : 'help' ,
gradleVersion : '8.0' ,
gradleHomeDir : '/opt/gradle' ,
buildFailed : false ,
2024-07-18 15:22:38 -06:00
configCacheHit : false ,
2024-04-25 17:32:09 +01:00
buildScanUri : 'https://scans.gradle.com/s/abc123' ,
buildScanFailed : false
}
const failedHelpBuild : BuildResult = {
. . . successfulHelpBuild ,
buildFailed : true
}
const longArgsBuild : BuildResult = {
. . . successfulHelpBuild ,
requestedTasks : 'check publishMyLongNamePluginPublicationToMavenCentral publishMyLongNamePluginPublicationToPluginPortal' ,
}
const scanPublishDisabledBuild : BuildResult = {
. . . successfulHelpBuild ,
buildScanUri : '' ,
buildScanFailed : false ,
}
const scanPublishFailedBuild : BuildResult = {
. . . successfulHelpBuild ,
buildScanUri : '' ,
buildScanFailed : true ,
}
describe ( 'renderSummaryTable' , ( ) = > {
describe ( 'renders' , ( ) = > {
it ( 'successful build' , ( ) = > {
const table = renderSummaryTable ( [ successfulHelpBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : white_check_mark : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com/s/abc123" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Build%20Scan%C2%AE-06A0CE?logo=Gradle" alt = "Build Scan published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
it ( 'failed build' , ( ) = > {
const table = renderSummaryTable ( [ failedHelpBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : x : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com/s/abc123" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Build%20Scan%C2%AE-06A0CE?logo=Gradle" alt = "Build Scan published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
describe ( 'when build scan' , ( ) = > {
it ( 'publishing disabled' , ( ) = > {
const table = renderSummaryTable ( [ scanPublishDisabledBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : white_check_mark : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Not%20published-lightgrey" alt = "Build Scan not published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
it ( 'publishing failed' , ( ) = > {
const table = renderSummaryTable ( [ scanPublishFailedBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : white_check_mark : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://docs.gradle.com/develocity/gradle-plugin/#troubleshooting" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Publish%20failed-orange" alt = "Build Scan publish failed" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
} )
it ( 'multiple builds' , ( ) = > {
const table = renderSummaryTable ( [ successfulHelpBuild , failedHelpBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : white_check_mark : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com/s/abc123" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Build%20Scan%C2%AE-06A0CE?logo=Gradle" alt = "Build Scan published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > help < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : x : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com/s/abc123" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Build%20Scan%C2%AE-06A0CE?logo=Gradle" alt = "Build Scan published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
it ( 'truncating long requested tasks' , ( ) = > {
const table = renderSummaryTable ( [ longArgsBuild ] )
expect ( table . trim ( ) ) . toBe ( dedent `
< table >
< tr >
< th > Gradle Root Project < / th >
< th > Requested Tasks < / th >
< th > Gradle Version < / th >
< th > Build Outcome < / th >
2024-04-25 17:38:12 +01:00
< th > Build & nbsp ; Scan ® < / th >
2024-04-25 17:32:09 +01:00
< / tr >
< tr >
< td > root < / td >
< td > < div title = 'check publishMyLongNamePluginPublicationToMavenCentral publishMyLongNamePluginPublicationToPluginPortal' > check publishMyLongNamePluginPublicationToMavenCentral publ … < / div > < / td >
< td align = 'center' > 8.0 < / td >
< td align = 'center' > : white_check_mark : < / td >
2024-04-25 17:38:12 +01:00
< td > < a href = "https://scans.gradle.com/s/abc123" rel = "nofollow" target = "_blank" > < img src = "https://img.shields.io/badge/Build%20Scan%C2%AE-06A0CE?logo=Gradle" alt = "Build Scan published" / > < / a > < / td >
2024-04-25 17:32:09 +01:00
< / tr >
< / table >
` );
} )
} )
} )