@@ -20,6 +20,7 @@ const KORAP_LOGIN = 'KORAP_USERNAME' in process.env ? process.env.KORAP_USERNAME
2020const KORAP_PWD = process . env . KORAP_PWD || process . env . KORAP_PASSWORD || "password2" ;
2121const KORAP_QUERIES = process . env . KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
2222const KORAP_MIN_TOKENS_IN_CORPUS = parseInt ( process . env . KORAP_MIN_TOKENS_IN_CORPUS || "100000" , 10 ) ;
23+ const NOTIFY_ON_SUCCESS = process . env . NOTIFY_ON_SUCCESS === 'true' || process . env . NOTIFY_ON_SUCCESS === '1' ;
2324const korap_rc = require ( '../lib/korap_rc.js' ) . new ( KORAP_URL )
2425const { sendToNextcloudTalk, ifConditionIt } = require ( '../lib/utils.js' ) ;
2526
@@ -66,28 +67,40 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
6667 } )
6768
6869 afterEach ( async function ( ) {
69- if ( this . currentTest . state == "failed" ) {
70+ const testPassed = this . currentTest . state === "passed" ;
71+ const testFailed = this . currentTest . state === "failed" ;
72+
73+ // Determine if we should send notification based on NOTIFY_ON_SUCCESS setting
74+ const shouldNotify = NOTIFY_ON_SUCCESS ? testPassed : testFailed ;
75+
76+ if ( shouldNotify ) {
7077 // Only take screenshot if it's not one of the initial connectivity/SSL tests
7178 const initialTestTitles = [
7279 'should be reachable' ,
7380 'should have a valid SSL certificate'
7481 ] ;
7582 let screenshotPath = null ;
7683
77- if ( ! initialTestTitles . includes ( this . currentTest . title ) && page ) {
84+ // Only take screenshots for failures (not for success notifications)
85+ if ( testFailed && ! initialTestTitles . includes ( this . currentTest . title ) && page ) {
7886 screenshotPath = "failed_" + this . currentTest . title . replaceAll ( / [ & \/ ] / g, "_" ) + '.png' ;
7987 await page . screenshot ( { path : screenshotPath } ) ;
8088 }
8189
90+ // Prepare notification content based on success/failure
91+ const emoji = testPassed ? '✅' : '🚨' ;
92+ const status = testPassed ? 'passed' : 'failed' ;
93+ const color = testPassed ? 'good' : 'danger' ;
94+
8295 // Send notification to Slack
8396 if ( slack ) {
8497 try {
8598 slack . alert ( {
86- text : `🚨 Test on ${ KORAP_URL } failed : *${ this . currentTest . title } *` ,
99+ text : `${ emoji } Test on ${ KORAP_URL } ${ status } : *${ this . currentTest . title } *` ,
87100 attachments : [ {
88- color : 'danger' ,
101+ color : color ,
89102 fields : [ {
90- title : 'Failed Test' ,
103+ title : testPassed ? 'Passed Test' : 'Failed Test' ,
91104 value : this . currentTest . title ,
92105 short : false
93106 } , {
@@ -102,7 +115,7 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
102115 }
103116 }
104117
105- // Upload screenshot to Slack if available
118+ // Upload screenshot to Slack if available (only for failures)
106119 if ( screenshotPath ) {
107120 const slackToken = process . env . SLACK_TOKEN ;
108121 if ( slackToken ) {
@@ -126,9 +139,9 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
126139 }
127140 }
128141
129- // Send notification to Nextcloud Talk with screenshot
142+ // Send notification to Nextcloud Talk with screenshot (if available)
130143 try {
131- const message = `🚨 Test on ${ KORAP_URL } failed : **${ this . currentTest . title } **` ;
144+ const message = `${ emoji } Test on ${ KORAP_URL } ${ status } : **${ this . currentTest . title } **` ;
132145 await sendToNextcloudTalk ( message , false , screenshotPath ) ;
133146 } catch ( ncError ) {
134147 console . error ( 'Failed to send notification to Nextcloud Talk:' , ncError . message ) ;
0 commit comments